Skip to content

Commit

Permalink
修复 9f99515 导致的无法扫描影片文件的问题并添加测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuukiy committed Dec 18, 2023
1 parent 9f99515 commit 7e5042b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
5 changes: 3 additions & 2 deletions core/avid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''


Expand Down
40 changes: 40 additions & 0 deletions unittest/data/gyutto-266923 (gyutto).json
Original file line number Diff line number Diff line change
@@ -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
}
31 changes: 26 additions & 5 deletions unittest/test_file.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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'

Expand Down
1 change: 1 addition & 0 deletions web/gyutto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 7e5042b

Please sign in to comment.