Skip to content

Commit

Permalink
支持识别文件名中番号后未加-分隔的UC属性
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuukiy committed Jan 1, 2024
1 parent ee5588a commit 4b72ce8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def attr_str(self) -> str:
# 暂不支持多分片的影片
if len(self.files) != 1:
return ''
r = detect_special_attr(self.files[0])
r = detect_special_attr(self.files[0], self.dvdid)
if r:
r = '-' + r
return r
Expand Down
14 changes: 9 additions & 5 deletions core/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ def strftime_to_minutes(s: str) -> int:
elif len(items) == 3:
minutes = items[0] * 60 + items[1] + round(items[2]/60)
else:
logger.error(f"无法将字符串'{s}'转换为分钟")
return
raise ValueError(f"无法将字符串'{s}'转换为分钟")
return minutes


_PATTERN = re.compile(r'(uncen(sor(ed)?)?([- _\s]*leak(ed)?)?|[无無][码碼](流出|破解))', flags=re.I)
def detect_special_attr(filepath: str) -> str:
def detect_special_attr(filepath: str, avid: str = None) -> str:
"""通过文件名检测影片是否有特殊属性(内嵌字幕、无码流出/破解)
Returns:
Expand All @@ -59,10 +58,15 @@ def detect_special_attr(filepath: str) -> str:
postfix = base.split('-')[-1]
if postfix in ('U', 'C', 'UC'):
result += postfix
elif avid:
pattern_str = re.sub(r'[_-]', '[_-]*', avid) + '(UC|U|C)'
match = re.search(pattern_str, base, flags=re.I)
if match:
result += match.group(1)
# 最终格式化
result = ''.join(sorted(result, reverse=True))
result = ''.join(sorted(set(result), reverse=True))
return result


if __name__ == "__main__":
print(detect_special_attr('STARS-225_UNCENSORED_LEAKED.mp4'))
print(detect_special_attr('STARS225Uc.mp4', 'STARS-225'))
8 changes: 8 additions & 0 deletions unittest/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ def test_detect_special_attr():
assert run('STARS-225_无码.mp4') == ''
assert run('STARS-225_无码流出.mp4') == 'U'
assert run('STARS-225_无码破解.mp4') == 'U'
assert run('STARS-225_UNCEN.mp4') == 'U'
assert run('STARS-225_UNCEN-C.mp4') == 'UC'
assert run('STARS-225u.mp4', 'STARS-225') == 'U'
assert run('STARS-225C.mp4', 'STARS-225') == 'C'
assert run('STARS-225uC.mp4', 'STARS-225') == 'UC'
assert run('STARS225u.mp4', 'STARS-225') == 'U'
assert run('STARS225C.mp4', 'STARS-225') == 'C'
assert run('STARS225uC.mp4', 'STARS-225') == 'UC'

0 comments on commit 4b72ce8

Please sign in to comment.