Skip to content

Commit

Permalink
Subdl Provider: add tests and use standard utils
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiko98 committed Jul 14, 2024
1 parent 127a7ae commit 91a3531
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
7 changes: 2 additions & 5 deletions custom_libs/subliminal_patch/providers/subdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
from subliminal_patch.subtitle import Subtitle
from subliminal.subtitle import fix_line_ending
from subliminal_patch.providers import Provider
from subliminal_patch.subtitle import guess_matches
from guessit import guessit
from subliminal_patch.providers import utils

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -57,7 +56,6 @@ def id(self):

def get_matches(self, video):
matches = set()
type_ = "movie" if isinstance(video, Movie) else "episode"

# handle movies and series separately
if isinstance(video, Episode):
Expand All @@ -77,8 +75,7 @@ def get_matches(self, video):
# imdb
matches.add('imdb_id')

# other properties
matches |= guess_matches(video, guessit(self.release_info, {"type": type_}))
utils.update_matches(matches, video, self.release_info)

self.matches = matches

Expand Down
36 changes: 36 additions & 0 deletions tests/subliminal_patch/test_subdl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os

import pytest
from subliminal_patch.providers.subdl import SubdlProvider
from subliminal_patch.providers.subdl import SubdlSubtitle


@pytest.fixture(scope="session")
def provider():
with SubdlProvider(os.environ["SUBDL_TOKEN"]) as provider:
yield provider


def test_list_subtitles_movie(provider, movies, languages):
for sub in provider.list_subtitles(movies["dune"], {languages["en"]}):
assert sub.language == languages["en"]


def test_download_subtitle(provider, languages):
data = {
"language": languages["en"],
"forced": False,
"hearing_impaired": False,
"page_link": "https://subdl.com/s/info/ebC6BrLCOC",
"download_link": "/subtitle/2808552-2770424.zip",
"file_id": "SUBDL::dune-2021-2770424.zip",
"release_names": ["Dune Part 1 WebDl"],
"uploader": "makoto77",
"season": 0,
"episode": None,
}

sub = SubdlSubtitle(**data)
provider.download_subtitle(sub)

assert sub.is_valid()

0 comments on commit 91a3531

Please sign in to comment.