Conditions | 9 |
Total Lines | 73 |
Lines | 0 |
Ratio | 0 % |
Tests | 1 |
CRAP Score | 81.9024 |
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.sync.core.enums import SyncMedia |
|
76 | 1 | def update_changed(self, data, p_playlist, p_sections_map, t_list=None, t_list_items=None): |
|
77 | # Retrieve changed items |
||
78 | t_changes = self.get_changed_items(data) |
||
79 | |||
80 | if not t_changes: |
||
81 | log.debug('No changes detected in %r collection', data) |
||
82 | return |
||
83 | |||
84 | # Construct playlist mapper |
||
85 | mapper = PlaylistMapper(self.current, p_sections_map) |
||
86 | |||
87 | # Parse plex playlist items |
||
88 | mapper.plex.load(p_playlist) |
||
89 | |||
90 | # Parse trakt list items |
||
91 | mapper.trakt.load(t_list, t_list_items) |
||
92 | |||
93 | # Match playlist items and expand shows/seasons |
||
94 | m_trakt, m_plex = mapper.match() |
||
95 | |||
96 | log.debug( |
||
97 | 'Update - Mapper Result (%d items)\nt_items:\n%s\n\np_items:\n%s', |
||
98 | len(m_trakt) + len(m_plex), |
||
99 | '\n'.join(self.format_mapper_result(m_trakt)), |
||
100 | '\n'.join(self.format_mapper_result(m_plex)) |
||
101 | ) |
||
102 | |||
103 | log.debug( |
||
104 | 'Update - Changes (%d keys)\n%s', |
||
105 | len(t_changes), |
||
106 | '\n'.join(self.format_changes(t_changes)), |
||
107 | ) |
||
108 | |||
109 | # Iterate over matched trakt items |
||
110 | for key, index, (p_index, p_items), (t_index, t_items) in m_trakt: |
||
111 | # Expand shows/seasons into episodes |
||
112 | for p_item, t_item in self.expand(p_items, t_items): |
||
113 | if not t_item: |
||
114 | continue |
||
115 | |||
116 | if len(key) < 1: |
||
117 | log.warn('Invalid "key" format: %r', key) |
||
118 | continue |
||
119 | |||
120 | actions = list(t_changes.get(key[0], [])) |
||
121 | |||
122 | if not actions: |
||
123 | continue |
||
124 | |||
125 | if len(actions) > 1: |
||
126 | log.warn('Multiple actions returned for %r: %r', key[0], actions) |
||
127 | continue |
||
128 | |||
129 | # Get `SyncMedia` for `t_item` |
||
130 | media = self.get_media(t_item) |
||
131 | |||
132 | if media is None: |
||
133 | log.warn('Unable to identify media of "t_item" (p_item: %r, t_item: %r)', p_item, t_item) |
||
134 | continue |
||
135 | |||
136 | # Execute handler |
||
137 | self.execute_handlers( |
||
138 | media, data, |
||
139 | |||
140 | action=actions[0], |
||
141 | |||
142 | p_sections_map=p_sections_map, |
||
143 | p_playlist=p_playlist, |
||
144 | |||
145 | key=key, |
||
146 | |||
147 | p_item=p_item, |
||
148 | t_item=t_item |
||
149 | ) |
||
248 |