mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-26 01:27:07 +00:00
Search for subtitles when episodes and movies are added to Bazarr if there's no more than 5 items added (to avoid longer initial scan). #308
This commit is contained in:
parent
d9d0942d50
commit
d861cee4d2
4 changed files with 65 additions and 14 deletions
|
@ -11,6 +11,7 @@ from config import settings, url_sonarr
|
||||||
from helper import path_replace
|
from helper import path_replace
|
||||||
from list_subtitles import list_missing_subtitles, store_subtitles, series_full_scan_subtitles, \
|
from list_subtitles import list_missing_subtitles, store_subtitles, series_full_scan_subtitles, \
|
||||||
movies_full_scan_subtitles
|
movies_full_scan_subtitles
|
||||||
|
from get_subtitle import episode_download_subtitles
|
||||||
|
|
||||||
|
|
||||||
def update_all_episodes():
|
def update_all_episodes():
|
||||||
|
@ -37,7 +38,7 @@ def sync_episodes():
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
|
|
||||||
# Get current episodes id in DB
|
# Get current episodes id in DB
|
||||||
current_episodes_db = c.execute('SELECT sonarrEpisodeId, path FROM table_episodes').fetchall()
|
current_episodes_db = c.execute('SELECT sonarrEpisodeId, path, sonarrSeriesId FROM table_episodes').fetchall()
|
||||||
|
|
||||||
current_episodes_db_list = [x[0] for x in current_episodes_db]
|
current_episodes_db_list = [x[0] for x in current_episodes_db]
|
||||||
current_episodes_sonarr = []
|
current_episodes_sonarr = []
|
||||||
|
@ -137,7 +138,7 @@ def sync_episodes():
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# Get episodes list after INSERT and UPDATE
|
# Get episodes list after INSERT and UPDATE
|
||||||
episodes_now_in_db = c.execute('SELECT sonarrEpisodeId, path FROM table_episodes').fetchall()
|
episodes_now_in_db = c.execute('SELECT sonarrEpisodeId, path, sonarrSeriesId FROM table_episodes').fetchall()
|
||||||
|
|
||||||
# Close database connection
|
# Close database connection
|
||||||
c.close()
|
c.close()
|
||||||
|
@ -146,11 +147,17 @@ def sync_episodes():
|
||||||
altered_episodes = set(episodes_now_in_db).difference(set(current_episodes_db))
|
altered_episodes = set(episodes_now_in_db).difference(set(current_episodes_db))
|
||||||
for altered_episode in altered_episodes:
|
for altered_episode in altered_episodes:
|
||||||
store_subtitles(path_replace(altered_episode[1]))
|
store_subtitles(path_replace(altered_episode[1]))
|
||||||
|
list_missing_subtitles(altered_episode[2])
|
||||||
|
|
||||||
logging.debug('BAZARR All episodes synced from Sonarr into database.')
|
logging.debug('BAZARR All episodes synced from Sonarr into database.')
|
||||||
|
|
||||||
list_missing_subtitles()
|
# Search for desired subtitles if no more than 5 episodes have been added.
|
||||||
logging.debug('BAZARR All missing subtitles updated in database.')
|
if len(altered_episodes) <= 5:
|
||||||
|
logging.debug("BAZARR No more than 5 episodes were added during this sync then we'll search for subtitles.")
|
||||||
|
for altered_episode in altered_episodes:
|
||||||
|
episode_download_subtitles(altered_episode[0])
|
||||||
|
else:
|
||||||
|
logging.debug("BAZARR More than 5 episodes were added during this sync then we wont search for subtitles.")
|
||||||
|
|
||||||
notifications.write(msg='Episodes sync from Sonarr ended.', queue='get_episodes')
|
notifications.write(msg='Episodes sync from Sonarr ended.', queue='get_episodes')
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ from get_args import args
|
||||||
from config import settings, url_radarr
|
from config import settings, url_radarr
|
||||||
from helper import path_replace_movie
|
from helper import path_replace_movie
|
||||||
from list_subtitles import store_subtitles_movie, list_missing_subtitles_movies
|
from list_subtitles import store_subtitles_movie, list_missing_subtitles_movies
|
||||||
|
from get_subtitle import movies_download_subtitles
|
||||||
|
|
||||||
|
|
||||||
def update_movies():
|
def update_movies():
|
||||||
|
@ -42,7 +43,7 @@ def update_movies():
|
||||||
# Get current movies in DB
|
# Get current movies in DB
|
||||||
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
current_movies_db = c.execute('SELECT tmdbId, path FROM table_movies').fetchall()
|
current_movies_db = c.execute('SELECT tmdbId, path, radarrId FROM table_movies').fetchall()
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
current_movies_db_list = [x[0] for x in current_movies_db]
|
current_movies_db_list = [x[0] for x in current_movies_db]
|
||||||
|
@ -175,7 +176,7 @@ def update_movies():
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# Get movies list after INSERT and UPDATE
|
# Get movies list after INSERT and UPDATE
|
||||||
movies_now_in_db = c.execute('SELECT tmdbId, path FROM table_movies').fetchall()
|
movies_now_in_db = c.execute('SELECT tmdbId, path, radarrId FROM table_movies').fetchall()
|
||||||
|
|
||||||
# Close database connection
|
# Close database connection
|
||||||
db.close()
|
db.close()
|
||||||
|
@ -184,12 +185,18 @@ def update_movies():
|
||||||
altered_movies = set(movies_now_in_db).difference(set(current_movies_db))
|
altered_movies = set(movies_now_in_db).difference(set(current_movies_db))
|
||||||
for altered_movie in altered_movies:
|
for altered_movie in altered_movies:
|
||||||
store_subtitles_movie(path_replace_movie(altered_movie[1]))
|
store_subtitles_movie(path_replace_movie(altered_movie[1]))
|
||||||
|
list_missing_subtitles_movies(altered_movie[2])
|
||||||
|
|
||||||
|
# Search for desired subtitles if no more than 5 movies have been added.
|
||||||
|
if len(altered_movies) <= 5:
|
||||||
|
logging.debug("BAZARR No more than 5 movies were added during this sync then we'll search for subtitles.")
|
||||||
|
for altered_movie in altered_movies:
|
||||||
|
movies_download_subtitles(altered_movie[2])
|
||||||
|
else:
|
||||||
|
logging.debug("BAZARR More than 5 movies were added during this sync then we wont search for subtitles.")
|
||||||
|
|
||||||
logging.debug('BAZARR All movies synced from Radarr into database.')
|
logging.debug('BAZARR All movies synced from Radarr into database.')
|
||||||
|
|
||||||
list_missing_subtitles_movies()
|
|
||||||
logging.debug('BAZARR All movie missing subtitles updated in database.')
|
|
||||||
|
|
||||||
notifications.write(msg="Update movies list from Radarr is ended.", queue='get_movies')
|
notifications.write(msg="Update movies list from Radarr is ended.", queue='get_movies')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -469,6 +469,43 @@ def series_download_subtitles(no):
|
||||||
notifications.write(msg='Searching completed. Please reload the page.', type='success', duration='permanent', button='refresh', queue='get_subtitle')
|
notifications.write(msg='Searching completed. Please reload the page.', type='success', duration='permanent', button='refresh', queue='get_subtitle')
|
||||||
|
|
||||||
|
|
||||||
|
def episode_download_subtitles(no):
|
||||||
|
if settings.sonarr.getboolean('only_monitored'):
|
||||||
|
monitored_only_query_string = ' AND monitored = "True"'
|
||||||
|
else:
|
||||||
|
monitored_only_query_string = ""
|
||||||
|
|
||||||
|
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||||
|
c_db = conn_db.cursor()
|
||||||
|
episodes_details = c_db.execute(
|
||||||
|
'SELECT table_episodes.path, table_episodes.missing_subtitles, table_episodes.sonarrEpisodeId, table_episodes.scene_name, table_shows.hearing_impaired, table_shows.title, table_shows.sonarrSeriesId FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.sonarrEpisodeId = ?' + monitored_only_query_string, (no,)).fetchall()
|
||||||
|
c_db.close()
|
||||||
|
|
||||||
|
providers_list = get_providers()
|
||||||
|
providers_auth = get_providers_auth()
|
||||||
|
|
||||||
|
for episode in episodes_details:
|
||||||
|
for language in ast.literal_eval(episode[1]):
|
||||||
|
if language is not None:
|
||||||
|
notifications.write(msg='Searching for ' + str(
|
||||||
|
language_from_alpha2(language)) + ' subtitles for this episode: ' + path_replace(episode[0]),
|
||||||
|
queue='get_subtitle')
|
||||||
|
result = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(language)),
|
||||||
|
episode[4], providers_list, providers_auth, str(episode[3]),
|
||||||
|
episode[5], 'series')
|
||||||
|
if result is not None:
|
||||||
|
message = result[0]
|
||||||
|
path = result[1]
|
||||||
|
language_code = result[2]
|
||||||
|
provider = result[3]
|
||||||
|
score = result[4]
|
||||||
|
store_subtitles(path_replace(episode[0]))
|
||||||
|
history_log(1, episode[6], episode[2], message, path, language_code, provider, score)
|
||||||
|
send_notifications(episode[6], episode[2], message)
|
||||||
|
|
||||||
|
list_missing_subtitles(episode[6])
|
||||||
|
|
||||||
|
|
||||||
def movies_download_subtitles(no):
|
def movies_download_subtitles(no):
|
||||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||||
c_db = conn_db.cursor()
|
c_db = conn_db.cursor()
|
||||||
|
|
|
@ -1762,7 +1762,7 @@ def remove_subtitles_movie():
|
||||||
list_missing_subtitles_movies(radarrId)
|
list_missing_subtitles_movies(radarrId)
|
||||||
|
|
||||||
|
|
||||||
@route(base_url + 'get_subtitle', method='POST')
|
@route(base_url + 'INNtle', method='POST')
|
||||||
@custom_auth_basic(check_credentials)
|
@custom_auth_basic(check_credentials)
|
||||||
def get_subtitle():
|
def get_subtitle():
|
||||||
authorize()
|
authorize()
|
||||||
|
@ -1956,7 +1956,7 @@ def api_wanted():
|
||||||
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
data = c.execute(
|
data = c.execute(
|
||||||
"SELECT table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_episodes.missing_subtitles FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.missing_subtitles != '[]' ORDER BY table_episodes._rowid_ DESC LIMIT 10").fetchall()
|
"SELECT table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_episodes.missing_subtitles FROM table_episodes prin WHERE table_episodes.missing_subtitles != '[]' ORDER BY table_episodes._rowid_ DESC LIMIT 10").fetchall()
|
||||||
c.close()
|
c.close()
|
||||||
return dict(subtitles=data)
|
return dict(subtitles=data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue