2019-09-15 19:00:38 +02:00
|
|
|
import os
|
2019-09-15 17:31:49 +02:00
|
|
|
import unittest
|
2020-10-12 14:18:50 +02:00
|
|
|
from unittest.mock import patch
|
2019-09-15 17:31:49 +02:00
|
|
|
|
2020-10-12 19:32:06 +02:00
|
|
|
from requests import Response
|
2019-09-15 19:00:38 +02:00
|
|
|
from svtplay_dl.fetcher import VideoRetriever
|
2019-09-15 17:31:49 +02:00
|
|
|
from svtplay_dl.postprocess import _checktracks
|
|
|
|
from svtplay_dl.postprocess import _getcodec
|
|
|
|
from svtplay_dl.postprocess import _streams
|
2019-09-15 19:00:38 +02:00
|
|
|
from svtplay_dl.postprocess import _sublanguage
|
|
|
|
from svtplay_dl.service import Service
|
|
|
|
from svtplay_dl.utils.parser import setup_defaults
|
2019-09-15 17:31:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
class streams(unittest.TestCase):
|
|
|
|
def test_audio1(self):
|
|
|
|
audio = _streams("Stream #1:0: Audio: aac (LC), 48000 Hz, stereo, fltp, 126 kb/s")
|
|
|
|
assert audio == [("1:0", "", "", "Audio", "aac (LC), 48000 Hz, stereo, fltp, 126 kb/s")]
|
|
|
|
|
|
|
|
def test_audio2(self):
|
|
|
|
audio = _streams("Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)")
|
|
|
|
assert audio == [("0:1", "(und)", "", "Audio", "aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)")]
|
|
|
|
|
|
|
|
def test_video1(self):
|
|
|
|
video = _streams(
|
2020-12-26 13:10:56 +01:00
|
|
|
"Stream #0:0[0x21]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc",
|
2019-09-15 17:31:49 +02:00
|
|
|
)
|
|
|
|
assert video == [
|
|
|
|
(
|
|
|
|
"0:0",
|
|
|
|
"[0x21]",
|
|
|
|
"",
|
|
|
|
"Video",
|
|
|
|
"h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc",
|
2020-12-26 13:10:56 +01:00
|
|
|
),
|
2019-09-15 17:31:49 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def test_video2(self):
|
|
|
|
video = _streams(
|
2020-12-26 13:10:56 +01:00
|
|
|
"Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 2710 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)",
|
2019-09-15 17:31:49 +02:00
|
|
|
)
|
|
|
|
assert video == [
|
|
|
|
(
|
|
|
|
"0:0",
|
|
|
|
"(und)",
|
|
|
|
"",
|
|
|
|
"Video",
|
|
|
|
"h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 2710 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)",
|
2020-12-26 13:10:56 +01:00
|
|
|
),
|
2019-09-15 17:31:49 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def test_video3(self):
|
|
|
|
video = _streams(
|
2020-12-26 13:10:56 +01:00
|
|
|
"Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 2710 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)",
|
2019-09-15 17:31:49 +02:00
|
|
|
)
|
|
|
|
assert video == [
|
|
|
|
(
|
|
|
|
"0:0",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"Video",
|
|
|
|
"h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 2710 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)",
|
2020-12-26 13:10:56 +01:00
|
|
|
),
|
2019-09-15 17:31:49 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class getcodec(unittest.TestCase):
|
|
|
|
def test_codec1(self):
|
|
|
|
assert (
|
|
|
|
_getcodec([("1:0", "", "", "Audio", "aac (LC), 48000 Hz, stereo, fltp, 126 kb/s")], "1:0") == "aac (LC), 48000 Hz, stereo, fltp, 126 kb/s"
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_codec2(self):
|
|
|
|
assert (
|
|
|
|
_getcodec(
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"0:0",
|
|
|
|
"[0x21]",
|
|
|
|
"",
|
|
|
|
"Video",
|
|
|
|
"h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc",
|
2020-12-26 13:10:56 +01:00
|
|
|
),
|
2019-09-15 17:31:49 +02:00
|
|
|
],
|
|
|
|
"0:0",
|
|
|
|
)
|
|
|
|
== "h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc"
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_codec3(self):
|
|
|
|
assert not (_getcodec([("1:0", "", "", "Audio", "aac (LC), 48000 Hz, stereo, fltp, 126 kb/s")], "0:0"))
|
|
|
|
|
|
|
|
|
|
|
|
class checktracks(unittest.TestCase):
|
|
|
|
def test_cktracks1(self):
|
2020-09-06 14:19:24 +02:00
|
|
|
assert (
|
|
|
|
_checktracks(
|
|
|
|
[
|
|
|
|
("1:0", "", "", "Audio", "aac (LC), 48000 Hz, stereo, fltp, 126 kb/s"),
|
|
|
|
(
|
|
|
|
"0:0",
|
|
|
|
"[0x21]",
|
|
|
|
"",
|
|
|
|
"Video",
|
|
|
|
"h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc",
|
|
|
|
),
|
2020-12-26 13:10:56 +01:00
|
|
|
],
|
2020-09-06 14:19:24 +02:00
|
|
|
)
|
|
|
|
== ("0:0", "1:0")
|
|
|
|
)
|
2019-09-15 17:31:49 +02:00
|
|
|
|
|
|
|
def test_cktracks2(self):
|
2020-09-06 14:19:24 +02:00
|
|
|
assert (
|
|
|
|
_checktracks(
|
|
|
|
[
|
|
|
|
("1:0", "", "", "Substr", "aac (LC), 48000 Hz, stereo, fltp, 126 kb/s"),
|
|
|
|
(
|
|
|
|
"0:0",
|
|
|
|
"[0x21]",
|
|
|
|
"",
|
|
|
|
"Video",
|
|
|
|
"h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc",
|
|
|
|
),
|
2020-12-26 13:10:56 +01:00
|
|
|
],
|
2020-09-06 14:19:24 +02:00
|
|
|
)
|
|
|
|
== ("0:0", None)
|
|
|
|
)
|
2019-09-15 17:31:49 +02:00
|
|
|
|
|
|
|
def test_cktracks3(self):
|
|
|
|
assert _checktracks([("1:0", "", "", "Audio", "aac (LC), 48000 Hz, stereo, fltp, 126 kb/s")]) == (None, "1:0")
|
|
|
|
|
|
|
|
def test_cktracks4(self):
|
|
|
|
assert _checktracks([("1:0", "", "", "Audio", "mp3, 0 channels")]) == (None, None)
|
2019-09-15 19:00:38 +02:00
|
|
|
|
|
|
|
|
2020-10-12 14:18:50 +02:00
|
|
|
@patch("svtplay_dl.postprocess.post")
|
2019-09-15 19:00:38 +02:00
|
|
|
class sublang(unittest.TestCase):
|
2020-10-12 14:18:50 +02:00
|
|
|
def setup_mock(self, req, lang):
|
|
|
|
class MockResponse(Response):
|
|
|
|
def __init__(self, lang, status=200):
|
|
|
|
self.status_code = status
|
|
|
|
self._json = {"language": lang}
|
|
|
|
|
|
|
|
def json(self):
|
|
|
|
return self._json
|
|
|
|
|
|
|
|
req.return_value = MockResponse(lang)
|
|
|
|
|
|
|
|
def test_sublang(self, req):
|
2019-09-15 19:00:38 +02:00
|
|
|
config = setup_defaults()
|
2020-10-12 14:18:50 +02:00
|
|
|
self.setup_mock(req, "swe")
|
2019-09-15 19:00:38 +02:00
|
|
|
config.set("output", os.path.join(os.path.dirname(os.path.realpath(__file__)), "postprocess/textfile-service"))
|
|
|
|
service = Service(config, "http://exmaple.com")
|
|
|
|
service.output["title"] = "textfile"
|
|
|
|
stream = VideoRetriever(config, "http://example.com", 0, output=service.output)
|
2020-10-12 14:18:50 +02:00
|
|
|
self.assertEqual(_sublanguage(stream, config, None), ["swe"])
|
2019-09-15 19:00:38 +02:00
|
|
|
|
2020-10-12 14:18:50 +02:00
|
|
|
def test_sublang2(self, req):
|
2019-09-15 19:00:38 +02:00
|
|
|
config = setup_defaults()
|
2020-10-12 14:18:50 +02:00
|
|
|
self.setup_mock(req, "swe")
|
2019-09-15 19:00:38 +02:00
|
|
|
config.set("output", os.path.join(os.path.dirname(os.path.realpath(__file__)), "postprocess/textfile-service"))
|
|
|
|
config.set("get_all_subtitles", True)
|
|
|
|
service = Service(config, "http://exmaple.com")
|
|
|
|
service.output["title"] = "textfile"
|
|
|
|
stream = VideoRetriever(config, "http://example.com", 0, output=service.output)
|
2020-10-12 14:18:50 +02:00
|
|
|
self.assertEqual(_sublanguage(stream, config, ["grej", "hej"]), ["swe", "swe"])
|
2019-09-15 19:00:38 +02:00
|
|
|
|
2020-10-12 14:18:50 +02:00
|
|
|
def test_sublang3(self, req):
|
2019-09-15 19:00:38 +02:00
|
|
|
config = setup_defaults()
|
2020-10-12 14:18:50 +02:00
|
|
|
self.setup_mock(req, "smj")
|
2019-09-15 19:00:38 +02:00
|
|
|
config.set("output", os.path.join(os.path.dirname(os.path.realpath(__file__)), "postprocess/textfile-service"))
|
|
|
|
config.set("get_all_subtitles", True)
|
|
|
|
service = Service(config, "http://exmaple.com")
|
|
|
|
service.output["title"] = "textfile"
|
|
|
|
stream = VideoRetriever(config, "http://example.com", 0, output=service.output)
|
2020-10-12 14:18:50 +02:00
|
|
|
self.assertEqual(_sublanguage(stream, config, ["lulesamiska"]), ["smj"])
|