pull/997/head
Louis Vézina 5 years ago
parent 1a30974cb7
commit e1c9c4c415

@ -30,7 +30,7 @@ from list_subtitles import store_subtitles, store_subtitles_movie, series_scan_s
list_missing_subtitles, list_missing_subtitles_movies list_missing_subtitles, list_missing_subtitles_movies
from utils import history_log, history_log_movie, get_sonarr_version, get_radarr_version from utils import history_log, history_log_movie, get_sonarr_version, get_radarr_version
from get_providers import get_providers, get_providers_auth, list_throttled_providers, reset_throttled_providers from get_providers import get_providers, get_providers_auth, list_throttled_providers, reset_throttled_providers
from websocket_handler import event_stream from event_handler import event_stream
from scheduler import Scheduler from scheduler import Scheduler
from subliminal_patch.core import SUBTITLE_EXTENSIONS from subliminal_patch.core import SUBTITLE_EXTENSIONS
@ -343,7 +343,7 @@ class Series(Resource):
list_missing_subtitles(no=seriesId) list_missing_subtitles(no=seriesId)
event_stream.write(type='series', action='update', series=seriesId) event_stream(type='series', action='update', series=seriesId)
return '', 204 return '', 204
@ -372,7 +372,7 @@ class SeriesEditSave(Resource):
else: else:
list_missing_subtitles(no=seriesid) list_missing_subtitles(no=seriesid)
event_stream.write(type='series', action='update', series=seriesid) event_stream(type='series', action='update', series=seriesid)
return '', 204 return '', 204
@ -493,7 +493,7 @@ class EpisodesSubtitlesDownload(Resource):
send_notifications(sonarrSeriesId, sonarrEpisodeId, message) send_notifications(sonarrSeriesId, sonarrEpisodeId, message)
store_subtitles(path, episodePath) store_subtitles(path, episodePath)
else: else:
event_stream.write(type='episode', action='update', series=int(sonarrSeriesId), episode=int(sonarrEpisodeId)) event_stream(type='episode', action='update', series=int(sonarrSeriesId), episode=int(sonarrEpisodeId))
return result, 201 return result, 201
except OSError: except OSError:
pass pass
@ -760,7 +760,7 @@ class Movies(Resource):
list_missing_subtitles_movies(no=radarrId) list_missing_subtitles_movies(no=radarrId)
event_stream.write(type='movie', action='update', movie=radarrId) event_stream(type='movie', action='update', movie=radarrId)
return '', 204 return '', 204
@ -789,7 +789,7 @@ class MoviesEditSave(Resource):
else: else:
list_missing_subtitles_movies(no=radarrid) list_missing_subtitles_movies(no=radarrid)
event_stream.write(type='movie', action='update', movie=radarrid) event_stream(type='movie', action='update', movie=radarrid)
return '', 204 return '', 204
@ -846,7 +846,7 @@ class MovieSubtitlesDownload(Resource):
send_notifications_movie(radarrId, message) send_notifications_movie(radarrId, message)
store_subtitles_movie(path, moviePath) store_subtitles_movie(path, moviePath)
else: else:
event_stream.write(type='movie', action='update', movie=int(radarrId)) event_stream(type='movie', action='update', movie=int(radarrId))
return result, 201 return result, 201
except OSError: except OSError:
pass pass

@ -0,0 +1,21 @@
import json
from app import socketio
def event_stream(type=None, action=None, series=None, episode=None, movie=None, task=None):
"""
:param type: The type of element.
:type type: str
:param action: The action type of element from insert, update, delete.
:type action: str
:param series: The series id.
:type series: str
:param episode: The episode id.
:type episode: str
:param movie: The movie id.
:type movie: str
:param task: The task id.
:type task: str
"""
socketio.emit('event', json.dumps({"type": type, "action": action, "series": series, "episode": episode,
"movie": movie, "task": task}))

@ -7,7 +7,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
from get_subtitle import episode_download_subtitles from get_subtitle import episode_download_subtitles
from websocket_handler import event_stream from event_handler import event_stream
def update_all_episodes(): def update_all_episodes():
@ -125,7 +125,7 @@ def sync_episodes():
episode_to_delete = database.execute("SELECT sonarrSeriesId, sonarrEpisodeId FROM table_episodes WHERE " episode_to_delete = database.execute("SELECT sonarrSeriesId, sonarrEpisodeId FROM table_episodes WHERE "
"sonarrEpisodeId=?", (removed_episode,), only_one=True) "sonarrEpisodeId=?", (removed_episode,), only_one=True)
database.execute("DELETE FROM table_episodes WHERE sonarrEpisodeId=?", (removed_episode,)) database.execute("DELETE FROM table_episodes WHERE sonarrEpisodeId=?", (removed_episode,))
event_stream.write(type='episode', action='delete', series=episode_to_delete['sonarrSeriesId'], event_stream(type='episode', action='delete', series=episode_to_delete['sonarrSeriesId'],
episode=episode_to_delete['sonarrEpisodeId']) episode=episode_to_delete['sonarrEpisodeId'])
# Update existing episodes in DB # Update existing episodes in DB
@ -155,7 +155,7 @@ def sync_episodes():
''')''', query.values) ''')''', query.values)
if result > 0: if result > 0:
altered_episodes.append([added_episode['sonarrEpisodeId'], added_episode['path']]) altered_episodes.append([added_episode['sonarrEpisodeId'], added_episode['path']])
event_stream.write(type='episode', action='insert', series=added_episode['sonarrSeriesId'], event_stream(type='episode', action='insert', series=added_episode['sonarrSeriesId'],
episode=added_episode['sonarrEpisodeId']) episode=added_episode['sonarrEpisodeId'])
else: else:
logging.debug('BAZARR unable to insert this episode into the database:{}'.format(path_replace(added_episode['path']))) logging.debug('BAZARR unable to insert this episode into the database:{}'.format(path_replace(added_episode['path'])))

