aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorvitiko98 <[email protected]>2020-12-04 00:52:34 -0400
committervitiko98 <[email protected]>2020-12-04 00:52:34 -0400
commit30ff8dc13804c306fdfb65efa47dd611450b5ccf (patch)
treedf9a302b5dbc3a58255c1669491769f5c10e1785
parent99a3abb24083711a575031671929503cdd9a5604 (diff)
downloadbazarr-30ff8dc13804c306fdfb65efa47dd611450b5ccf.tar.gz
bazarr-30ff8dc13804c306fdfb65efa47dd611450b5ccf.zip
Convert release data to guessit format before refining from database
-rw-r--r--bazarr/get_subtitle.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py
index 0c88e9d31..4b291e471 100644
--- a/bazarr/get_subtitle.py
+++ b/bazarr/get_subtitle.py
@@ -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