This commit is contained in:
Louis Vézina 2019-10-26 21:16:59 -04:00
parent d4115cb65f
commit 7c6f47738f
6 changed files with 47 additions and 41 deletions

View File

@ -41,12 +41,18 @@ class SqliteDictPathMapper:
pass
def path_replace(self, values_dict):
for item in values_dict:
item['path'] = path_replace(item['path'])
if type(values_dict) is list:
for item in values_dict:
item['path'] = path_replace(item['path'])
elif type(values_dict) is dict:
values_dict['path'] = path_replace(values_dict['path'])
def path_replace_movie(self, values_dict):
for item in values_dict:
item['path'] = path_replace_movie(item['path'])
if type(values_dict) is list:
for item in values_dict:
item['path'] = path_replace_movie(item['path'])
elif type(values_dict) is dict:
values_dict['path'] = path_replace_movie(values_dict['path'])
dict_mapper = SqliteDictPathMapper()

View File

@ -560,7 +560,7 @@ def series_download_subtitles(no):
episodes_details_clause, (no,))
series_details = database.execute("SELECT hearing_impaired, title, forced FROM table_shows WHERE sonarrSeriesId=?",
(no,))
(no,), only_one=True)
providers_list = get_providers()
providers_auth = get_providers_auth()
@ -657,7 +657,7 @@ def movies_download_subtitles(no):
movie_details_clause = ''
movie = database.execute("SELECT path, missing_subtitles, radarrId, sceneName, hearing_impaired, title, forced "
"FROM table_movies WHERE radarrId=?" + movie_details_clause, (no,))
"FROM table_movies WHERE radarrId=?" + movie_details_clause, (no,), only_one=True)
providers_list = get_providers()
providers_auth = get_providers_auth()
@ -885,7 +885,7 @@ def refine_from_db(path, video):
"table_episodes.video_codec, table_episodes.audio_codec, table_episodes.path "
"FROM table_episodes INNER JOIN table_shows on "
"table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId "
"WHERE table_episodes.path = ?", (unicode(path_replace_reverse(path)),))[0]
"WHERE table_episodes.path = ?", (unicode(path_replace_reverse(path)),), only_one=True)
if data:
video.series, year, country = series_re.match(data['seriesTitle']).groups()
@ -906,7 +906,8 @@ def refine_from_db(path, video):
if data['audio_codec']: video.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 = ?", (unicode(path_replace_reverse_movie(path)),))
"imdbId FROM table_movies WHERE path = ?",
(unicode(path_replace_reverse_movie(path)),), only_one=True)
if data:
video.title = re.sub(r'(\(\d\d\d\d\))', '', data['title'])

View File