@ -8,7 +8,7 @@ import time
from get_args import args from get_args import args
from config import settings from config import settings
from websocket_handler import event_stream from event_handler import event_stream
from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked
from subliminal.exceptions import DownloadLimitExceeded, ServiceUnavailable from subliminal.exceptions import DownloadLimitExceeded, ServiceUnavailable
from subliminal import region as subliminal_cache_region from subliminal import region as subliminal_cache_region
@ -251,7 +251,7 @@ def update_throttled_provider():
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle: with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(handle) settings.write(handle)
event_stream.write(type='badges') event_stream(type='badges')
def list_throttled_providers(): def list_throttled_providers():

@ -9,7 +9,7 @@ from list_subtitles import list_missing_subtitles
from database import database, dict_converter from database import database, dict_converter
from utils import get_sonarr_version from utils import get_sonarr_version
from helper import path_replace from helper import path_replace
from websocket_handler import event_stream from event_handler import event_stream
def update_series(): def update_series():
@ -115,7 +115,7 @@ def update_series():
for series in removed_series: for series in removed_series:
database.execute("DELETE FROM table_shows WHERE sonarrSeriesId=?",(series,)) database.execute("DELETE FROM table_shows WHERE sonarrSeriesId=?",(series,))
event_stream.write(type='series', action='delete', series=series) event_stream(type='series', action='delete', series=series)
# Update existing series in DB # Update existing series in DB
series_in_db_list = [] series_in_db_list = []
@ -131,7 +131,7 @@ def update_series():
query = dict_converter.convert(updated_series) query = dict_converter.convert(updated_series)
database.execute('''UPDATE table_shows SET ''' + query.keys_update + ''' WHERE sonarrSeriesId = ?''', database.execute('''UPDATE table_shows SET ''' + query.keys_update + ''' WHERE sonarrSeriesId = ?''',
query.values + (updated_series['sonarrSeriesId'],)) query.values + (updated_series['sonarrSeriesId'],))
event_stream.write(type='series', action='update', series=updated_series['sonarrSeriesId']) event_stream(type='series', action='update', series=updated_series['sonarrSeriesId'])
# Insert new series in DB # Insert new series in DB
for added_series in series_to_add: for added_series in series_to_add:
@ -145,7 +145,7 @@ def update_series():
logging.debug('BAZARR unable to insert this series into the database:', logging.debug('BAZARR unable to insert this series into the database:',
path_replace(added_series['path'])) path_replace(added_series['path']))
event_stream.write(type='series', action='insert', series=added_series['sonarrSeriesId']) event_stream(type='series', action='insert', series=added_series['sonarrSeriesId'])
logging.debug('BAZARR All series synced from Sonarr into database.') logging.debug('BAZARR All series synced from Sonarr into database.')

@ -19,7 +19,7 @@ from helper import path_replace, path_replace_movie, path_replace_reverse, \
path_replace_reverse_movie, get_subtitle_destination_folder path_replace_reverse_movie, get_subtitle_destination_folder
from embedded_subs_reader import embedded_subs_reader from embedded_subs_reader import embedded_subs_reader
from websocket_handler import event_stream from event_handler import event_stream
import chardet import chardet
gc.enable() gc.enable()
@ -234,9 +234,9 @@ def list_missing_subtitles(no=None, epno=None):
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])) (missing_subtitles_item[0], missing_subtitles_item[1]))
event_stream.write(type='episode', action='update', series=missing_subtitles_item[2], event_stream(type='episode', action='update', series=missing_subtitles_item[2],
episode=missing_subtitles_item[1]) episode=missing_subtitles_item[1])
event_stream.write(type='badges') event_stream(type='badges')
def list_missing_subtitles_movies(no=None): def list_missing_subtitles_movies(no=None):
@ -295,13 +295,12 @@ def list_missing_subtitles_movies(no=None):
database.execute("UPDATE table_movies SET missing_subtitles=? WHERE radarrId=?", database.execute("UPDATE table_movies SET missing_subtitles=? WHERE radarrId=?",
(missing_subtitles_item[0], missing_subtitles_item[1])) (missing_subtitles_item[0], missing_subtitles_item[1]))
event_stream.write(type='movie', action='update', movie=missing_subtitles_item[1]) event_stream(type='movie', action='update', movie=missing_subtitles_item[1])
event_stream.write(type='badges') event_stream(type='badges')
def series_full_scan_subtitles(): def series_full_scan_subtitles():
episodes = database.execute("SELECT path FROM table_episodes") episodes = database.execute("SELECT path FROM table_episodes")
count_episodes = len(episodes)
for i, episode in enumerate(episodes, 1): for i, episode in enumerate(episodes, 1):
store_subtitles(episode['path'], path_replace(episode['path'])) store_subtitles(episode['path'], path_replace(episode['path']))
@ -311,7 +310,6 @@ def series_full_scan_subtitles():
def movies_full_scan_subtitles(): def movies_full_scan_subtitles():
movies = database.execute("SELECT path FROM table_movies") movies = database.execute("SELECT path FROM table_movies")
count_movies = len(movies)
for i, movie in enumerate(movies, 1): for i, movie in enumerate(movies, 1):
store_subtitles_movie(movie['path'], path_replace_movie(movie['path'])) store_subtitles_movie(movie['path'], path_replace_movie(movie['path']))

