|
|
@ -3,8 +3,9 @@
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
from database import get_exclusion_clause, TableEpisodes, TableShows
|
|
|
|
from gevent import sleep
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from database import get_exclusion_clause, TableEpisodes, TableShows
|
|
|
|
from config import settings, url_sonarr
|
|
|
|
from config import settings, url_sonarr
|
|
|
|
from helper import path_mappings
|
|
|
|
from helper import path_mappings
|
|
|
|
from list_subtitles import store_subtitles, series_full_scan_subtitles
|
|
|
|
from list_subtitles import store_subtitles, series_full_scan_subtitles
|
|
|
@ -42,6 +43,7 @@ def sync_episodes(series_id=None, send_event=True):
|
|
|
|
|
|
|
|
|
|
|
|
series_count = len(seriesIdList)
|
|
|
|
series_count = len(seriesIdList)
|
|
|
|
for i, seriesId in enumerate(seriesIdList, 1):
|
|
|
|
for i, seriesId in enumerate(seriesIdList, 1):
|
|
|
|
|
|
|
|
sleep()
|
|
|
|
if send_event:
|
|
|
|
if send_event:
|
|
|
|
show_progress(id='episodes_progress',
|
|
|
|
show_progress(id='episodes_progress',
|
|
|
|
header='Syncing episodes...',
|
|
|
|
header='Syncing episodes...',
|
|
|
@ -56,6 +58,7 @@ def sync_episodes(series_id=None, send_event=True):
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
for episode in episodes:
|
|
|
|
for episode in episodes:
|
|
|
|
|
|
|
|
sleep()
|
|
|
|
if 'hasFile' in episode:
|
|
|
|
if 'hasFile' in episode:
|
|
|
|
if episode['hasFile'] is True:
|
|
|
|
if episode['hasFile'] is True:
|
|
|
|
if 'episodeFile' in episode:
|
|
|
|
if 'episodeFile' in episode:
|
|
|
@ -82,6 +85,7 @@ def sync_episodes(series_id=None, send_event=True):
|
|
|
|
removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))
|
|
|
|
removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))
|
|
|
|
|
|
|
|
|
|
|
|
for removed_episode in removed_episodes:
|
|
|
|
for removed_episode in removed_episodes:
|
|
|
|
|
|
|
|
sleep()
|
|
|
|
episode_to_delete = TableEpisodes.select(TableEpisodes.sonarrSeriesId, TableEpisodes.sonarrEpisodeId)\
|
|
|
|
episode_to_delete = TableEpisodes.select(TableEpisodes.sonarrSeriesId, TableEpisodes.sonarrEpisodeId)\
|
|
|
|
.where(TableEpisodes.sonarrEpisodeId == removed_episode)\
|
|
|
|
.where(TableEpisodes.sonarrEpisodeId == removed_episode)\
|
|
|
|
.dicts()\
|
|
|
|
.dicts()\
|
|
|
@ -114,6 +118,7 @@ def sync_episodes(series_id=None, send_event=True):
|
|
|
|
episodes_to_update_list = [i for i in episodes_to_update if i not in episode_in_db_list]
|
|
|
|
episodes_to_update_list = [i for i in episodes_to_update if i not in episode_in_db_list]
|
|
|
|
|
|
|
|
|
|
|
|
for updated_episode in episodes_to_update_list:
|
|
|
|
for updated_episode in episodes_to_update_list:
|
|
|
|
|
|
|
|
sleep()
|
|
|
|
TableEpisodes.update(updated_episode).where(TableEpisodes.sonarrEpisodeId ==
|
|
|
|
TableEpisodes.update(updated_episode).where(TableEpisodes.sonarrEpisodeId ==
|
|
|
|
updated_episode['sonarrEpisodeId']).execute()
|
|
|
|
updated_episode['sonarrEpisodeId']).execute()
|
|
|
|
altered_episodes.append([updated_episode['sonarrEpisodeId'],
|
|
|
|
altered_episodes.append([updated_episode['sonarrEpisodeId'],
|
|
|
@ -122,6 +127,7 @@ def sync_episodes(series_id=None, send_event=True):
|
|
|
|
|
|
|
|
|
|
|
|
# Insert new episodes in DB
|
|
|
|
# Insert new episodes in DB
|
|
|
|
for added_episode in episodes_to_add:
|
|
|
|
for added_episode in episodes_to_add:
|
|
|
|
|
|
|
|
sleep()
|
|
|
|
result = TableEpisodes.insert(added_episode).on_conflict(action='IGNORE').execute()
|
|
|
|
result = TableEpisodes.insert(added_episode).on_conflict(action='IGNORE').execute()
|
|
|
|
if result > 0:
|
|
|
|
if result > 0:
|
|
|
|
altered_episodes.append([added_episode['sonarrEpisodeId'],
|
|
|
|
altered_episodes.append([added_episode['sonarrEpisodeId'],
|
|
|
@ -135,6 +141,7 @@ def sync_episodes(series_id=None, send_event=True):
|
|
|
|
|
|
|
|
|
|
|
|
# Store subtitles for added or modified episodes
|
|
|
|
# Store subtitles for added or modified episodes
|
|
|
|
for i, altered_episode in enumerate(altered_episodes, 1):
|
|
|
|
for i, altered_episode in enumerate(altered_episodes, 1):
|
|
|
|
|
|
|
|
sleep()
|
|
|
|
store_subtitles(altered_episode[1], path_mappings.path_replace(altered_episode[1]))
|
|
|
|
store_subtitles(altered_episode[1], path_mappings.path_replace(altered_episode[1]))
|
|
|
|
|
|
|
|
|
|
|
|
logging.debug('BAZARR All episodes synced from Sonarr into database.')
|
|
|
|
logging.debug('BAZARR All episodes synced from Sonarr into database.')
|
|
|
|