summaryrefslogtreecommitdiffhomepage
path: root/tests/subliminal_patch/test_subdivx.py
blob: 26afdedde774c3c283f42675b8fe6287cc6d3368 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# -*- coding: utf-8 -*-

import pytest
import copy

from subliminal_patch.providers.subdivx import SubdivxSubtitlesProvider
from subliminal_patch.providers.subdivx import SubdivxSubtitle
from subliminal_patch.core import SZProviderPool
from subliminal_patch.core import Episode
from subzero.language import Language


def test_list_subtitles_movie(movies):
    item = movies["dune"]
    with SubdivxSubtitlesProvider() as provider:
        subtitles = provider.list_subtitles(item, {Language("spa", "MX")})
        assert len(subtitles) >= 9


def test_list_subtitles_movie_with_year_fallback(movies):
    item = list(movies.values())[0]
    item.title = "Everything Everywhere All at Once"
    item.year = 2022

    with SubdivxSubtitlesProvider() as provider:
        assert provider.list_subtitles(item, {Language("spa", "MX")})


def test_handle_multi_page_search(episodes):
    with SubdivxSubtitlesProvider() as provider:
        for _ in provider._handle_multi_page_search(
            "Game Of Thrones", episodes["got_s03e10"]
        ):
            pass


@pytest.mark.parametrize(
    "episode_key,expected", [("breaking_bad_s01e01", 15), ("inexistent", 0)]
)
def test_list_subtitles_episode(episodes, episode_key, expected):
    item = episodes[episode_key]
    with SubdivxSubtitlesProvider() as provider:
        subtitles = provider.list_subtitles(item, {Language("spa", "MX")})
        assert len(subtitles) >= expected


def test_list_subtitles_castillian_spanish(episodes):
    item = episodes["better_call_saul_s06e04"]
    with SubdivxSubtitlesProvider() as provider:
        assert provider.list_subtitles(item, {Language.fromietf("es")})


def test_list_subtitles_episode_with_title_only_fallback(episodes):
    item = list(episodes.values())[0]
    item.series = "The Bear"
    item.name = "The Bear"
    item.season = 1
    item.episode = 1

    with SubdivxSubtitlesProvider() as provider:
        subtitles = provider.list_subtitles(item, {Language("spa", "MX")})
        assert len(subtitles) > 2


def test_download_subtitle(movies):
    subtitle = SubdivxSubtitle(
        Language("spa", "MX"),
        movies["dune"],
        "https://www.subdivx.com/X66XNjMxMTAxX-dune--2021-aka-dune-part-one.html",
        "Dune",
        "",
        "",
        "https://www.subdivx.com/bajar.php?id=631101&u=9",
    )
    with SubdivxSubtitlesProvider() as provider:
        provider.download_subtitle(subtitle)
        assert subtitle.content is not None


def test_download_subtitle_episode_pack(episodes):
    video = copy.copy(episodes["breaking_bad_s01e01"])
    video.episode = 3

    subtitle = SubdivxSubtitle(
        Language("spa", "MX"),
        video,
        "https://www.subdivx.com/X66XMzY1NjEwX-breaking-bad-s01e0107.html",
        "Breaking Bad S01E01-07",
        "Son los del torrent que vienen Formato / Dimensiones 624x352 / Tamaño 351 MB -Incluye los Torrents-",
        "",
        "https://www.subdivx.com/bajar.php?id=365610&u=7",
    )
    with SubdivxSubtitlesProvider() as provider:
        provider.download_subtitle(subtitle)
        assert subtitle.content is not None


@pytest.fixture
def video():
    return Episode(
        **{
            "name": "/tv/SEAL Team/Season 5/SEAL.Team.S05E11.1080p.WEB.H264-CAKES[rarbg].mkv",
            "release_group": "CAKES",
            "series": "SEAL Team",
            "source": "Web",
            "resolution": "1080p",
            "video_codec": "H.264",
            "season": 5,
            "episode": 11,
            "title": "Violence of Action",
            "alternative_series": [],
        }
    )


def test_subtitle_description_not_lowercase(video):
    with SubdivxSubtitlesProvider() as provider:
        subtitles = provider.list_subtitles(video, {Language("spa", "MX")})
        assert subtitles
        assert not subtitles[0]._description.islower()


def test_subtitle_matches(video):
    subtitle = SubdivxSubtitle(
        Language("spa", "MX"),
        video,
        "SEAL Team S05E10",
        "https://www.subdivx.com/X66XNjM1MTAxX-seal-team-s05e10.html",
        (
            "Mi subtítulo y sincronización en Español neutro, para SEAL TEAM -Temp 05x10 "
            "Head On para WEB.H265-GGWP, NTb 1080p, WEB-H264.CAKES, WEBRip.x264-ION10 y "
            "otras seguramente, gracias por sus comentarios, saludos."
        ),
        "tolobich",
        "https://www.subdivx.com/bajar.php?id=635101&u=9",
    )

    matches = subtitle.get_matches(video)
    assert "source" in matches
    assert "resolution" in matches
    assert "video_codec" in matches
    assert "release_group" in matches