@@ -163,51 +163,52 @@ def __emby_update_playlist(
163
163
# Get the latest playlist
164
164
edited_emby_playlist :EmbyPlaylist = self .emby_api .get_playlist_items (original_emby_playlist .id )
165
165
166
- # Should be the correct length before this call but make sure
167
- if len (edited_emby_playlist .items ) == len (emby_item_ids ):
168
- playlist_changed = False
169
- playlist_index = 0
170
- for item_id in emby_item_ids :
171
- if item_id != edited_emby_playlist .items [playlist_index ].id :
172
- playlist_changed = True
173
- break
174
- playlist_index += 1
175
-
176
- if playlist_changed :
177
- # The order changed now iterate through the correct item order and find the playlist id to use in moving items
178
- current_index = 0
179
- for correct_item_id in emby_item_ids :
180
- for current_playlist_item in edited_emby_playlist .items :
181
- if correct_item_id == current_playlist_item .id :
182
- if not self .emby_api .set_move_playlist_item_to_index (
183
- edited_emby_playlist .id ,
184
- current_playlist_item .playlist_item_id ,
185
- current_index
186
- ):
187
- playlist_tag = utils .get_tag ("playlist" , original_emby_playlist .name )
188
- item_tag = utils .get_tag ("item" , current_playlist_item .playlist_item_id )
189
- index_tag = utils .get_tag ("index" , current_index )
190
- self .log_warning (
191
- f"{ utils .get_formatted_emby ()} failed { playlist_tag } moving { item_tag } to { index_tag } "
192
- )
193
- current_index += 1
194
- break
195
-
196
- if playlist_changed or add_delete_info .added_items > 0 or add_delete_info .deleted_items > 0 :
197
- collection_tag = utils .get_tag ("collection" , original_emby_playlist .name )
198
- added_tag = utils .get_tag ("added" , add_delete_info .added_items )
199
- deleted_tag = utils .get_tag ("deleted" , add_delete_info .deleted_items )
200
- reordered_tag = utils .get_tag ("reordered" , playlist_changed )
201
- self .log_info (
202
- f"Syncing { utils .get_formatted_plex ()} { collection_tag } to { utils .get_formatted_emby ()} { added_tag } { deleted_tag } { reordered_tag } "
203
- )
204
- else :
205
- collection_tag = utils .get_tag ("collection" , original_emby_playlist .name )
206
- length_tag = utils .get_tag ("length" , len (emby_item_ids ))
207
- reported_length_tag = utils .get_tag ("reported_length" , len (edited_emby_playlist .items ))
208
- self .log_warning (
209
- f"{ utils .get_emby_ansi_code ()} sync { utils .get_plex_ansi_code ()} { collection_tag } playlist update failed. Playlist length should be { length_tag } { reported_length_tag } !"
210
- )
166
+ if edited_emby_playlist is not None :
167
+ # Should be the correct length before this call but make sure
168
+ if len (edited_emby_playlist .items ) == len (emby_item_ids ):
169
+ playlist_changed = False
170
+ playlist_index = 0
171
+ for item_id in emby_item_ids :
172
+ if item_id != edited_emby_playlist .items [playlist_index ].id :
173
+ playlist_changed = True
174
+ break
175
+ playlist_index += 1
176
+
177
+ if playlist_changed :
178
+ # The order changed now iterate through the correct item order and find the playlist id to use in moving items
179
+ current_index = 0
180
+ for correct_item_id in emby_item_ids :
181
+ for current_playlist_item in edited_emby_playlist .items :
182
+ if correct_item_id == current_playlist_item .id :
183
+ if not self .emby_api .set_move_playlist_item_to_index (
184
+ edited_emby_playlist .id ,
185
+ current_playlist_item .playlist_item_id ,
186
+ current_index
187
+ ):
188
+ playlist_tag = utils .get_tag ("playlist" , original_emby_playlist .name )
189
+ item_tag = utils .get_tag ("item" , current_playlist_item .playlist_item_id )
190
+ index_tag = utils .get_tag ("index" , current_index )
191
+ self .log_warning (
192
+ f"{ utils .get_formatted_emby ()} failed { playlist_tag } moving { item_tag } to { index_tag } "
193
+ )
194
+ current_index += 1
195
+ break
196
+
197
+ if playlist_changed or add_delete_info .added_items > 0 or add_delete_info .deleted_items > 0 :
198
+ collection_tag = utils .get_tag ("collection" , original_emby_playlist .name )
199
+ added_tag = utils .get_tag ("added" , add_delete_info .added_items )
200
+ deleted_tag = utils .get_tag ("deleted" , add_delete_info .deleted_items )
201
+ reordered_tag = utils .get_tag ("reordered" , playlist_changed )
202
+ self .log_info (
203
+ f"Syncing { utils .get_formatted_plex ()} { collection_tag } to { utils .get_formatted_emby ()} { added_tag } { deleted_tag } { reordered_tag } "
204
+ )
205
+ else :
206
+ collection_tag = utils .get_tag ("collection" , original_emby_playlist .name )
207
+ length_tag = utils .get_tag ("length" , len (emby_item_ids ))
208
+ reported_length_tag = utils .get_tag ("reported_length" , len (edited_emby_playlist .items ))
209
+ self .log_warning (
210
+ f"{ utils .get_emby_ansi_code ()} sync { utils .get_plex_ansi_code ()} { collection_tag } playlist update failed. Playlist length should be { length_tag } { reported_length_tag } !"
211
+ )
211
212
212
213
def __sync_emby_playlist_with_plex_collection (self , plex_collection : PlexCollection ):
213
214
emby_item_ids : list [str ] = []
@@ -232,7 +233,7 @@ def __sync_emby_playlist_with_plex_collection(self, plex_collection: PlexCollect
232
233
)
233
234
else :
234
235
emby_playlist :EmbyPlaylist = self .emby_api .get_playlist_items (emby_playlist_id )
235
- if emby_playlist :
236
+ if emby_playlist is not None :
236
237
self .__emby_update_playlist (emby_item_ids , emby_playlist )
237
238
238
239
# Give emby time to process
@@ -263,7 +264,7 @@ def __sync_playlists(self):
263
264
self .log_warning (self .emby_api .get_connection_error_log ())
264
265
265
266
def init_scheduler_jobs (self ):
266
- if self .cron :
267
+ if self .cron is not None :
267
268
self .log_service_enabled ()
268
269
self .scheduler .add_job (
269
270
self .__sync_playlists ,
0 commit comments