Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce AvistaZ and CinemaZ subtitles provider (via web scraping) #2375

Merged
merged 18 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions bazarr/radarr/sync/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,32 @@ def get_movies_from_radarr_api(apikey_radarr, radarr_id=None):
return r.json()
else:
return


def get_history_from_radarr_api(apikey_radarr, movie_id):
url_sonarr_api_episode = f"{url_api_radarr()}history?eventType=1&movieIds={movie_id}&apikey={apikey_radarr}"

try:
r = requests.get(url_sonarr_api_episode, timeout=int(settings.sonarr.http_timeout), verify=False,
headers=headers)
r.raise_for_status()
except requests.exceptions.HTTPError:
logging.exception("BAZARR Error trying to get history from Sonarr. Http error.")
return
except requests.exceptions.ConnectionError:
logging.exception("BAZARR Error trying to get history from Sonarr. Connection Error.")
return
except requests.exceptions.Timeout:
logging.exception("BAZARR Error trying to get history from Sonarr. Timeout Error.")
return
except requests.exceptions.RequestException:
logging.exception("BAZARR Error trying to get history from Sonarr.")
return
except Exception as e:
logging.exception(f"Exception raised while getting history from Sonarr API: {e}")
return
else:
if r.status_code == 200:
return r.json()
else:
return
43 changes: 22 additions & 21 deletions bazarr/sonarr/sync/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,32 @@ def get_episodes_from_sonarr_api(apikey_sonarr, series_id=None, episode_id=None)
return


def get_history_from_sonarr_api(apikey_sonarr, episode_id=None):
url_sonarr_api_episode = f"{url_api_sonarr()}history?eventType=1&episodeId={episode_id}&apikey={apikey_sonarr}"
def get_episodesFiles_from_sonarr_api(apikey_sonarr, series_id=None, episode_file_id=None):
if series_id:
url_sonarr_api_episodeFiles = f"{url_api_sonarr()}episodeFile?seriesId={series_id}&apikey={apikey_sonarr}"
elif episode_file_id:
url_sonarr_api_episodeFiles = f"{url_api_sonarr()}episodeFile/{episode_file_id}?apikey={apikey_sonarr}"
else:
return

try:
r = requests.get(url_sonarr_api_episode, timeout=int(settings.sonarr.http_timeout), verify=False, headers=headers)
r = requests.get(url_sonarr_api_episodeFiles, timeout=int(settings.sonarr.http_timeout), verify=False,
headers=headers)
r.raise_for_status()
except requests.exceptions.HTTPError:
logging.exception("BAZARR Error trying to get history from Sonarr. Http error.")
logging.exception("BAZARR Error trying to get episodeFiles from Sonarr. Http error.")
return
except requests.exceptions.ConnectionError:
logging.exception("BAZARR Error trying to get history from Sonarr. Connection Error.")
logging.exception("BAZARR Error trying to get episodeFiles from Sonarr. Connection Error.")
return
except requests.exceptions.Timeout:
logging.exception("BAZARR Error trying to get history from Sonarr. Timeout Error.")
logging.exception("BAZARR Error trying to get episodeFiles from Sonarr. Timeout Error.")
return
except requests.exceptions.RequestException:
logging.exception("BAZARR Error trying to get history from Sonarr.")
logging.exception("BAZARR Error trying to get episodeFiles from Sonarr.")
return
except Exception as e:
logging.exception(f"Exception raised while getting history from Sonarr API: {e}")
logging.exception(f"Exception raised while getting episodes from Sonarr API: {e}")
return
else:
if r.status_code == 200:
Expand All @@ -162,32 +168,27 @@ def get_history_from_sonarr_api(apikey_sonarr, episode_id=None):
return


def get_episodesFiles_from_sonarr_api(apikey_sonarr, series_id=None, episode_file_id=None):
if series_id:
url_sonarr_api_episodeFiles = f"{url_api_sonarr()}episodeFile?seriesId={series_id}&apikey={apikey_sonarr}"
elif episode_file_id:
url_sonarr_api_episodeFiles = f"{url_api_sonarr()}episodeFile/{episode_file_id}?apikey={apikey_sonarr}"
else:
return
def get_history_from_sonarr_api(apikey_sonarr, episode_id):
url_sonarr_api_episode = f"{url_api_sonarr()}history?eventType=1&episodeId={episode_id}&apikey={apikey_sonarr}"

try:
r = requests.get(url_sonarr_api_episodeFiles, timeout=int(settings.sonarr.http_timeout), verify=False,
r = requests.get(url_sonarr_api_episode, timeout=int(settings.sonarr.http_timeout), verify=False,
headers=headers)
r.raise_for_status()
except requests.exceptions.HTTPError:
logging.exception("BAZARR Error trying to get episodeFiles from Sonarr. Http error.")
logging.exception("BAZARR Error trying to get history from Sonarr. Http error.")
return
except requests.exceptions.ConnectionError:
logging.exception("BAZARR Error trying to get episodeFiles from Sonarr. Connection Error.")
logging.exception("BAZARR Error trying to get history from Sonarr. Connection Error.")
return
except requests.exceptions.Timeout:
logging.exception("BAZARR Error trying to get episodeFiles from Sonarr. Timeout Error.")
logging.exception("BAZARR Error trying to get history from Sonarr. Timeout Error.")
return
except requests.exceptions.RequestException:
logging.exception("BAZARR Error trying to get episodeFiles from Sonarr.")
logging.exception("BAZARR Error trying to get history from Sonarr.")
return
except Exception as e:
logging.exception(f"Exception raised while getting episodes from Sonarr API: {e}")
logging.exception(f"Exception raised while getting history from Sonarr API: {e}")
return
else:
if r.status_code == 200:
Expand Down
4 changes: 2 additions & 2 deletions bazarr/subtitles/refiners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from .ffprobe import refine_from_ffprobe
from .database import refine_from_db
from .sonarr import refine_from_sonarr
from .arr_history import refine_from_arr_history

registered = {
"database": refine_from_db,
"ffprobe": refine_from_ffprobe,
"sonarr": refine_from_sonarr,
"arr_history": refine_from_arr_history,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
import logging

from app.config import settings
from guessit import guessit
from sonarr.info import url_api_sonarr
from radarr.sync.utils import get_history_from_radarr_api
from sonarr.sync.utils import get_history_from_sonarr_api
from subliminal import Movie
from subliminal import Episode, Movie

from utilities.path_mappings import path_mappings
from app.database import TableEpisodes, TableMovies, database, select
from utilities.video_analyzer import parse_video_metadata


def refine_from_sonarr(path, video):
refine_info_url(video)
def refine_from_arr_history(path, video):
if 'avistaz' in settings.general.enabled_providers and video.info_url is None:
refine_info_url(video)


def refine_info_url(video):
history = get_history_from_sonarr_api(settings.sonarr.apikey, video.sonarrEpisodeId)
if isinstance(video, Episode):
history = get_history_from_sonarr_api(settings.sonarr.apikey, video.sonarrEpisodeId)
else:
history = get_history_from_radarr_api(settings.radarr.apikey, video.radarrId)

for grab in history['records']:
if ('releaseGroup' in grab['data'] and grab['data']['releaseGroup'] == video.release_group
and 'nzbInfoUrl' in grab['data'] and grab['data']['nzbInfoUrl']):
Expand Down
Loading