Conditions | 9 |
Total Lines | 65 |
Lines | 0 |
Ratio | 0 % |
Tests | 1 |
CRAP Score | 81 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | 1 | from plugin.core.constants import GUID_SERVICES |
|
21 | 1 | @elapsed.clock |
|
22 | def run(self): |
||
23 | # Retrieve movie sections |
||
24 | p_sections, p_sections_map = self.sections('movie') |
||
25 | |||
26 | # Fetch movies with account settings |
||
27 | p_items = self.plex.library.movies.mapped( |
||
28 | p_sections, [ |
||
29 | MetadataItem.library_section |
||
30 | ], |
||
31 | account=self.current.account.plex.key, |
||
32 | parse_guid=True |
||
33 | ) |
||
34 | |||
35 | # Calculate total number of movies |
||
36 | pending = {} |
||
37 | |||
38 | for data in self.get_data(SyncMedia.Movies): |
||
39 | if data not in pending: |
||
40 | pending[data] = {} |
||
41 | |||
42 | for pk in self.trakt[(SyncMedia.Movies, data)]: |
||
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) |
||
57 | |||
58 | # Store in item map |
||
59 | self.current.map.add(p_item.get('library_section'), rating_key, [key, pk]) |
||
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): |
||
67 | t_movie = self.trakt[(SyncMedia.Movies, data)].get(pk) |
||
68 | |||
69 | self.execute_handlers( |
||
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() |
||
82 | |||
83 | # Log details |
||
84 | log_unsupported(log, 'Found %d unsupported movie(s)\n%s', unsupported_movies) |
||
85 | log.debug('Pending: %r', pending) |
||
86 |