Passed
Push — develop ( af752c...572338 )
by Dean
02:33
created

Movies   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Test Coverage

Coverage 6.67%
Metric Value
dl 0
loc 106
ccs 3
cts 45
cp 0.0667
rs 10
wmc 15

1 Method

Rating   Name   Duplication   Size   Complexity  
F run() 0 103 15
1 1
from plugin.sync.core.constants import GUID_AGENTS
2 1
from plugin.sync.core.enums import SyncMode, SyncData, SyncMedia
3 1
from plugin.sync.modes.core.base import Mode, log_unsupported, mark_unsupported
4
5 1
from plex_database.models import MetadataItem
6 1
from trakt_sync.cache.main import Cache
7 1
import elapsed
8 1
import logging
9
10 1
log = logging.getLogger(__name__)
11
12
13 1
class Movies(Mode):
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
14 1
    mode = SyncMode.FastPull
15
16 1
    @elapsed.clock
17
    def run(self):
18
        # Retrieve movie sections
19
        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...
20
21
        # Fetch movies with account settings
22
        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...
23
            p_sections, [
24
                MetadataItem.library_section
25
            ],
26
            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...
27
            parse_guid=True
28
        )
29
30
        # Calculate total number of steps
31
        total = 0
32
33
        for key, result in self.trakt.changes:
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...
34
            media, data = key[0:2]
35
36
            if media != SyncMedia.Movies:
37
                # Ignore changes that aren't for episodes
38
                continue
39
40
            data_name = Cache.Data.get(data)
41
42
            for count in result.metrics.movies.get(data_name, {}).itervalues():
43
                total += count
44
45
        # Task started
46
        unsupported_movies = {}
47
48
        self.current.progress.start(total)
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...
49
50
        # Process movies
51
        for rating_key, p_guid, p_item in p_items:
52
            if not p_guid or p_guid.agent not in GUID_AGENTS:
53
                mark_unsupported(unsupported_movies, rating_key, p_guid, p_item)
54
                continue
55
56
            key = (p_guid.agent, p_guid.sid)
57
58
            log.debug('Processing movie: %s', key)
59
60
            # Try retrieve `pk` for `key`
61
            pk = self.trakt.table.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...
62
63
            # Store in item map
64
            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...
65
66
            if pk is None:
67
                # No `pk` found
68
                continue
69
70
            # Iterate over changed data
71
            for key, result in self.trakt.changes:
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...
72
                media, data = key[0:2]
73
74
                if media != SyncMedia.Movies:
75
                    # Ignore changes that aren't for movies
76
                    continue
77
78
                if data == SyncData.Watchlist:
79
                    # Ignore watchlist data
80
                    continue
81
82
                if not self.is_data_enabled(data):
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named is_data_enabled.

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...
83
                    # Data type has been disabled
84
                    continue
85
86
                data_name = Cache.Data.get(data)
87
88
                if data_name not in result.changes:
89
                    # No changes for collection
90
                    continue
91
92
                for action, items in result.changes[data_name].items():
93
                    t_item = items.get(pk)
94
95
                    if t_item is None:
96
                        # No item found in changes
97
                        continue
98
99
                    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...
100
                        SyncMedia.Movies, data,
101
                        action=action,
102
                        key=rating_key,
103
104
                        p_item=p_item,
105
                        t_item=t_item
106
                    )
107
108
                    # Increment one step
109
                    self.current.progress.step()
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...
110
111
            # Task checkpoint
112
            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...
113
114
        # Log details
115
        log_unsupported(log, 'Found %d unsupported movie(s)\n%s', unsupported_movies)
116
117
        # Task stopped
118
        self.current.progress.stop()
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...
119