Passed
Push — develop ( de3ad7...3c2cc7 )
by Dean
02:41
created

Movies   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 10.71%
Metric Value
dl 0
loc 73
ccs 3
cts 28
cp 0.1071
rs 10
wmc 9

1 Method

Rating   Name   Duplication   Size   Complexity  
D run() 0 65 9
1 1
from plugin.core.constants import GUID_SERVICES
2 1
from plugin.sync.core.enums import SyncData, SyncMedia
3 1
from plugin.sync.modes.core.base import log_unsupported, mark_unsupported
4 1
from plugin.sync.modes.pull.base import Base
5
6 1
from plex_database.models import MetadataItem
7 1
import elapsed
8 1
import logging
9
10 1
log = logging.getLogger(__name__)
11
12
13 1
class Movies(Base):
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
14 1
    data = [
15
        SyncData.Collection,
16
        SyncData.Playback,
17
        SyncData.Ratings,
18
        SyncData.Watched
19
    ]
20
21 1
    @elapsed.clock
22
    def run(self):
23
        # Retrieve movie sections
24
        p_sections, p_sections_map = self.sections('movie')
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named sections.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Unused Code introduced by
The variable p_sections_map seems to be unused.
Loading history...
25
26
        # Fetch movies with account settings
27
        p_items = self.plex.library.movies.mapped(
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named plex.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
28
            p_sections, [
29
                MetadataItem.library_section
30
            ],
31
            account=self.current.account.plex.key,
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named current.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
32
            parse_guid=True
33
        )
34
35
        # Calculate total number of movies
36
        pending = {}
37
38
        for data in self.get_data(SyncMedia.Movies):
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named get_data.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
39
            if data not in pending:
40
                pending[data] = {}
41
42
            for pk in self.trakt[(SyncMedia.Movies, data)]:
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named trakt.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
43
                pending[data][pk] = False
44
45
        # Task started
46
        unsupported_movies = {}
47
48
        for rating_key, guid, p_item in p_items:
49
            if not guid or guid.service not in GUID_SERVICES:
50
                mark_unsupported(unsupported_movies, rating_key, guid)
51
                continue
52
53
            key = (guid.service, guid.id)
54
55
            # Try retrieve `pk` for `key`
56
            pk = self.trakt.table('movies').get(key)
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named trakt.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
57
58
            # Store in item map
59
            self.current.map.add(p_item.get('library_section'), rating_key, [key, pk])
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named current.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
60
61
            if pk is None:
62
                # No `pk` found
63
                continue
64
65
            # Execute data handlers
66
            for data in self.get_data(SyncMedia.Movies):
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named get_data.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
67
                t_movie = self.trakt[(SyncMedia.Movies, data)].get(pk)
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named trakt.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
68
69
                self.execute_handlers(
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named execute_handlers.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
70
                    SyncMedia.Movies, data,
71
                    key=rating_key,
72
73
                    p_item=p_item,
74
                    t_item=t_movie
75
                )
76
77
                # Increment one step
78
                self.step(pending, data, pk)
79
80
            # Task checkpoint
81
            self.checkpoint()
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named checkpoint.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
82
83
        # Log details
84
        log_unsupported(log, 'Found %d unsupported movie(s)\n%s', unsupported_movies)
85
        log.debug('Pending: %r', pending)
86