From fce3589d768b36403cff397b15f535558c3fff2a Mon Sep 17 00:00:00 2001 From: Tom Niget Date: Tue, 7 Nov 2023 17:04:21 +0100 Subject: [PATCH 1/5] fix: Move skip check before call to Youtube-DL --- Contents/Code/plex_api_helper.py | 59 +++++++++++++++----------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/Contents/Code/plex_api_helper.py b/Contents/Code/plex_api_helper.py index 28ba4a6e..567322f7 100644 --- a/Contents/Code/plex_api_helper.py +++ b/Contents/Code/plex_api_helper.py @@ -27,7 +27,7 @@ from plexapi.utils import reverseSearchType # local imports -from constants import contributes_to, guid_map +from constants import contributes_to, guid_map, media_type_dict import general_helper import lizardbyte_db_helper import tmdb_helper @@ -185,10 +185,28 @@ def update_plex_item(rating_key): except KeyError: Log.Info('{}: No theme song found for {} ({})'.format(item.ratingKey, item.title, item.year)) else: - theme_url = process_youtube(url=yt_video_url) - - if theme_url: - add_media(item=item, media_type='themes', media_url_id=yt_video_url, media_url=theme_url) + settings_hash = general_helper.get_themerr_settings_hash() + themerr_data = general_helper.get_themerr_json_data(item=item) + + try: + skip = themerr_data['settings_hash'] == settings_hash \ + and themerr_data[media_type_dict['themes']['themerr_data_key']] == yt_video_url + except KeyError: + skip = False + + if skip: + Log.Info('Skipping {} for type: {}, title: {}, rating_key: {}'.format( + media_type_dict['themes']['name'], item.type, item.title, item.ratingKey + )) + else: + try: + theme_url = process_youtube(url=yt_video_url) + except Exception as e: + Log.Exception('{}: Error processing youtube url: {}'.format(item.ratingKey, e)) + else: + if theme_url: + add_media(item=item, media_type='themes', media_url_id=yt_video_url, media_url=theme_url) + def add_media(item, media_type, media_url_id, media_file=None, media_url=None): @@ -224,33 +242,9 @@ def add_media(item, media_type, media_url_id, media_file=None, media_url=None): """ uploaded = False - settings_hash = general_helper.get_themerr_settings_hash() + themerr_data = general_helper.get_themerr_json_data(item=item) - media_type_dict = dict( - art=dict( - method=item.uploadArt, - type='art', - name='art', - themerr_data_key='art_url', - remove_pref='bool_remove_unused_art', - ), - posters=dict( - method=item.uploadPoster, - type='posters', - name='poster', - themerr_data_key='poster_url', - remove_pref='bool_remove_unused_posters', - ), - themes=dict( - method=item.uploadTheme, - type='themes', - name='theme', - themerr_data_key='youtube_theme_url', - remove_pref='bool_remove_unused_theme_songs', - ), - ) - if media_file or media_url: global plex if not plex: @@ -280,15 +274,16 @@ def add_media(item, media_type, media_url_id, media_file=None, media_url=None): media_type_dict[media_type]['name'], item.type, item.title, item.ratingKey )) if media_file: - uploaded = upload_media(item=item, method=media_type_dict[media_type]['method'], filepath=media_file) + uploaded = upload_media(item=item, method=media_type_dict[media_type]['method'](item), filepath=media_file) if media_url: - uploaded = upload_media(item=item, method=media_type_dict[media_type]['method'], url=media_url) + uploaded = upload_media(item=item, method=media_type_dict[media_type]['method'](item), url=media_url) else: Log.Warning('No theme songs provided for type: {}, title: {}, rating_key: {}'.format( item.type, item.title, item.ratingKey )) if uploaded: + settings_hash = general_helper.get_themerr_settings_hash() # new data for themerr.json new_themerr_data = dict( settings_hash=settings_hash From d529253914a3768e424d7d16f2da9f018198a249 Mon Sep 17 00:00:00 2001 From: Tom Niget Date: Wed, 8 Nov 2023 16:21:29 +0100 Subject: [PATCH 2/5] fix: add dict to constants --- Contents/Code/constants.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Contents/Code/constants.py b/Contents/Code/constants.py index f10e9637..2eb85846 100644 --- a/Contents/Code/constants.py +++ b/Contents/Code/constants.py @@ -99,3 +99,27 @@ base_url, issue_label, issue_template, title_prefix['movie_collections'], '{}', url_name, url_prefix['movie_collections'], '{}'), ) + +media_type_dict = dict( + art=dict( + method=lambda item: item.uploadArt, + type='art', + name='art', + themerr_data_key='art_url', + remove_pref='bool_remove_unused_art', + ), + posters=dict( + method=lambda item: item.uploadPoster, + type='posters', + name='poster', + themerr_data_key='poster_url', + remove_pref='bool_remove_unused_posters', + ), + themes=dict( + method=lambda item: item.uploadTheme, + type='themes', + name='theme', + themerr_data_key='youtube_theme_url', + remove_pref='bool_remove_unused_theme_songs', + ), +) From 949824640745dba4d90c9a59eb169effb2f84fe1 Mon Sep 17 00:00:00 2001 From: Tom Niget Date: Wed, 8 Nov 2023 16:55:31 +0100 Subject: [PATCH 3/5] style: flake8 --- Contents/Code/plex_api_helper.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Contents/Code/plex_api_helper.py b/Contents/Code/plex_api_helper.py index 567322f7..7c3d599c 100644 --- a/Contents/Code/plex_api_helper.py +++ b/Contents/Code/plex_api_helper.py @@ -205,8 +205,8 @@ def update_plex_item(rating_key): Log.Exception('{}: Error processing youtube url: {}'.format(item.ratingKey, e)) else: if theme_url: - add_media(item=item, media_type='themes', media_url_id=yt_video_url, media_url=theme_url) - + add_media(item=item, media_type='themes', + media_url_id=yt_video_url, media_url=theme_url) def add_media(item, media_type, media_url_id, media_file=None, media_url=None): @@ -242,7 +242,6 @@ def add_media(item, media_type, media_url_id, media_file=None, media_url=None): """ uploaded = False - themerr_data = general_helper.get_themerr_json_data(item=item) if media_file or media_url: From 1ffc327b1721ba436a858aa498ee1b88b027d6a8 Mon Sep 17 00:00:00 2001 From: Tom Niget Date: Wed, 8 Nov 2023 16:58:34 +0100 Subject: [PATCH 4/5] fix: again --- Contents/Code/plex_api_helper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Contents/Code/plex_api_helper.py b/Contents/Code/plex_api_helper.py index 7c3d599c..7ab36cd4 100644 --- a/Contents/Code/plex_api_helper.py +++ b/Contents/Code/plex_api_helper.py @@ -205,7 +205,7 @@ def update_plex_item(rating_key): Log.Exception('{}: Error processing youtube url: {}'.format(item.ratingKey, e)) else: if theme_url: - add_media(item=item, media_type='themes', + add_media(item=item, media_type='themes', media_url_id=yt_video_url, media_url=theme_url) @@ -242,6 +242,7 @@ def add_media(item, media_type, media_url_id, media_file=None, media_url=None): """ uploaded = False + settings_hash = general_helper.get_themerr_settings_hash() themerr_data = general_helper.get_themerr_json_data(item=item) if media_file or media_url: From 0ff67b1330237272d251b195438b66eea2907ca9 Mon Sep 17 00:00:00 2001 From: Tom Niget Date: Wed, 8 Nov 2023 17:46:14 +0100 Subject: [PATCH 5/5] fix: remove leftover line Co-authored-by: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> --- Contents/Code/plex_api_helper.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Contents/Code/plex_api_helper.py b/Contents/Code/plex_api_helper.py index 7ab36cd4..1d905b7d 100644 --- a/Contents/Code/plex_api_helper.py +++ b/Contents/Code/plex_api_helper.py @@ -283,7 +283,6 @@ def add_media(item, media_type, media_url_id, media_file=None, media_url=None): )) if uploaded: - settings_hash = general_helper.get_themerr_settings_hash() # new data for themerr.json new_themerr_data = dict( settings_hash=settings_hash