Merge pull request #1205 from vitiko98/sucha-new-api

Convert release data to guessit format before refining from database
This commit is contained in:
morpheus65535 2020-12-08 17:15:45 -05:00 committed by GitHub
commit 855727643b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 10 deletions

View File

@ -29,6 +29,7 @@ from notifier import send_notifications, send_notifications_movie
from get_providers import get_providers, get_providers_auth, provider_throttle, provider_pool
from knowit import api
from subsyncer import subsync
from guessit import guessit
from database import database, dict_mapper, get_exclusion_clause
from analytics import track_event
@ -241,7 +242,7 @@ def download_subtitle(path, language, audio_language, hi, forced, providers, pro
(path_mappings.path_replace_reverse(path),),
only_one=True)
series_id = episode_metadata['sonarrSeriesId']
episode_id = episode_metadata['sonarrEpisodeId']
episode_id = episode_metadata['sonarrEpisodeId']
sync_subtitles(video_path=path, srt_path=downloaded_path,
srt_lang=downloaded_language_code3, media_type=media_type,
percent_score=percent_score,
@ -252,7 +253,7 @@ def download_subtitle(path, language, audio_language, hi, forced, providers, pro
(path_mappings.path_replace_reverse_movie(path),),
only_one=True)
series_id = ""
episode_id = movie_metadata['radarrId']
episode_id = movie_metadata['radarrId']
sync_subtitles(video_path=path, srt_path=downloaded_path,
srt_lang=downloaded_language_code3, media_type=media_type,
percent_score=percent_score,
@ -640,7 +641,7 @@ def manual_upload_subtitle(path, language, forced, title, scene_name, media_type
(path_mappings.path_replace_reverse(path),),
only_one=True)
series_id = episode_metadata['sonarrSeriesId']
episode_id = episode_metadata['sonarrEpisodeId']
episode_id = episode_metadata['sonarrEpisodeId']
sync_subtitles(video_path=path, srt_path=subtitle_path, srt_lang=uploaded_language_code3, media_type=media_type,
percent_score=100, sonarr_series_id=episode_metadata['sonarrSeriesId'],
sonarr_episode_id=episode_metadata['sonarrEpisodeId'])
@ -649,7 +650,7 @@ def manual_upload_subtitle(path, language, forced, title, scene_name, media_type
(path_mappings.path_replace_reverse_movie(path),),
only_one=True)
series_id = ""
episode_id = movie_metadata['radarrId']
episode_id = movie_metadata['radarrId']
sync_subtitles(video_path=path, srt_path=subtitle_path, srt_lang=uploaded_language_code3, media_type=media_type,
percent_score=100, radarr_id=movie_metadata['radarrId'])
@ -1021,6 +1022,13 @@ def search_active(timestamp):
return True
def convert_to_guessit(guessit_key, attr_from_db):
try:
return guessit(attr_from_db)[guessit_key]
except KeyError:
return attr_from_db
def refine_from_db(path, video):
if isinstance(video, Episode):
data = database.execute(
@ -1045,13 +1053,13 @@ def refine_from_db(path, video):
if data['imdbId'] and not video.series_imdb_id:
video.series_imdb_id = data['imdbId']
if not video.source:
video.source = str(data['format'])
video.source = convert_to_guessit('source', str(data['format']))
if not video.resolution:
video.resolution = str(data['resolution'])
if not video.video_codec:
if data['video_codec']: video.video_codec = data['video_codec']
if data['video_codec']: video.video_codec = convert_to_guessit('video_codec', data['video_codec'])
if not video.audio_codec:
if data['audio_codec']: video.audio_codec = data['audio_codec']
if data['audio_codec']: video.audio_codec = convert_to_guessit('audio_codec', data['audio_codec'])
elif isinstance(video, Movie):
data = database.execute("SELECT title, year, alternativeTitles, format, resolution, video_codec, audio_codec, "
"imdbId FROM table_movies WHERE path = ?",
@ -1066,13 +1074,13 @@ def refine_from_db(path, video):
video.imdb_id = data['imdbId']
video.alternative_titles = ast.literal_eval(data['alternativeTitles'])
if not video.source:
if data['format']: video.source = data['format']
if data['format']: video.source = convert_to_guessit('source', data['format'])
if not video.resolution:
if data['resolution']: video.resolution = data['resolution']
if not video.video_codec:
if data['video_codec']: video.video_codec = data['video_codec']
if data['video_codec']: video.video_codec = convert_to_guessit('video_codec', data['video_codec'])
if not video.audio_codec:
if data['audio_codec']: video.audio_codec = data['audio_codec']
if data['audio_codec']: video.audio_codec = convert_to_guessit('audio_codec', data['audio_codec'])
return video