1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-12-11 20:34:18 +01:00
svtplay-dl/lib/svtplay_dl/tests/test_formatname.py

390 lines
18 KiB
Python
Raw Normal View History

2020-09-19 15:03:12 +02:00
import platform
import unittest
from svtplay_dl.service import Service
2019-08-25 00:40:39 +02:00
from svtplay_dl.utils.output import _formatname
2020-09-19 14:49:26 +02:00
from svtplay_dl.utils.output import formatname
from svtplay_dl.utils.parser import setup_defaults
class formatnameTest(unittest.TestCase):
all_combo = [
[
2019-08-25 00:27:31 +02:00
"test-{title}-{service}-{ext}-{episode}-{id}-{season}-{episodename}",
{"title": "title", "season": 99, "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
"test-title-service-mp4-21-0xdeadface-99-episodename",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{service}-{ext}-{episode}-{id}-{season}-{episodename}",
{"title": "title", "season": 99, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"test-title-service-mp4-0xdeadface-99-episodename",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{service}-{ext}-{episode}-{id}-{season}-{episodename}",
{"title": "title", "season": 99, "id": "0xdeadface", "ext": "ext"},
"test-title-service-mp4-0xdeadface-99",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{service}-{ext}-{episode}-{id}-{season}-{episodename}",
{"title": "title", "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"test-title-service-mp4-21-0xdeadface-episodename",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{service}-{ext}-{episode}-{id}-{season}-{episodename}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"test-title-service-mp4-0xdeadface-episodename",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{service}-{ext}-{episode}-{id}-{season}-{episodename}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface"},
"test-title-service-mp4-0xdeadface-episodename",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{episode}-{season}-{service}-{episodename}-{id}-{ext}",
{"title": "title", "season": 99, "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"test-title-21-99-service-episodename-0xdeadface-mp4",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{episode}-{season}-{service}-{episodename}-{id}-{ext}",
{"title": "title", "season": 99, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"test-title-99-service-episodename-0xdeadface-mp4",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{episode}-{season}-{service}-{episodename}-{id}-{ext}",
{"title": "title", "season": 99, "id": "0xdeadface", "ext": "ext"},
"test-title-99-service-0xdeadface-mp4",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{episode}-{season}-{service}-{episodename}-{id}-{ext}",
{"title": "title", "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"test-title-21-service-episodename-0xdeadface-mp4",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{episode}-{season}-{service}-{episodename}-{id}-{ext}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"test-title-service-episodename-0xdeadface-mp4",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{episode}-{season}-{service}-{episodename}-{id}-{ext}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface"},
"test-title-service-episodename-0xdeadface-mp4",
],
[
2019-08-25 00:27:31 +02:00
"{id}-{season}-{ext}-{episode}-{episodename}-{title}-{service}",
{"title": "title", "season": 99, "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"0xdeadface-99-mp4-21-episodename-title-service",
],
[
2019-08-25 00:27:31 +02:00
"{id}-{season}-{ext}-{episode}-{episodename}-{title}-{service}",
{"title": "title", "season": 99, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"0xdeadface-99-mp4-episodename-title-service",
],
[
2019-08-25 00:27:31 +02:00
"{id}-{season}-{ext}-{episode}-{episodename}-{title}-{service}",
{"title": "title", "season": 99, "id": "0xdeadface", "ext": "ext"},
"0xdeadface-99-mp4-title-service",
],
[
2019-08-25 00:27:31 +02:00
"{id}-{season}-{ext}-{episode}-{episodename}-{title}-{service}",
{"title": "title", "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"0xdeadface-mp4-21-episodename-title-service",
],
[
2019-08-25 00:27:31 +02:00
"{id}-{season}-{ext}-{episode}-{episodename}-{title}-{service}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"0xdeadface-mp4-episodename-title-service",
],
[
2019-08-25 00:27:31 +02:00
"{id}-{season}-{ext}-{episode}-{episodename}-{title}-{service}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface"},
"0xdeadface-mp4-episodename-title-service",
],
[
2019-08-25 00:27:31 +02:00
"{service}-{ext}-{season}-{id}-{title}-{episodename}-{episode}",
{"title": "title", "season": 99, "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"service-mp4-99-0xdeadface-title-episodename-21",
],
[
2019-08-25 00:27:31 +02:00
"{service}-{ext}-{season}-{id}-{title}-{episodename}-{episode}",
{"title": "title", "season": 99, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"service-mp4-99-0xdeadface-title-episodename",
],
[
2019-08-25 00:27:31 +02:00
"{service}-{ext}-{season}-{id}-{title}-{episodename}-{episode}",
{"title": "title", "season": 99, "id": "0xdeadface", "ext": "ext"},
"service-mp4-99-0xdeadface-title",
],
[
2019-08-25 00:27:31 +02:00
"{service}-{ext}-{season}-{id}-{title}-{episodename}-{episode}",
{"title": "title", "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"service-mp4-0xdeadface-title-episodename-21",
],
[
2019-08-25 00:27:31 +02:00
"{service}-{ext}-{season}-{id}-{title}-{episodename}-{episode}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"service-mp4-0xdeadface-title-episodename",
],
[
2019-08-25 00:27:31 +02:00
"{service}-{ext}-{season}-{id}-{title}-{episodename}-{episode}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface"},
"service-mp4-0xdeadface-title-episodename",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{service}-{ext}-{episode}-{id}-{season}",
{"title": "title", "season": 99, "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"test-title-service-mp4-21-0xdeadface-99",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{service}-{ext}-{episode}-{id}-{season}",
{"title": "title", "season": 99, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"test-title-service-mp4-0xdeadface-99",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{service}-{ext}-{episode}-{id}-{season}",
{"title": "title", "season": 99, "id": "0xdeadface", "ext": "ext"},
"test-title-service-mp4-0xdeadface-99",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{service}-{ext}-{episode}-{id}-{season}",
{"title": "title", "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"test-title-service-mp4-21-0xdeadface",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{service}-{ext}-{episode}-{id}-{season}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"test-title-service-mp4-0xdeadface",
],
[
2019-08-25 00:27:31 +02:00
"test-{title}-{service}-{ext}-{episode}-{id}-{season}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface"},
"test-title-service-mp4-0xdeadface",
],
[
2019-08-25 00:27:31 +02:00
"{title}-{ext}-{episode}-{id}-{season}",
{"title": "title", "season": 99, "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title-mp4-21-0xdeadface-99",
],
[
2019-08-25 00:27:31 +02:00
"{title}-{ext}-{episode}-{id}-{season}",
{"title": "title", "season": 99, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title-mp4-0xdeadface-99",
],
["{title}-{ext}-{episode}-{id}-{season}", {"title": "title", "season": 99, "id": "0xdeadface", "ext": "ext"}, "title-mp4-0xdeadface-99"],
[
2019-08-25 00:27:31 +02:00
"{title}-{ext}-{episode}-{id}-{season}",
{"title": "title", "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title-mp4-21-0xdeadface",
],
[
2019-08-25 00:27:31 +02:00
"{title}-{ext}-{episode}-{id}-{season}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title-mp4-0xdeadface",
],
["{title}-{ext}-{episode}-{id}-{season}", {"title": "title", "episodename": "episodename", "id": "0xdeadface"}, "title-mp4-0xdeadface"],
[
2019-08-25 00:27:31 +02:00
"{title}-{ext}.{episode}-{id}.{season}",
{"title": "title", "season": 99, "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title-mp4.21-0xdeadface.99",
],
[
2019-08-25 00:27:31 +02:00
"{title}-{ext}.{episode}-{id}.{season}",
{"title": "title", "season": 99, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title-mp4-0xdeadface.99",
],
["{title}-{ext}.{episode}-{id}.{season}", {"title": "title", "season": 99, "id": "0xdeadface", "ext": "ext"}, "title-mp4-0xdeadface.99"],
[
2019-08-25 00:27:31 +02:00
"{title}-{ext}.{episode}-{id}.{season}",
{"title": "title", "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title-mp4.21-0xdeadface",
],
[
2019-08-25 00:27:31 +02:00
"{title}-{ext}.{episode}-{id}.{season}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title-mp4-0xdeadface",
],
["{title}-{ext}.{episode}-{id}.{season}", {"title": "title", "episodename": "episodename", "id": "0xdeadface"}, "title-mp4-0xdeadface"],
[
2019-08-25 00:27:31 +02:00
"{id}-{season}{ext}-{episode}{episodename}-{title}-{service}",
{"title": "title", "season": 99, "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"0xdeadface-99mp4-21episodename-title-service",
],
[
2019-08-25 00:27:31 +02:00
"{id}-{season}{ext}-{episode}{episodename}-{title}-{service}",
{"title": "title", "season": 99, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"0xdeadface-99mp4episodename-title-service",
],
[
2019-08-25 00:27:31 +02:00
"{id}-{season}{ext}-{episode}{episodename}-{title}-{service}",
{"title": "title", "season": 99, "id": "0xdeadface", "ext": "ext"},
"0xdeadface-99mp4-title-service",
],
[
2019-08-25 00:27:31 +02:00
"{id}-{season}{ext}-{episode}{episodename}-{title}-{service}",
{"title": "title", "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"0xdeadfacemp4-21episodename-title-service",
],
[
2019-08-25 00:27:31 +02:00
"{id}-{season}{ext}-{episode}{episodename}-{title}-{service}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"0xdeadfacemp4episodename-title-service",
],
[
2019-08-25 00:27:31 +02:00
"{id}-{season}{ext}-{episode}{episodename}-{title}-{service}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface"},
"0xdeadfacemp4episodename-title-service",
],
[
2019-08-25 00:27:31 +02:00
"{episodename}a{title}-{service}",
{"title": "title", "season": 99, "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"episodenameatitle-service",
],
[
2019-08-25 00:27:31 +02:00
"{episodename}a{title}-{service}",
{"title": "title", "season": 99, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"episodenameatitle-service",
],
["{episodename}a{title}-{service}", {"title": "title", "season": 99, "id": "0xdeadface", "ext": "ext"}, "atitle-service"],
[
2019-08-25 00:27:31 +02:00
"{episodename}a{title}-{service}",
{"title": "title", "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"episodenameatitle-service",
],
[
2019-08-25 00:27:31 +02:00
"{episodename}a{title}-{service}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"episodenameatitle-service",
],
["{episodename}a{title}-{service}", {"title": "title", "episodename": "episodename", "id": "0xdeadface"}, "episodenameatitle-service"],
[
2019-08-25 00:27:31 +02:00
"{title}.{episode}.{episodename}-{id}-{service}.{ext}",
{"title": "title", "season": 99, "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title.21.episodename-0xdeadface-service.mp4",
],
[
2019-08-25 00:27:31 +02:00
"{title}.{episode}.{episodename}-{id}-{service}.{ext}",
{"title": "title", "season": 99, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title.episodename-0xdeadface-service.mp4",
],
[
2019-08-25 00:27:31 +02:00
"{title}.{episode}.{episodename}-{id}-{service}.{ext}",
{"title": "title", "season": 99, "id": "0xdeadface", "ext": "ext"},
"title-0xdeadface-service.mp4",
],
[
2019-08-25 00:27:31 +02:00
"{title}.{episode}.{episodename}-{id}-{service}.{ext}",
{"title": "title", "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title.21.episodename-0xdeadface-service.mp4",
],
[
2019-08-25 00:27:31 +02:00
"{title}.{episode}.{episodename}-{id}-{service}.{ext}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title.episodename-0xdeadface-service.mp4",
],
[
2019-08-25 00:27:31 +02:00
"{title}.{episode}.{episodename}-{id}-{service}.{ext}",
{"title": "title", "episodename": "episodename", "id": "0xdeadface"},
"title.episodename-0xdeadface-service.mp4",
],
[
2019-08-25 00:27:31 +02:00
"{title}.s{season}e{episode}.{episodename}-{id}-{service}.{ext}",
{"title": "title", "season": 99, "episode": 21, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title.s99e21.episodename-0xdeadface-service.mp4",
],
[
2019-08-25 00:27:31 +02:00
"{title}.s{season}e{episode}.{episodename}-{id}-{service}.{ext}",
{"title": "title", "season": 99, "episodename": "episodename", "id": "0xdeadface", "ext": "ext"},
2019-08-25 00:27:31 +02:00
"title.s99.episodename-0xdeadface-service.mp4",
],
]
def test_formatname(self):
for item in self.all_combo:
config = setup_defaults()
config.set("filename", item[0])
service = Service(config, "localhost")
service.output.update(item[1])
service.output["ext"] = "mp4"
assert str(_formatname(service.output, config)) == item[2]
2020-09-19 14:49:26 +02:00
class formatnameTest2(unittest.TestCase):
def test_formatnameEmpty(self):
config = setup_defaults()
service = Service(config, "http://localhost")
service.output["ext"] = "mp4"
assert str(formatname(service.output, config).name) == "-service.mp4"
2020-09-19 14:49:26 +02:00
def test_formatnameOutput(self):
config = setup_defaults()
2020-09-19 15:03:12 +02:00
if platform.system() == "Windows":
config.set("output", "c:\\Users")
service = Service(config, "http://localhost")
service.output["ext"] = "mp4"
assert str(formatname(service.output, config)) == "c:\\Users\\-service.mp4"
2020-09-19 15:03:12 +02:00
else:
config.set("output", "/tmp")
service = Service(config, "http://localhost")
service.output["ext"] = "mp4"
assert str(formatname(service.output, config)) == "/tmp/-service.mp4"
2020-09-19 14:49:26 +02:00
def test_formatnameBasedir(self):
config = setup_defaults()
service = Service(config, "http://localhost")
service.output["basedir"] = True
service.output["ext"] = "mp4"
assert str(formatname(service.output, config).name) == "-service.mp4"
2020-09-19 14:49:26 +02:00
def test_formatnameTvshow(self):
config = setup_defaults()
service = Service(config, "http://localhost")
service.output["tvshow"] = True
service.output["title"] = "kalle"
service.output["season"] = 2
service.output["episode"] = 2
service.output["ext"] = "mp4"
assert str(formatname(service.output, config).name) == "kalle.s02e02-service.mp4"
2020-09-19 14:49:26 +02:00
def test_formatnameTvshowSubfolder(self):
config = setup_defaults()
config.set("subfolder", True)
service = Service(config, "http://localhost")
service.output["tvshow"] = True
service.output["title"] = "kalle"
service.output["season"] = 2
service.output["episode"] = 2
service.output["ext"] = "mp4"
2020-09-19 15:03:12 +02:00
if platform.system() == "Windows":
assert str(formatname(service.output, config)) == "kalle\\kalle.s02e02-service.mp4"
2020-09-19 15:03:12 +02:00
else:
assert str(formatname(service.output, config)) == "kalle/kalle.s02e02-service.mp4"
2020-09-19 14:49:26 +02:00
def test_formatnameTvshowSubfolderMovie(self):
config = setup_defaults()
config.set("subfolder", True)
service = Service(config, "http://localhost")
service.output["tvshow"] = False
service.output["title"] = "kalle"
service.output["season"] = 2
service.output["episode"] = 2
service.output["ext"] = "mp4"
2020-09-19 15:03:12 +02:00
if platform.system() == "Windows":
assert str(formatname(service.output, config)) == "movies\\kalle.s02e02-service.mp4"
2020-09-19 15:03:12 +02:00
else:
assert str(formatname(service.output, config)) == "movies/kalle.s02e02-service.mp4"
2020-09-19 14:49:26 +02:00
def test_formatnameTvshowPath(self):
config = setup_defaults()
2020-09-19 15:03:12 +02:00
if platform.system() == "Windows":
config.set("path", "c:\\")
2020-09-19 15:03:12 +02:00
else:
config.set("path", "/tmp")
2020-09-19 14:49:26 +02:00
service = Service(config, "http://localhost")
service.output["title"] = "kalle"
service.output["season"] = 2
service.output["episode"] = 2
service.output["ext"] = "mp4"
2020-09-19 15:03:12 +02:00
if platform.system() == "Windows":
assert str(formatname(service.output, config)) == "c:\\kalle.s02e02-service.mp4"
2020-09-19 15:03:12 +02:00
else:
assert str(formatname(service.output, config)) == "/tmp/kalle.s02e02-service.mp4"