Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add bnj to be able to resolve url without bvid in parse_link by __INITIAL_STATE__ #640

Merged
merged 7 commits into from
Jan 14, 2024

Conversation

TimG233
Copy link
Contributor

@TimG233 TimG233 commented Jan 12, 2024

parse_link添加了处理拜年纪url中没有bvid的情况,通过Nemo说的__INITIAL_STATE__来获取bvid

  • 目前返回所有返回值里第一个视频(也就是正片第一个)

如果认为返回整个dict或者返回一个全部bvid的列表,我也可以改一下。(词典会稍稍麻烦些因为没法塞到Video类里,然后列表的话就看不到分类(比如说正片,单品,等等))

TimG233 and others added 2 commits January 12, 2024 00:39
当获取历史弹幕时,需要初始化from_seg,to_seg。否则 语句 for seg in range(from_seg, to_seg+1)会产生TypeError。
@Nemo2011
Copy link
Owner

其实 www.bilibili.com/festival/*** 不仅仅是拜年祭用的链接。

https://www.bilibili.com/festival/talktalk

https://www.bilibili.com/festival/genshin2023

fix TypeError: 'NoneType' + 'int' in history danmuku
@TimG233
Copy link
Contributor Author

TimG233 commented Jan 12, 2024

yew还有这种?!但这些可以通过re匹配一下单独处理倒是,所以是这三个每个都塞到parse_link还是说都先不管了。

@Nemo2011
Copy link
Owner

Nemo2011 commented Jan 12, 2024

把正则改一下,别管 festival/ 后面的内容,只看前面匹配不匹配。如果链接不存在函数是可以识别出来的。

其实可以直接把正则优化掉,用 yarl 处理,传入的 url 参数实际上是 yarl.URL 对象。

@Nemo2011
Copy link
Owner

还有,如果要用到 get_initial_state 的话,建议用异步函数,把整个 parse_bnj 都改成异步,再把调用这个函数的 parse_link 函数的调用加上 await ,因为 parse_link 是异步函数。

@TimG233
Copy link
Contributor Author

TimG233 commented Jan 13, 2024

哦对这个确实,用了get_initial_state了那还是把parse_bnj改成异步合理否则blocking了,那我把所有这三种(或者说这类)都塞到parse_bnj吗还是弄个新的

@z0z0r4
Copy link
Collaborator

z0z0r4 commented Jan 13, 2024

哦对这个确实,用了get_initial_state了那还是把parse_bnj改成异步合理否则blocking了,那我把所有这三种(或者说这类)都塞到parse_bnj吗还是弄个新的

能解析出对应 Video 对象就行了,没人在乎分类,改成 parse_festival 就行

@Nemo2011
Copy link
Owner

Nemo2011 commented Jan 13, 2024

总结一下:对于有 festival 的链接(不要管这个 festival/ 后面是什么内容,这个没有影响)且未提供 bvid 的,直接用 get_initial_state 抓取正片 bvid

@TimG233
Copy link
Contributor Author

TimG233 commented Jan 13, 2024

这次加了parse_festival获取所有festival链接里的第一个正片视频,用yarl替换了re,返回的是Video对象,如果不存在则返回-1

@Nemo2011
Copy link
Owner

Nemo2011 commented Jan 13, 2024

看完后我觉得有两个问题:为什么留下 parse_bnj ?为什么不将 parse_bnj 中的识别 bvid 字段的代码合并到 parse_festival

@Nemo2011 Nemo2011 self-requested a review January 13, 2024 10:16
@TimG233
Copy link
Contributor Author

TimG233 commented Jan 14, 2024

ok了,这回全都放到了parse_festival里,上面这些url都可以处理。感谢提醒

@Nemo2011 Nemo2011 merged commit 94ccb8a into Nemo2011:dev Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants