From 7e5042b5fb215f0e034ab537d67dde61f0ee9db3 Mon Sep 17 00:00:00 2001 From: Yuukiy <76897913+Yuukiy@users.noreply.github.com> Date: Mon, 18 Dec 2023 21:19:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=209f99515c=20=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E6=97=A0=E6=B3=95=E6=89=AB=E6=8F=8F=E5=BD=B1?= =?UTF-8?q?=E7=89=87=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/avid.py | 5 +-- unittest/data/gyutto-266923 (gyutto).json | 40 +++++++++++++++++++++++ unittest/test_file.py | 31 +++++++++++++++--- web/gyutto.py | 1 + 4 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 unittest/data/gyutto-266923 (gyutto).json 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)