@ -22,7 +22,7 @@ from tzlocal import get_localzone
from calendar import day_name from calendar import day_name
import pretty import pretty
from random import randrange from random import randrange
from websocket_handler import event_stream from event_handler import event_stream
class Scheduler: class Scheduler:
@ -36,12 +36,12 @@ class Scheduler:
def task_listener_add(event): def task_listener_add(event):
if event.job_id not in self.__running_tasks: if event.job_id not in self.__running_tasks:
self.__running_tasks.append(event.job_id) self.__running_tasks.append(event.job_id)
event_stream.write(type='task', task=event.job_id) event_stream(type='task', task=event.job_id)
def task_listener_remove(event): def task_listener_remove(event):
if event.job_id in self.__running_tasks: if event.job_id in self.__running_tasks:
self.__running_tasks.remove(event.job_id) self.__running_tasks.remove(event.job_id)
event_stream.write(type='task', task=event.job_id) event_stream(type='task', task=event.job_id)
self.aps_scheduler.add_listener(task_listener_add, EVENT_JOB_SUBMITTED) self.aps_scheduler.add_listener(task_listener_add, EVENT_JOB_SUBMITTED)
self.aps_scheduler.add_listener(task_listener_remove, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR) self.aps_scheduler.add_listener(task_listener_remove, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR)

@ -10,7 +10,7 @@ from whichcraft import which
from get_args import args from get_args import args
from config import settings, url_sonarr, url_radarr from config import settings, url_sonarr, url_radarr
from database import database from database import database
from websocket_handler import event_stream from event_handler import event_stream
from subliminal import region as subliminal_cache_region from subliminal import region as subliminal_cache_region
import datetime import datetime
@ -23,14 +23,14 @@ def history_log(action, sonarr_series_id, sonarr_episode_id, description, video_
"video_path, language, provider, score) VALUES (?,?,?,?,?,?,?,?,?)", "video_path, language, provider, score) VALUES (?,?,?,?,?,?,?,?,?)",
(action, sonarr_series_id, sonarr_episode_id, time.time(), description, video_path, language, (action, sonarr_series_id, sonarr_episode_id, time.time(), description, video_path, language,
provider, score)) provider, score))
event_stream.write(type='episodeHistory') event_stream(type='episodeHistory')
def history_log_movie(action, radarr_id, description, video_path=None, language=None, provider=None, score=None): def history_log_movie(action, radarr_id, description, video_path=None, language=None, provider=None, score=None):
database.execute("INSERT INTO table_history_movie (action, radarrId, timestamp, description, video_path, language, " database.execute("INSERT INTO table_history_movie (action, radarrId, timestamp, description, video_path, language, "
"provider, score) VALUES (?,?,?,?,?,?,?,?)", "provider, score) VALUES (?,?,?,?,?,?,?,?)",
(action, radarr_id, time.time(), description, video_path, language, provider, score)) (action, radarr_id, time.time(), description, video_path, language, provider, score))
event_stream.write(type='movieHistory') event_stream(type='movieHistory')
def get_binary(name): def get_binary(name):

@ -1,32 +0,0 @@
import json
from app import socketio
class EventStream:
"""
This class is used to broadcast notifications to web client.
"""
def __init__(self):
pass
def write(self, type=None, action=None, series=None, episode=None, movie=None, task=None):
"""
:param type: The type of element.
:type type: str
:param action: The action type of element from insert, update, delete.
:type action: str
:param series: The series id.
:type series: str
:param episode: The episode id.
:type episode: str
:param movie: The movie id.
:type movie: str
:param task: The task id.
:type task: str
"""
socketio.emit('event', json.dumps({"type": type, "action": action, "series": series, "episode": episode,
"movie": movie, "task": task}))
event_stream = EventStream()
Loading…
Cancel
Save