diff options
author | Vitiko <[email protected]> | 2024-01-28 17:18:48 -0400 |
---|---|---|
committer | Vitiko <[email protected]> | 2024-01-28 17:18:48 -0400 |
commit | deef13d11b9310384d71cb0a4af230a524541359 (patch) | |
tree | 4c20a15cc49acc3e4b6c7b019427ddddcc140dbb /libs | |
parent | d758c53b412ab8bcd5927beba13ff5a56b266c17 (diff) | |
download | bazarr-deef13d11b9310384d71cb0a4af230a524541359.tar.gz bazarr-deef13d11b9310384d71cb0a4af230a524541359.zip |
Add Argenteam Dump Provider
Diffstat (limited to 'libs')
-rw-r--r-- | libs/subliminal_patch/providers/argenteamdump.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/libs/subliminal_patch/providers/argenteamdump.py b/libs/subliminal_patch/providers/argenteamdump.py new file mode 100644 index 000000000..127f5a6d9 --- /dev/null +++ b/libs/subliminal_patch/providers/argenteamdump.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- +import logging + +from requests import Session +from subliminal_patch.core import Episode +from subliminal_patch.core import Movie +from subliminal_patch.providers import Provider +from subliminal_patch.providers.utils import get_archive_from_bytes +from subliminal_patch.providers.utils import get_subtitle_from_archive +from subliminal_patch.providers.utils import update_matches +from subliminal_patch.subtitle import Subtitle +from subzero.language import Language + +logger = logging.getLogger(__name__) + + +class ArgenteamSubtitle(Subtitle): + provider_name = "argenteam_dump" + hash_verifiable = False + hearing_impaired_verifiable = True + + def __init__(self, language, rel_path, release_info, matches=None): + super().__init__(language, hearing_impaired=language.hi) + self.release_info = release_info + self.rel_path = rel_path + self._matches = matches or set() + + def get_matches(self, video): + update_matches(self._matches, video, self.release_info) + return self._matches + + @property + def id(self): + return f"{self.provider_name}_{self.rel_path}" + + +_BASE_URL = "https://argt.caretas.club" + + +class ArgenteamDumpProvider(Provider): + provider_name = "argenteam_dump" + + video_types = (Movie, Episode) + subtitle_class = ArgenteamSubtitle + + languages = {Language("spa", "MX")} + _language = Language("spa", "MX") + + def __init__(self) -> None: + self._session = Session() + self._session.headers.update({"User-Agent": "Bazarr"}) + + def initialize(self): + pass + + def terminate(self): + self._session.close() + + def list_subtitles(self, video, languages): + episode = None + if isinstance(video, Movie): + params = {"query": video.title} + matches = {"title"} + endpoint = f"{_BASE_URL}/search/movies/" + else: + params = { + "query": video.series, + "season": video.season, + "episode": video.episode, + } + matches = {"tvdb_id", "imdb_id", "series", "title", "episode", "season"} + endpoint = f"{_BASE_URL}/search/episodes/" + + response = self._session.get(endpoint, params=params) + response.raise_for_status() + items = response.json() + if not items: + return [] + + subs = [] + for item in items: + subs.append( + ArgenteamSubtitle( + self._language, item["rel_path"], item["release_info"], matches + ) + ) + + return subs + + def download_subtitle(self, subtitle): + response = self._session.get( + f"{_BASE_URL}/download/", params={"rel_path": subtitle.rel_path} + ) + response.raise_for_status() + archive = get_archive_from_bytes(response.content) + subtitle.content = get_subtitle_from_archive(archive) |