Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

fix: Move skip check before call to Youtube-DL #204

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Contents/Code/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
)
56 changes: 25 additions & 31 deletions Contents/Code/plex_api_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
zdimension marked this conversation as resolved.
Show resolved Hide resolved
import general_helper
import lizardbyte_db_helper
import tmdb_helper
Expand Down Expand Up @@ -185,10 +185,28 @@
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

Check warning on line 195 in Contents/Code/plex_api_helper.py

View check run for this annotation

Codecov / codecov/patch

Contents/Code/plex_api_helper.py#L194-L195

Added lines #L194 - L195 were not covered by tests

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))

Check warning on line 205 in Contents/Code/plex_api_helper.py

View check run for this annotation

Codecov / codecov/patch

Contents/Code/plex_api_helper.py#L202-L205

Added lines #L202 - L205 were not covered by tests
else:
if theme_url:
add_media(item=item, media_type='themes',

Check warning on line 208 in Contents/Code/plex_api_helper.py

View check run for this annotation

Codecov / codecov/patch

Contents/Code/plex_api_helper.py#L207-L208

Added lines #L207 - L208 were not covered by tests
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):
Expand Down Expand Up @@ -227,30 +245,6 @@
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:
Expand Down Expand Up @@ -280,9 +274,9 @@
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)

Check warning on line 277 in Contents/Code/plex_api_helper.py

View check run for this annotation

Codecov / codecov/patch

Contents/Code/plex_api_helper.py#L277

Added line #L277 was not covered by tests
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)

Check warning on line 279 in Contents/Code/plex_api_helper.py

View check run for this annotation

Codecov / codecov/patch

Contents/Code/plex_api_helper.py#L279

Added line #L279 was not covered by tests
else:
Log.Warning('No theme songs provided for type: {}, title: {}, rating_key: {}'.format(
item.type, item.title, item.ratingKey
Expand Down
Loading