Skip to content

Commit

Permalink
修复标题过长引发的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
HFrost0 committed May 7, 2022
1 parent a47e371 commit 416d030
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ bilix get_series 'url'
`get_series`很强大,会自动识别系列所有视频并下载,如果该系列只有一个视频(比如单p投稿)也是可以正常下载的。

💡什么是一个系列:比如一个多p投稿的所有p,一部动漫的所有集。

另外`get_series`支持集数选择参数`-p`,例如通过`-p 1 3`即可指定下载P1至P3的视频
### 单个下载
用户😨:我不想下载那么多,只想下载单个视频。没问题,试试这个,只需要提供那个视频的网页链接:
```shell
Expand Down Expand Up @@ -148,3 +150,4 @@ asyncio.run(main())
* 出现未被正常捕捉的异常后断点重连可能导致视频画面或者音频部分缺失(例如突然拉闸😅)
* 不支持部分的没有音画分开下载方式的老视频
* 当两个视频名字完全一样时,任务冲突但不会报错,可能导致视频缺胳膊少腿
* 未知情况下出现无限下载[issue](https://github.com/HFrost0/bilix/issues/11)
6 changes: 2 additions & 4 deletions bilix/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def handle_help(ctx: click.Context, param: typing.Union[click.Option, click.Para

def print_help():
console = rich.console.Console()

console.print("\n[bold]Bilix️", justify="center")
console.print("\n[bold]Bilix", justify="center")
console.print("⚡️快如闪电的bilibili下载工具,基于Python现代Async特性,高速批量下载整部动漫,电视剧,up投稿等\n", justify="center")
console.print("使用方法: bilix [cyan]<method> <key> [OPTIONS][/cyan] ", justify="left")
table = Table.grid(padding=1, pad_edge=False)
Expand Down Expand Up @@ -133,9 +132,8 @@ async def download(
subtitle: bool,
dm: bool,
only_audio: bool,
p_range: tuple[int]
p_range
):
print(p_range)
d = Downloader(videos_dir=videos_dir, video_concurrency=video_concurrency, sess_data=cookie)
if method == 'get_series' or method == 's':
await d.get_series(key, quality=quality,
Expand Down
31 changes: 23 additions & 8 deletions bilix/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@ def legal_title(title, add_name=''):
:param add_name: 分P名
:return:
"""
title = title.strip()
add_name = add_name.strip()
if add_name:
title = f'{title}-{add_name}'
title = html.unescape(title) # handel & "...
title = re.sub(r"[/\\:*?\"<>|]", '', title) # replace illegal file character
# todo 标题过长时引发系统错误
return title

title, add_name = _replace(title), _replace(add_name)
title = _truncation(title) # avoid OSError caused by title too long
return f'{title}-{add_name}' if add_name else title


def _replace(s: str):
s = s.strip()
s = html.unescape(s) # handel & "...
s = re.sub(r"[/\\:*?\"<>|]", '', s) # replace illegal filename character
return s


def _truncation(s: str, target=150):
while len(s.encode('utf8')) > target - 3:
s = s[:-1]
return s


if __name__ == '__main__':
a = legal_title("【Udemy付费课程】Node JS 高级概念-进阶课程 学习使用 Redis 进行缓存,通过集群加速,使用 S3 和 Node 添加图片上传!(中英文字幕)",
"P80-082 Solving Authentication Issues with")
print(a)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_license():
setup(
name='bilix',
python_requires=">=3.8",
version='0.4.3',
version='0.4.3.1',
author='HFrost0',
author_email='[email protected]',
description='⚡️快如闪电的b站视频下载工具,基于Python现代Async异步特性,高速批量下载整部动漫,电视剧,电影,up投稿等',
Expand Down

0 comments on commit 416d030

Please sign in to comment.