|
|
|
@ -3,6 +3,8 @@ import os
|
|
|
|
|
|
|
|
|
|
import fese
|
|
|
|
|
import pytest
|
|
|
|
|
import fese
|
|
|
|
|
from fese import FFprobeSubtitleStream
|
|
|
|
|
from subliminal_patch.core import Episode, Movie
|
|
|
|
|
from subliminal_patch.providers.embeddedsubtitles import EmbeddedSubtitlesProvider
|
|
|
|
|
from subzero.language import Language
|
|
|
|
@ -44,6 +46,7 @@ def config(tmpdir):
|
|
|
|
|
"cache_dir": tmpdir,
|
|
|
|
|
"ffprobe_path": None,
|
|
|
|
|
"ffmpeg_path": None,
|
|
|
|
|
"hi_fallback": False,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -68,6 +71,74 @@ def test_inexistent_video(video_inexistent):
|
|
|
|
|
assert len(subtitles) == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def fake_streams():
|
|
|
|
|
return {
|
|
|
|
|
"en_hi": FFprobeSubtitleStream(
|
|
|
|
|
{
|
|
|
|
|
"index": 3,
|
|
|
|
|
"codec_name": "subrip",
|
|
|
|
|
"disposition": {"default": 1, "hearing_impaired": 1},
|
|
|
|
|
"tags": {"language": "eng", "title": "English"},
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
"en": FFprobeSubtitleStream(
|
|
|
|
|
{
|
|
|
|
|
"index": 3,
|
|
|
|
|
"codec_name": "subrip",
|
|
|
|
|
"tags": {"language": "eng", "title": "English"},
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_subtitles_hi_fallback_one_stream(
|
|
|
|
|
video_single_language, fake_streams, mocker
|
|
|
|
|
):
|
|
|
|
|
with EmbeddedSubtitlesProvider(hi_fallback=True) as provider:
|
|
|
|
|
language = Language.fromalpha2("en")
|
|
|
|
|
mocker.patch(
|
|
|
|
|
"fese.FFprobeVideoContainer.get_subtitles",
|
|
|
|
|
return_value=[fake_streams["en_hi"]],
|
|
|
|
|
)
|
|
|
|
|
fake = fese.FFprobeVideoContainer.get_subtitles("")[0]
|
|
|
|
|
assert fake.disposition.hearing_impaired == True
|
|
|
|
|
|
|
|
|
|
subs = provider.list_subtitles(video_single_language, {language})
|
|
|
|
|
assert subs
|
|
|
|
|
assert subs[0].hearing_impaired == False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_subtitles_hi_fallback_multiple_streams(
|
|
|
|
|
video_single_language, fake_streams, mocker
|
|
|
|
|
):
|
|
|
|
|
with EmbeddedSubtitlesProvider(hi_fallback=True) as provider:
|
|
|
|
|
language = Language.fromalpha2("en")
|
|
|
|
|
mocker.patch(
|
|
|
|
|
"fese.FFprobeVideoContainer.get_subtitles",
|
|
|
|
|
return_value=[fake_streams["en_hi"], fake_streams["en"]],
|
|
|
|
|
)
|
|
|
|
|
subs = provider.list_subtitles(video_single_language, {language})
|
|
|
|
|
assert len(subs) == 2
|
|
|
|
|
assert subs[0].hearing_impaired == True
|
|
|
|
|
assert subs[1].hearing_impaired == False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_subtitles_hi_fallback_multiple_hi_streams(
|
|
|
|
|
video_single_language, fake_streams, mocker
|
|
|
|
|
):
|
|
|
|
|
with EmbeddedSubtitlesProvider(hi_fallback=True) as provider:
|
|
|
|
|
language = Language.fromalpha2("en")
|
|
|
|
|
mocker.patch(
|
|
|
|
|
"fese.FFprobeVideoContainer.get_subtitles",
|
|
|
|
|
return_value=[fake_streams["en_hi"], fake_streams["en_hi"]],
|
|
|
|
|
)
|
|
|
|
|
subs = provider.list_subtitles(video_single_language, {language})
|
|
|
|
|
assert len(subs) == 2
|
|
|
|
|
assert subs[0].hearing_impaired == False
|
|
|
|
|
assert subs[1].hearing_impaired == False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_subtitles_only_forced(video_single_language):
|
|
|
|
|
with EmbeddedSubtitlesProvider() as provider:
|
|
|
|
|
language = Language.fromalpha2("en")
|
|
|
|
|