diff options
-rw-r--r-- | frontend/src/pages/Settings/Providers/list.ts | 5 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/argenteamdump.py | 96 | ||||
-rw-r--r-- | tests/subliminal_patch/test_argenteam_dump.py | 22 |
3 files changed, 123 insertions, 0 deletions
diff --git a/frontend/src/pages/Settings/Providers/list.ts b/frontend/src/pages/Settings/Providers/list.ts index b70b989ce..f4f6dc471 100644 --- a/frontend/src/pages/Settings/Providers/list.ts +++ b/frontend/src/pages/Settings/Providers/list.ts @@ -64,6 +64,11 @@ export const ProviderList: Readonly<ProviderInfo[]> = [ ], }, { + key: "argenteam_dump", + name: "Argenteam Dump", + description: "Subtitles dump of the now extinct Argenteam", + }, + { key: "assrt", description: "Chinese Subtitles Provider", inputs: [ 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) diff --git a/tests/subliminal_patch/test_argenteam_dump.py b/tests/subliminal_patch/test_argenteam_dump.py new file mode 100644 index 000000000..15b784510 --- /dev/null +++ b/tests/subliminal_patch/test_argenteam_dump.py @@ -0,0 +1,22 @@ +import pytest +from subliminal_patch.providers.argenteamdump import ArgenteamDumpProvider +from subzero.language import Language + + +def test_list_subtitles_movies(movies): + languages = {Language("spa", "MX")} + with ArgenteamDumpProvider() as provider: + subtitles = provider.list_subtitles(movies["man_of_steel"], languages) + assert subtitles + + provider.download_subtitle(subtitles[0]) + assert subtitles[0].is_valid() + +def test_list_subtitles_episodes(episodes): + languages = {Language("spa", "MX")} + with ArgenteamDumpProvider() as provider: + subtitles = provider.list_subtitles(episodes["got_s03e10"], languages) + assert subtitles + + provider.download_subtitle(subtitles[0]) + assert subtitles[0].is_valid() |