|
|
|
@ -9,7 +9,7 @@ import os
|
|
|
|
|
from functools import reduce
|
|
|
|
|
|
|
|
|
|
from utilities.path_mappings import path_mappings
|
|
|
|
|
from subtitles.indexer.series import store_subtitles
|
|
|
|
|
from subtitles.indexer.series import store_subtitles, list_missing_subtitles
|
|
|
|
|
from sonarr.history import history_log
|
|
|
|
|
from app.notifier import send_notifications
|
|
|
|
|
from app.get_providers import get_providers
|
|
|
|
@ -29,22 +29,15 @@ def series_download_subtitles(no):
|
|
|
|
|
raise OSError
|
|
|
|
|
|
|
|
|
|
conditions = [(TableEpisodes.sonarrSeriesId == no),
|
|
|
|
|
(TableEpisodes.missing_subtitles != '[]')]
|
|
|
|
|
(TableEpisodes.missing_subtitles.is_not('[]'))]
|
|
|
|
|
conditions += get_exclusion_clause('series')
|
|
|
|
|
episodes_details = database.execute(
|
|
|
|
|
select(TableEpisodes.path,
|
|
|
|
|
TableEpisodes.missing_subtitles,
|
|
|
|
|
TableEpisodes.monitored,
|
|
|
|
|
TableEpisodes.sonarrEpisodeId,
|
|
|
|
|
TableEpisodes.sceneName,
|
|
|
|
|
TableShows.tags,
|
|
|
|
|
TableShows.seriesType,
|
|
|
|
|
TableEpisodes.audio_language,
|
|
|
|
|
select(TableEpisodes.sonarrEpisodeId,
|
|
|
|
|
TableShows.title,
|
|
|
|
|
TableEpisodes.season,
|
|
|
|
|
TableEpisodes.episode,
|
|
|
|
|
TableEpisodes.title.label('episodeTitle'),
|
|
|
|
|
TableShows.profileId)
|
|
|
|
|
TableEpisodes.missing_subtitles)
|
|
|
|
|
.select_from(TableEpisodes)
|
|
|
|
|
.join(TableShows)
|
|
|
|
|
.where(reduce(operator.and_, conditions))) \
|
|
|
|
@ -66,36 +59,7 @@ def series_download_subtitles(no):
|
|
|
|
|
value=i,
|
|
|
|
|
count=count_episodes_details)
|
|
|
|
|
|
|
|
|
|
audio_language_list = get_audio_profile_languages(episode.audio_language)
|
|
|
|
|
if len(audio_language_list) > 0:
|
|
|
|
|
audio_language = audio_language_list[0]['name']
|
|
|
|
|
else:
|
|
|
|
|
audio_language = 'None'
|
|
|
|
|
|
|
|
|
|
languages = []
|
|
|
|
|
for language in ast.literal_eval(episode.missing_subtitles):
|
|
|
|
|
if language is not None:
|
|
|
|
|
hi_ = "True" if language.endswith(':hi') else "False"
|
|
|
|
|
forced_ = "True" if language.endswith(':forced') else "False"
|
|
|
|
|
languages.append((language.split(":")[0], hi_, forced_))
|
|
|
|
|
|
|
|
|
|
if not languages:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
for result in generate_subtitles(path_mappings.path_replace(episode.path),
|
|
|
|
|
languages,
|
|
|
|
|
audio_language,
|
|
|
|
|
str(episode.sceneName),
|
|
|
|
|
episode.title,
|
|
|
|
|
'series',
|
|
|
|
|
episode.profileId,
|
|
|
|
|
check_if_still_required=True):
|
|
|
|
|
if result:
|
|
|
|
|
if isinstance(result, tuple) and len(result):
|
|
|
|
|
result = result[0]
|
|
|
|
|
store_subtitles(episode.path, path_mappings.path_replace(episode.path))
|
|
|
|
|
history_log(1, no, episode.sonarrEpisodeId, result)
|
|
|
|
|
send_notifications(no, episode.sonarrEpisodeId, result.message)
|
|
|
|
|
episode_download_subtitles(no=episode.sonarrEpisodeId, send_progress=False, providers_list=providers_list)
|
|
|
|
|
else:
|
|
|
|
|
logging.info("BAZARR All providers are throttled")
|
|
|
|
|
break
|
|
|
|
@ -103,11 +67,10 @@ def series_download_subtitles(no):
|
|
|
|
|
hide_progress(id=f'series_search_progress_{no}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def episode_download_subtitles(no, send_progress=False):
|
|
|
|
|
def episode_download_subtitles(no, send_progress=False, providers_list=None):
|
|
|
|
|
conditions = [(TableEpisodes.sonarrEpisodeId == no)]
|
|
|
|
|
conditions += get_exclusion_clause('series')
|
|
|
|
|
episodes_details = database.execute(
|
|
|
|
|
select(TableEpisodes.path,
|
|
|
|
|
stmt = select(TableEpisodes.path,
|
|
|
|
|
TableEpisodes.missing_subtitles,
|
|
|
|
|
TableEpisodes.monitored,
|
|
|
|
|
TableEpisodes.sonarrEpisodeId,
|
|
|
|
@ -120,16 +83,26 @@ def episode_download_subtitles(no, send_progress=False):
|
|
|
|
|
TableEpisodes.title.label('episodeTitle'),
|
|
|
|
|
TableEpisodes.season,
|
|
|
|
|
TableEpisodes.episode,
|
|
|
|
|
TableShows.profileId)
|
|
|
|
|
.select_from(TableEpisodes)
|
|
|
|
|
.join(TableShows)
|
|
|
|
|
.where(reduce(operator.and_, conditions))) \
|
|
|
|
|
.all()
|
|
|
|
|
if not episodes_details:
|
|
|
|
|
TableShows.profileId,
|
|
|
|
|
TableEpisodes.subtitles) \
|
|
|
|
|
.select_from(TableEpisodes) \
|
|
|
|
|
.join(TableShows) \
|
|
|
|
|
.where(reduce(operator.and_, conditions))
|
|
|
|
|
episode = database.execute(stmt).first()
|
|
|
|
|
|
|
|
|
|
if not episode:
|
|
|
|
|
logging.debug("BAZARR no episode with that sonarrEpisodeId can be found in database:", str(no))
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
for episode in episodes_details:
|
|
|
|
|
elif episode.subtitles is None:
|
|
|
|
|
# subtitles indexing for this episode is incomplete, we'll do it again
|
|
|
|
|
store_subtitles(episode.path, path_mappings.path_replace_movie(episode.path))
|
|
|
|
|
episode = database.execute(stmt).first()
|
|
|
|
|
elif episode.missing_subtitles is None:
|
|
|
|
|
# missing subtitles calculation for this episode is incomplete, we'll do it again
|
|
|
|
|
list_missing_subtitles(epno=no)
|
|
|
|
|
episode = database.execute(stmt).first()
|
|
|
|
|
|
|
|
|
|
if not providers_list:
|
|
|
|
|
providers_list = get_providers()
|
|
|
|
|
|
|
|
|
|
if providers_list:
|
|
|
|
@ -154,7 +127,7 @@ def episode_download_subtitles(no, send_progress=False):
|
|
|
|
|
languages.append((language.split(":")[0], hi_, forced_))
|
|
|
|
|
|
|
|
|
|
if not languages:
|
|
|
|
|
continue
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
for result in generate_subtitles(path_mappings.path_replace(episode.path),
|
|
|
|
|
languages,
|
|
|
|
@ -175,4 +148,3 @@ def episode_download_subtitles(no, send_progress=False):
|
|
|
|
|
hide_progress(id=f'episode_search_progress_{no}')
|
|
|
|
|
else:
|
|
|
|
|
logging.info("BAZARR All providers are throttled")
|
|
|
|
|
break
|
|
|
|
|