diff --git a/core/avid.py b/core/avid.py index e39e935d0..6dce67772 100644 --- a/core/avid.py +++ b/core/avid.py @@ -79,8 +79,9 @@ def get_id(filepath: str) -> str: # 如果最后仍然匹配不了番号,则尝试使用文件所在文件夹的名字去匹配 if os.path.isfile(filepath): norm = os.path.normpath(filepath) - folder = norm.split(os.sep)[-2] - return get_id(folder) + if os.sep in norm: + folder = norm.split(os.sep)[-2] + return get_id(folder) return '' diff --git a/unittest/data/gyutto-266923 (gyutto).json b/unittest/data/gyutto-266923 (gyutto).json new file mode 100644 index 000000000..a38d52dbf --- /dev/null +++ b/unittest/data/gyutto-266923 (gyutto).json @@ -0,0 +1,40 @@ +{ + "dvdid": "GYUTTO-266923", + "cid": null, + "url": "http://gyutto.com/i/item266923?select_uaflag=1", + "plot": "シコリティ高すぎイキ狂い巨乳肉便器ちゃん。本能から妊娠望んでる女はこうなるらC。無責任中出し合法系ビッチなので着床狙いで子宮ドプドプにしておきました。おかずローテ入り不可避極上オナネタ", + "cover": "http://gyutto.com/data/item_img/2669/266923/266923.jpg", + "big_cover": null, + "genre": [ + "巨乳", + "フェラ", + "中出し", + "おっぱい", + "孕ませ", + "ニーソックス・ニーソ", + "美少女", + "コスプレ動画+写真" + ], + "genre_id": null, + "genre_norm": null, + "score": null, + "title": "【一発かんたんDL版】受精中毒レム!子宮堕ちビッチ発狂痙攣イキでおっぱい揺れ揺れ!妊娠したがり美巨乳ちゃんの孕み様を見よ!完全肉便器極エロボディ子種仕込み中出し絶頂孕まSEX!! ", + "ori_title": null, + "magnet": null, + "serial": null, + "actress": null, + "actress_pics": null, + "director": null, + "duration": null, + "producer": "こすっち", + "publisher": null, + "uncensored": null, + "publish_date": "2023-12-08", + "preview_pics": [ + "http://gyutto.com/data/item_img/2669/266923/266923.jpg", + "http://gyutto.com/data/item_img/2669/266923/266923_430.jpg", + "http://gyutto.com/data/item_img/2669/266923/266923_431.jpg", + "http://gyutto.com/data/item_img/2669/266923/266923_432.jpg" + ], + "preview_video": null +} \ No newline at end of file diff --git a/unittest/test_file.py b/unittest/test_file.py index 34e5d090d..04e1231aa 100644 --- a/unittest/test_file.py +++ b/unittest/test_file.py @@ -1,15 +1,16 @@ import os import sys -import uuid +import random +import string import pytest from shutil import rmtree sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -from core.file import * +from core.file import failed_items, scan_movies -tmp_folder = 'tmp_' + uuid.uuid4().hex[:8] +tmp_folder = 'TMP_' + ''.join(random.choices(string.ascii_uppercase, k=6)) @pytest.fixture @@ -121,6 +122,25 @@ def test_scan_movies__0x123(prepare_files): assert basenames[2] == 'ABC-123.03.mp4' +# 无效: 没有可以匹配到番号的文件 +@pytest.mark.parametrize('files', [('什么也没有.mp4',)]) +def test_scan_movies__nothing(prepare_files): + movies = scan_movies(tmp_folder) + assert len(movies) == 0 + + +# 无效: 在CWD下没有可以匹配到番号的文件 +@pytest.mark.parametrize('files', [('什么也没有.mp4',)]) +def test_scan_movies__nothing_in_cwd(prepare_files): + cwd = os.getcwd() + os.chdir(tmp_folder) + try: + movies = scan_movies('.') + finally: + os.chdir(cwd) + assert len(movies) == 0 + + # 无效:多个分片命名杂乱 @pytest.mark.parametrize('files', [('ABC-123-1.mp4','ABC-123-第2部分.mp4','ABC-123-3.mp4')]) def test_scan_movies__strange_names(prepare_files): @@ -186,12 +206,13 @@ def test_scan_movies__1_video_with_ad(prepare_files): # 文件夹以番号命名,文件夹内同时有带番号的影片和超出阈值的广告 @pytest.mark.parametrize('files', [{'ABC-123/ABC-123.mp4': 1, 'ABC-123/广告1.mp4': 1024, 'ABC-123/广告2.mp4': 1048576, 'ABC-123/Advertisement.mp4': 2**30}]) def test_scan_movies__1_video_with_large_ad(prepare_files): + before = failed_items.copy() movies = scan_movies(tmp_folder) + after = failed_items.copy() + failed = [i for i in after if i not in before] assert len(movies) == 1 assert movies[0].dvdid == 'ABC-123' assert len(movies[0].files) == 1 - import core.file - failed = core.file.failed_items assert len(failed) == 1 and len(failed[0].files) == 1 assert os.path.basename(failed[0].files[0]) == 'Advertisement.mp4' diff --git a/web/gyutto.py b/web/gyutto.py index 537497ad0..9f2d10266 100644 --- a/web/gyutto.py +++ b/web/gyutto.py @@ -85,5 +85,6 @@ def parse_data(movie: MovieInfo): try: parse_data(movie) + print(movie) except CrawlerError as e: logger.error(e, exc_info=1)