@ -104,13 +104,14 @@ def store_subtitles(file):
actual_subtitles.append([str(detected_language), path_replace_reverse(
os.path.join(os.path.dirname(file), subtitle))])
database.execute("UPDATE table_episodes SET =? WHERE path=?",
database.execute("UPDATE table_episodes SET subtitles=? WHERE path=?",
(str(actual_subtitles), path_replace_reverse(file)))
episode = database.execute("SELECT sonarrSeriesId FROM table_episodes WHERE path=?", (path_replace_reverse(file),))
episode = database.execute("SELECT sonarrEpisodeId FROM table_episodes WHERE path=?",
(path_replace_reverse(file),), only_one=True)
if len(episode):
logging.debug("BAZARR storing those languages to DB: " + str(actual_subtitles))
list_missing_subtitles(epno=episode[0]['sonarrEpisodeId'])
list_missing_subtitles(epno=episode['sonarrEpisodeId'])
else:
logging.debug("BAZARR haven't been able to update existing subtitles to DB : " + str(actual_subtitles))
else:
@ -270,7 +271,7 @@ def list_missing_subtitles(no=None, epno=None):
missing_subtitles_global.append(tuple([str(missing_subtitles), episode_subtitles['sonarrEpisodeId']]))
for missing_subtitles_item in missing_subtitles_global:
database.execute("UPDATE table_episodes SET missing_subtitles=? WHERE sonarrEpisodeId=?",
database.execute("UPDATE table_episodes SET missing_subtitles=? WHERE sonarrEpisodeId=?",
(missing_subtitles_item[0], missing_subtitles_item[1]))
@ -356,14 +357,14 @@ def series_scan_subtitles(no):
episodes = database.execute("SELECT path FROM table_episodes WHERE sonarrSeriesId=?", (no,))
for episode in episodes:
store_subtitles(path_replace(episode.path))
store_subtitles(path_replace(episode['path']))
def movies_scan_subtitles(no):
movies = database.execute("SELECT path FROM table_movies WHERE radarrId=?", (no,))
for movie in movies:
store_subtitles_movie(path_replace_movie(movie.path))
store_subtitles_movie(path_replace_movie(movie['path']))
def get_external_subtitles_path(file, subtitle):

View File

@ -575,7 +575,7 @@ def serieseditor():
authorize()
# Get missing count
missing_count = database.execute("SELECT COUNT(*) FROM table_shows")
missing_count = len(database.execute("SELECT COUNT(*) FROM table_shows"))
# Get series list
data = database.execute("SELECT tvdbId, title, path, languages, hearing_impaired, sonarrSeriesId, poster, "
@ -649,8 +649,8 @@ def edit_series(no):
else:
hi = "False"
result = database.execute("UPDATE table_shows SET languages=?, hearing_impaired=?, forced=?) WHERE "
"sonarrSeriesId=?", (lang, hi, forced, no))
result = database.execute("UPDATE table_shows SET languages=?, hearing_impaired=?, forced=? WHERE "
"sonarrSeriesId=?", (str(lang), hi, forced, no))
list_missing_subtitles(no=no)
@ -694,14 +694,11 @@ def episodes(no):
series_details = database.execute("SELECT title, overview, poster, fanart, hearing_impaired, tvdbId, "
"audio_language, languages, path, forced FROM table_shows WHERE "
"sonarrSeriesId=?", (no,))
"sonarrSeriesId=?", (no,), only_one=True)
# path_replace
dict_mapper.path_replace(series_details)
for series in series_details:
tvdbid = series['tvdbId']
series_details = series
break
tvdbid = series_details['tvdbId']
episodes = database.execute("SELECT title, path, season, episode, subtitles, sonarrSeriesId, missing_subtitles, "
"sonarrEpisodeId, scene_name, monitored, failedAttempts FROM table_episodes WHERE "
@ -727,7 +724,7 @@ def episodes(no):
def movies():
authorize()
missing_count = database.execute("SELECT COUNT(*) FROM table_movies")
missing_count = len(database.execute("SELECT COUNT(*) FROM table_movies"))
page = request.GET.page
if page == "":
page = "1"
@ -754,7 +751,7 @@ def movies():
def movieseditor():
authorize()
missing_count = database.execute("SELECT COUNT(*) FORM table_movies")
missing_count = len(database.execute("SELECT COUNT(*) FROM table_movies"))
data = database.execute("SELECT tmdbId, title, path, languages, hearing_impaired, radarrId, poster, "
"audio_language, forced FROM table_movies ORDER BY sortTitle ASC")
@ -844,7 +841,7 @@ def movie(no):
movies_details = database.execute("SELECT title, overview, poster, fanart, hearing_impaired, tmdbId, "
"audio_language, languages, path, subtitles, radarrId, missing_subtitles, "
"scenename, monitored, failedAttempts, forced FROM table_movies "
"WHERE radarrId=?", (no,))
"WHERE radarrId=?", (no,), only_one=True)
# path_replace
dict_mapper.path_replace(movies_details)
@ -917,9 +914,9 @@ def history():
def historyseries():
authorize()
row_count = database.execute("SELECT COUNT(*) FROM table_history LEFT JOIN table_shows on "
"table_history.sonarrSeriesId = table_shows.sonarrSeriesId WHERE table_shows.title "
"is not NULL")
row_count = len(database.execute("SELECT COUNT(*) FROM table_history LEFT JOIN table_shows on "
"table_history.sonarrSeriesId = table_shows.sonarrSeriesId WHERE "
"table_shows.title is not NULL"))
page = request.GET.page
if page == "":
page = "1"
@ -995,9 +992,9 @@ def historyseries():
def historymovies():
authorize()
row_count = database.execute("SELECT COUNT(*) FROM table_history_movie LEFT JOIN table_movies ON "
"table_history_movie.radarrId=table_movies.radarrId "
"WHERE table_movies.title is not NULL")
row_count = len(database.execute("SELECT COUNT(*) FROM table_history_movie LEFT JOIN table_movies ON "
"table_history_movie.radarrId=table_movies.radarrId "
"WHERE table_movies.title is not NULL"))
page = request.GET.page
if page == "":
page = "1"
@ -1084,8 +1081,8 @@ def wantedseries():
else:
monitored_only_query_string = ''
missing_count = database.execute("SELECT COUNT(*) FROM table_episodes WHERE missing_subtitles != '[]'" +
monitored_only_query_string)
missing_count = len(database.execute("SELECT COUNT(*) FROM table_episodes WHERE missing_subtitles != '[]'" +
monitored_only_query_string))
page = request.GET.page
if page == "":
page = "1"
@ -1117,8 +1114,8 @@ def wantedmovies():
else:
monitored_only_query_string = ''
missing_count = database.execute("SELECT COUNT(*) FROM table_movies WHERE missing_subtitles != '[]'" +
monitored_only_query_string)
missing_count = len(database.execute("SELECT COUNT(*) FROM table_movies WHERE missing_subtitles != '[]'" +
monitored_only_query_string))
page = request.GET.page
if page == "":
page = "1"

View File

@ -47,19 +47,20 @@ def get_notifier_providers():
def get_series_name(sonarrSeriesId):
data = database.execute("SELECT title FROM table_shows WHERE sonarrSeriesId=?", (sonarrSeriesId,))
data = database.execute("SELECT title FROM table_shows WHERE sonarrSeriesId=?", (sonarrSeriesId,), only_one=True)
return data[0]['title'] or None
def get_episode_name(sonarrEpisodeId):
data = database.execute("SELECT title, season, episode FROM table_episodes WHERE sonarrEpisodeId=?", (sonarrEpisodeId,))
data = database.execute("SELECT title, season, episode FROM table_episodes WHERE sonarrEpisodeId=?",
(sonarrEpisodeId,), only_one=True)
return data['title'], data['season'], data['episode']
def get_movies_name(radarrId):
data = database.execute("SELECT title FROM table_movies WHERE radarrId=?", (radarrId,))
data = database.execute("SELECT title FROM table_movies WHERE radarrId=?", (radarrId,), only_one=True)
return data['title']

View File

@ -258,8 +258,8 @@
if missing_languages is not None:
from get_subtitle import search_active
for language in missing_languages:
if episode['failed_attempts'] is not None and settings.general.getboolean('adaptive_searching') and language in episode['failed_attempts']:
for lang in ast.literal_eval(episode['failed_attempts']):
if episode['failedAttempts'] is not None and settings.general.getboolean('adaptive_searching') and language in episode['failedAttempts']:
for lang in ast.literal_eval(episode['failedAttempts']):
if language in lang:
if search_active(lang[1]):
%>
@ -276,7 +276,7 @@
%end
%end
%else:
<a data-episodePath="{{episode['path']}}" data-scenename="{{episode['scene_name']}}" data-language="{{alpha3_from_alpha2(str(language.split(':')[0]))}}" data-hi="{{details['hearing_impaired']}}" data-forced="{{"True" if len(language.split(':')) > 1 else "False"}}" data-sonarrSeriesId="{{episode['sonarrSeriesId']}}" data-sonarrEpisodeId="{{episode['sonarrEpisodeId']}}" class="get_subtitle ui tiny label">
<a data-episodePath="{{episode['path']}}" data-scenename="{{episode['scene_name']}}" data-language="{{alpha3_from_alpha2(str(language.split(':')[0]))}}" data-hi="{{details['hearing_impaired']}}" data-forced="{{"True" if len(language.split(':')) > 1 else "False"}}" data-sonarrSeriesId="{{episode['sonarrSeriesId']}}" data-sonarrEpisodeId="{{episode['sonarrEpisodeId']}}" class="get_subtitle ui tiny label">
{{language}}
<i style="margin-left:3px; margin-right:0" class="search icon"></i>
</a>