diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/subliminal_patch/data/titlovi_gettoken_response.json | 6 | ||||
-rw-r--r-- | tests/subliminal_patch/data/titlovi_search_response.json | 172 | ||||
-rw-r--r-- | tests/subliminal_patch/data/titlovi_some_subtitle_pack.zip | bin | 0 -> 254959 bytes | |||
-rw-r--r-- | tests/subliminal_patch/test_titlovi.py | 69 |
4 files changed, 247 insertions, 0 deletions
diff --git a/tests/subliminal_patch/data/titlovi_gettoken_response.json b/tests/subliminal_patch/data/titlovi_gettoken_response.json new file mode 100644 index 000000000..ab1627590 --- /dev/null +++ b/tests/subliminal_patch/data/titlovi_gettoken_response.json @@ -0,0 +1,6 @@ +{ + "ExpirationDate": "2024-10-06T19:05:13.5", + "Token": "asdf1234", + "UserId": 111, + "UserName": "user1" +}
\ No newline at end of file diff --git a/tests/subliminal_patch/data/titlovi_search_response.json b/tests/subliminal_patch/data/titlovi_search_response.json new file mode 100644 index 000000000..2bbe054ac --- /dev/null +++ b/tests/subliminal_patch/data/titlovi_search_response.json @@ -0,0 +1,172 @@ +{ + "ResultsFound": 11, + "PagesAvailable": 1, + "CurrentPage": 1, + "SubtitleResults": [ + { + "Id": 346305, + "Title": "Nikita aka La Femme Nikita", + "Year": 1990, + "Type": 1, + "Link": "https://titlovi.com/download/?type=1&mediaid=346305", + "Season": -1, + "Episode": -1, + "Special": -1, + "Lang": "Srpski", + "Date": "2022-04-11T14:03:30.59", + "DownloadCount": 415, + "Rating": 0.0, + "Release": "PROPER.FRENCH.1080p.BluRay.x264.TrueHD.5.1-FGT" + }, + { + "Id": 323824, + "Title": "Nikita Aka La Femme Nikita", + "Year": 1990, + "Type": 1, + "Link": "https://titlovi.com/download/?type=1&mediaid=323824", + "Season": -1, + "Episode": -1, + "Special": -1, + "Lang": "Srpski", + "Date": "2021-02-21T23:53:51.257", + "DownloadCount": 397, + "Rating": 0.0, + "Release": "720p BluRay x264 DTS-PRoDJi" + }, + { + "Id": 120571, + "Title": "Nikita Aka La Femme Nikita", + "Year": 1990, + "Type": 1, + "Link": "https://titlovi.com/download/?type=1&mediaid=120571", + "Season": -1, + "Episode": -1, + "Special": -1, + "Lang": "Srpski", + "Date": "2011-02-28T22:54:45.7", + "DownloadCount": 3543, + "Rating": 0.0, + "Release": "720p.BD rip" + }, + { + "Id": 91576, + "Title": "La Femme Nikita", + "Year": 1997, + "Type": 2, + "Link": "https://titlovi.com/download/?type=1&mediaid=91576", + "Season": 5, + "Episode": 0, + "Special": -1, + "Lang": "Srpski", + "Date": "2009-12-21T23:13:20.407", + "DownloadCount": 3227, + "Rating": 0.0, + "Release": "" + }, + { + "Id": 81025, + "Title": "La Femme Nikita", + "Year": 1997, + "Type": 2, + "Link": "https://titlovi.com/download/?type=1&mediaid=81025", + "Season": 4, + "Episode": 0, + "Special": -1, + "Lang": "Srpski", + "Date": "2009-06-05T03:09:19.77", + "DownloadCount": 3799, + "Rating": 0.0, + "Release": "" + }, + { + "Id": 81024, + "Title": "La Femme Nikita", + "Year": 1997, + "Type": 2, + "Link": "https://titlovi.com/download/?type=1&mediaid=81024", + "Season": 3, + "Episode": 0, + "Special": -1, + "Lang": "Srpski", + "Date": "2009-06-05T03:07:39.683", + "DownloadCount": 3842, + "Rating": 0.0, + "Release": "" + }, + { + "Id": 81023, + "Title": "La Femme Nikita", + "Year": 1997, + "Type": 2, + "Link": "https://titlovi.com/download/?type=1&mediaid=81023", + "Season": 2, + "Episode": 0, + "Special": -1, + "Lang": "Srpski", + "Date": "2009-06-05T03:06:06.21", + "DownloadCount": 4310, + "Rating": 0.0, + "Release": "" + }, + { + "Id": 81022, + "Title": "La Femme Nikita", + "Year": 1997, + "Type": 2, + "Link": "https://titlovi.com/download/?type=1&mediaid=81022", + "Season": 1, + "Episode": 0, + "Special": -1, + "Lang": "Srpski", + "Date": "2009-06-05T03:04:40.14", + "DownloadCount": 3924, + "Rating": 0.0, + "Release": "" + }, + { + "Id": 69118, + "Title": "Nikita Aka La Femme Nikita", + "Year": 1990, + "Type": 1, + "Link": "https://titlovi.com/download/?type=1&mediaid=69118", + "Season": -1, + "Episode": -1, + "Special": -1, + "Lang": "Srpski", + "Date": "2008-12-07T18:48:22.087", + "DownloadCount": 4950, + "Rating": 5.0, + "Release": "720p.BluRay.x264-SiNNERS" + }, + { + "Id": 14697, + "Title": "Nikita Aka La Femme Nikita", + "Year": 1990, + "Type": 1, + "Link": "https://titlovi.com/download/?type=1&mediaid=14697", + "Season": -1, + "Episode": -1, + "Special": -1, + "Lang": "Srpski", + "Date": "2006-03-14T11:29:44.45", + "DownloadCount": 2188, + "Rating": 5.0, + "Release": "" + }, + { + "Id": 10582, + "Title": "Nikita Aka La Femme Nikita", + "Year": 1990, + "Type": 1, + "Link": "https://titlovi.com/download/?type=1&mediaid=10582", + "Season": -1, + "Episode": -1, + "Special": -1, + "Lang": "Srpski", + "Date": "2005-09-24T19:40:34.233", + "DownloadCount": 1214, + "Rating": 0.0, + "Release": "" + } + ] +}
\ No newline at end of file diff --git a/tests/subliminal_patch/data/titlovi_some_subtitle_pack.zip b/tests/subliminal_patch/data/titlovi_some_subtitle_pack.zip Binary files differnew file mode 100644 index 000000000..9c66352b1 --- /dev/null +++ b/tests/subliminal_patch/data/titlovi_some_subtitle_pack.zip diff --git a/tests/subliminal_patch/test_titlovi.py b/tests/subliminal_patch/test_titlovi.py new file mode 100644 index 000000000..886c43be0 --- /dev/null +++ b/tests/subliminal_patch/test_titlovi.py @@ -0,0 +1,69 @@ +import pytest +import subliminal +import datetime +import tempfile +import os + +from subliminal_patch.providers.titlovi import TitloviProvider +from subliminal_patch.providers.titlovi import TitloviSubtitle +from dogpile.cache.region import register_backend as register_cache_backend +from subliminal_patch.core import Episode +from subzero.language import Language +from subliminal.subtitle import fix_line_ending + +from zipfile import ZipFile + [email protected](scope="session") +def titlovi_episodes(): + return { + "la_femme_nikita_s01e13": Episode( + "La Femme Nikita (1997) - S01E13 - Recruit [HDTV-720p][Opus 2.0][x265].mkv", + "La Femme Nikita", + 1, + 13, + series_imdb_id="tt21209876", + video_codec="x265", + ), + } + [email protected](scope="session") +def region(): + register_cache_backend("subzero.cache.file", "subzero.cache_backends.file", "SZFileBackend") + subliminal.region.configure( + "subzero.cache.file", + expiration_time=datetime.timedelta(days=30), + arguments={"appname": "sz_cache", "app_cache_dir": tempfile.gettempdir()}, + replace_existing_backend=True, + ) + subliminal.region.backend.sync() + +def test_list_subtitles_and_download_from_pack(region, titlovi_episodes, requests_mock, data): + language = Language.fromietf('sr-Latn') + item = titlovi_episodes["la_femme_nikita_s01e13"] + + with open(os.path.join(data, 'titlovi_gettoken_response.json'), "rb") as f: + response = f.read() + requests_mock.post('https://kodi.titlovi.com/api/subtitles/gettoken?username=user1&password=pass1&json=True', content=response) + + with open(os.path.join(data, 'titlovi_search_response.json'), "rb") as f: + response = f.read() + requests_mock.get('https://kodi.titlovi.com/api/subtitles/search?token=asdf1234&userid=111&&query=la femme nikita&lang=Srpski&json=True', content=response) + + with open(os.path.join(data, 'titlovi_some_subtitle_pack.zip'), "rb") as f: + response = f.read() + requests_mock.get('https://titlovi.com/download/?type=1&mediaid=81022', content=response) + + with TitloviProvider('user1','pass1') as provider: + subtitles = provider.list_subtitles(item, languages={language}) + + assert len(subtitles) == 1 + + subtitle = subtitles[0] + provider.download_subtitle(subtitle) + with open(os.path.join(data, 'titlovi_some_subtitle_pack.zip'), "rb") as f: + archive = ZipFile(f) + # subs_in_archive = archive.namelist() + subtitle_content = fix_line_ending(archive.read('La Femme Nikita - 01x13 - Recruit.srt')) + assert(subtitle.content == subtitle_content) + + |