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

Add get_short_url to generate the b23.tv url from the bilibili.com url #720

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

TimG233
Copy link
Contributor

@TimG233 TimG233 commented Mar 20, 2024

添加了get_short_url来生成b23的短链接

  • 支持选择性传入凭据类,会获取其中的buvid,若没传入或buvidNone,则随机生成buvid(同一个文件的acquire_buvid方法里)。

移除了get_real_urlcredential参数

  • 因为确实之前的版本中,credential就没用过。其次,redirect这个也不需要传入任何凭据类。

更新了docs

  • docs上面说的应该都更新了

来源:#702

代码水平有限,大佬们多指点!感谢!

Copy link
Collaborator

@z0z0r4 z0z0r4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个接口的鉴权是 APP 鉴权吧? sessdata 的能用?

Comment on lines 36 to 40
# random generation
buvid3_pattern = '8-4-4-4-17' # current buvid3 char-length pattern, might be changed later
parts = buvid3_pattern.split('-')

buvid3_rand_gen = ["".join(random.choices(string.digits + string.ascii_letters, k=int(part))) for part in parts]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议随机,有spi接口可以用

'platform': random.choice(['android', 'ios']),
'share_channel': 'COPY',
'share_id': 'public.webview.0.0.pv',
'share_mode': str(random.randint(1, 10))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不了解的参数可以照旧,build 也是

@TimG233
Copy link
Contributor Author

TimG233 commented Mar 21, 2024

  • sessdata的不能用吧,他必须需要buvid的key-pair,但离谱的是,buvid你随便写其实是可以的,只要存在且不为空(至少目前)是可以用的,我怀疑他根本没查其实。
  • 添加了get_spi_buvid,现在只有无credential + get_spi_buvid都不行才会随机生成,毕竟buvid一定不能为空。但其实get_spi_buvid测试时是一直好用的。
  • build直接改成999999999了,其实只要大于5.5M就可以用,无上限。share_mode改为固定值3,对应的是链接分享。

@z0z0r4
Copy link
Collaborator

z0z0r4 commented Mar 21, 2024

  • sessdata的不能用吧,他必须需要buvid的key-pair,但离谱的是,buvid你随便写其实是可以的,只要存在且不为空(至少目前)是可以用的,我怀疑他根本没查其实。

    • 添加了get_spi_buvid,现在只有无credential + get_spi_buvid都不行才会随机生成,毕竟buvid一定不能为空。但其实get_spi_buvid测试时是一直好用的。

    • build直接改成999999999了,其实只要大于5.5M就可以用,无上限。share_mode改为固定值3,对应的是链接分享。

随机 buvid 没有意义...没有 buvid 就应该去 spi 获取...没查是一回事

这个接口你测试过不需要登录吗?你说 sessdata 不能用,我记得我也没写 app 鉴权,那你咋请求的?有测试数据提供一份吗?

麻烦固定 build,不同 build 的参数可能不同

@TimG233
Copy link
Contributor Author

TimG233 commented Mar 21, 2024

  • Ok那我把随机那部分去掉了,那如果spi没返回我直接就扔ApiException
  • 这个接口我之前在写的时候跑过一些测试(>100),不需要登录目前看来无风控(当然每个测试中间会随机time.sleep几秒吧)
  • build这样我固定成你在BAC里那份吧,7300400,平台固定成android。

他需要什么他会写出来,你可以试一下requests.post不传入任何data,他会返回一个json如下

{'code': -400, 'message': "Key: 'ClickReq.ShareId' Error:Field validation for 'ShareId' failed on the 'required' tag\nKey: 'ClickReq.Oid' Error:Field validation for 'Oid' failed on the 'required' tag\nKey: 'ClickReq.ShareMode' Error:Field validation for 'ShareMode' failed on the 'required' tag\nKey: 'ClickReq.ShareChannel' Error:Field validation for 'ShareChannel' failed on the 'required' tag\nKey: 'ClickReq.Buvid' Error:Field validation for 'Buvid' failed on the 'required' tag\nKey: 'ClickReq.Platform' Error:Field validation for 'Platform' failed on the 'required' tag", 'ttl': 1}

其中message里显示所有需要的key,如下

  • share_id
  • oid
  • share_mode
  • share_channel
  • buvid
  • platform
    其中oid既可以是比如说一个视频的id,也可以是整个长链接,有了oid就不需要share_content了。
  • build虽然这里没写,但是不加build版本会不返回任何短链接,如下
{'code': 0, 'message': '0', 'ttl': 1, 'data': {'count': 0}}

所以,他现在不查buvid的情况下,就变成了真·啥也不查(当然buvid还是正常填入)

P.S. 正常返回的情况,json会像这样

{'code': 0, 'message': '0', 'ttl': 1, 'data': {'content': 'https://b23.tv/UfikcVQ', 'count': 0}}

@z0z0r4
Copy link
Collaborator

z0z0r4 commented Mar 21, 2024

主要是不需要登录吗?就算不需要,可以考虑下等我这周末把APP鉴权加进去之后再合并,这个短链接能识别分享者的

@z0z0r4
Copy link
Collaborator

z0z0r4 commented Mar 23, 2024

还真不用登录啊...那我想摆烂了,继续鸽着登录吧,没啥意义+-=

@z0z0r4 z0z0r4 linked an issue Mar 23, 2024 that may be closed by this pull request
@z0z0r4
Copy link
Collaborator

z0z0r4 commented Mar 23, 2024

基本上,如果 share_idpublic.webview.0.0.pv 的话没法直接分享 oid,只能分享链接,你可以试试看

视频只能 main.ugc-video-detail.0.0.pv 搭配 aid

我觉得需要捕捉点 share_id 来,比如专栏、音频、动态的

share_content 与实际的 redirect 无关其实无关

@z0z0r4
Copy link
Collaborator

z0z0r4 commented Mar 23, 2024

动态

access_key=&appkey=1d8b6e7d45233436&build=7710300&buvid=&c_locale=zh_CN&channel=bili&disable_rcmd=0&mobi_app=android&oid=912088171364220936&panel_type=1&platform=android&s_locale=zh_CN&share_channel=COPY&share_content=https%3A%2F%2Ft.bilibili.com%2F912088171364220936%3Fshare_source%3Dcopy_link%26share_medium%3Dandroid&share_id=dt.dt-detail.0.0.pv&share_mode=3&share_origin=dynamic&share_pattern=0&share_session_id=8309efe8-3600-4632-a880-4d1dda6ba876&share_title=%40%E5%90%8C%E6%B5%8E%E5%AD%90%E8%B1%AA%E5%85%84%20%E5%8F%91%E5%B8%83%E4%BA%86%E4%B8%80%E6%9D%A1%E5%8A%A8%E6%80%81%EF%BC%8C%E5%BF%AB%E6%9D%A5%E7%9C%8B%E7%9C%8B%E5%90%A7&spm_id=dt.opus-detail.0.0&statistics=%7B%22appId%22%3A1%2C%22platform%22%3A3%2C%22version%22%3A%227.71.0%22%2C%22abtest%22%3A%22%22%7D&ts=1711207146&sign=daa4138787a515911c5b3243983396f6

@z0z0r4
Copy link
Collaborator

z0z0r4 commented Mar 23, 2024

专栏

access_key=6&build=7710300&buvid=&c_locale=zh_CN&channel=bili&disable_rcmd=0&mobi_app=android&oid=22194789&panel_type=1&platform=android&s_locale=zh_CN&share_channel=COPY&share_content=https%3A%2F%2Fwww.bilibili.com%2Fread%2Fcv22194789&share_id=read.column-detail.roof.8.click&share_mode=3&share_pattern=0&share_session_id=f38d8e8e-acf8-49c3-924f-f8ad99a1e9ee&share_title=%E6%9F%90%E9%AD%94%E6%B3%95%E7%9A%84%E7%A6%81%E4%B9%A6%E7%9B%AE%E5%BD%95%20%E5%88%9B%E7%BA%A67%20%E5%BA%8F%E7%AB%A0&statistics=%7B%22appId%22%3A1%2C%22platform%22%3A3%2C%22version%22%3A%227.71.0%22%2C%22abtest%22%3A%22%22%7D&ts=1711207284&sign=4b70d9ec08a0e03ff97898df5fa36ec7

@z0z0r4
Copy link
Collaborator

z0z0r4 commented Mar 23, 2024

文集

&c_locale=zh_CN&channel=bili&disable_rcmd=0&mobi_app=android&oid=609448&panel_type=1&platform=android&s_locale=zh_CN&share_channel=COPY&share_content=https%3A%2F%2Fwww.bilibili.com%2Fread%2Freadlist%2Frl609448&share_id=read.column-readlist.share.0.click&share_mode=3&share_pattern=0&share_session_id=d9878314-9749-471c-b0b6-e22272691983&share_title=%E5%88%9B%E7%BA%A6%E6%9F%90%E9%AD%94%E6%B3%95%E7%9A%84%E7%A6%81%E4%B9%A6%E7%9B%AE%E5%BD%95%E7%AC%AC6%E5%8D%B7&statistics=%7B%22appId%22%3A1%2C%22platform%22%3A3%2C%22version%22%3A%227.71.0%22%2C%22abtest%22%3A%22%22%7D&ts=1711207337&sign=01b55ffa2fdf7e056bc9de2d23e7813c

@z0z0r4
Copy link
Collaborator

z0z0r4 commented Mar 23, 2024

直播

c_locale=zh_CN&channel=bili&disable_rcmd=0&mobi_app=android&object_extra_fields=%7B%22jumpfrom_id%22%3A30104%7D&oid=21861&panel_type=1&platform=android&s_locale=zh_CN&share_channel=COPY&share_content=%E3%80%90%E8%BF%99%E6%98%AF%EF%BC%81%EF%BC%9FBakaXL%204.0%E5%90%97%EF%BC%81%EF%BC%9F-bilibili%E7%9B%B4%E6%92%AD%E3%80%91https%3A%2F%2Flive.bilibili.com%2F21861%3Fbroadcast_type%3D0%26is_room_feed%3D1&share_id=live.live-room-detail.0.0.pv&share_mode=4&share_origin=vertical-three-point-panel&share_pattern=0&share_session_id=dd34c1f5-7982-468f-8a5a-e550038c4d45&share_title=%E3%80%90%E8%BF%99%E6%98%AF%EF%BC%81%EF%BC%9FBakaXL%204.0%E5%90%97%EF%BC%81%EF%BC%9F-%E5%93%94%E5%93%A9%E5%93%94%E5%93%A9%E7%9B%B4%E6%92%AD%E3%80%91&statistics=%7B%22appId%22%3A1%2C%22platform%22%3A3%2C%22version%22%3A%227.71.0%22%2C%22abtest%22%3A%22%22%7D&ts=1711207520&sign=fe5451556d5c230fcdddd409fba0ebe4

@z0z0r4
Copy link
Collaborator

z0z0r4 commented Mar 23, 2024

用户

&c_locale=zh_CN&channel=bili&disable_rcmd=0&mobi_app=android&object_extra_fields=%7B%22state%22%3A%222%22%7D&oid=3493082817366845&panel_type=1&platform=android&s_locale=zh_CN&share_channel=COPY&share_content=https%3A%2F%2Fspace.bilibili.com%2F3493082817366845%3Fshare_medium%3Dandroid%26share_source%3Dcopy_link%26bbid%3DXY929D1989D1F7CA82D538F11FC970072AA8C%26ts%3D1711207569665&share_id=main.space-total.more.0.click&share_mode=3&share_pattern=0&share_session_id=3e0fb62b-7b5f-4837-8db0-625bc2a3ef19&share_title=JLRS-jayfm%E7%9A%84%E7%A9%BA%E9%97%B4&statistics=%7B%22appId%22%3A1%2C%22platform%22%3A3%2C%22version%22%3A%227.71.0%22%2C%22abtest%22%3A%22%22%7D&ts=1711207569&sign=0b17fe34b242718aaeb07dc594f75748

@z0z0r4
Copy link
Collaborator

z0z0r4 commented Mar 23, 2024

课程
c_locale=zh_CN&channel=bili&disable_rcmd=0&from=6&from_spmid=dt.dt-video-quick-cosume.origin-share.0&mobi_app=android&object_extra_fields=%7B%22epid%22%3A%22409808%22%2C%22cid%22%3A%221398781253%22%7D&oid=11040&panel_type=1&platform=android&s_locale=zh_CN&share_channel=COPY&share_content=%3Fbsource%3Dlink_copy&share_id=pugv.pugv-video-detail.0.0.pv&share_mode=4&share_origin=vinfo_player&share_pattern=0&share_session_id=d3fda612-4f39-4c92-8a5e-028fed48f49e&share_title=%E7%9C%9F%E6%AD%A3%E7%9C%8B%E6%87%82%E4%B8%AD%E5%9B%BD%E7%BB%8F%E6%B5%8E&sid=923378751&spm_id=united.player-video-detail.0.0&statistics=%7B%22appId%22%3A1%2C%22platform%22%3A3%2C%22version%22%3A%227.71.0%22%2C%22abtest%22%3A%22%22%7D&tag=&ts=1711207832&sign=430342795974a52ad0015c5eef085ff1

@z0z0r4
Copy link
Collaborator

z0z0r4 commented Mar 23, 2024

番剧

c_locale=zh_CN&channel=bili&disable_rcmd=0&from=0&from_spmid=main.space-bangumi.0.0&mobi_app=android&object_extra_fields=%7B%22season_type%22%3A%221%22%2C%22season_id%22%3A%2239481%22%2C%22epid%22%3A%22425006%22%2C%22dubbing_support%22%3Afalse%2C%22background_audio%22%3Afalse%2C%22role_audio_list%22%3Afalse%7D&oid=975831006&panel_type=1&platform=android&s_locale=zh_CN&share_channel=COPY&share_id=pgc.pgc-video-detail.interaction.share.click&share_mode=1&share_origin=new_ogv&share_pattern=0&share_session_id=4cacc1e1-61b8-4311-a97f-f08a6fa7f89a&sid=417036046&spm_id=united.player-video-detail.0.0&statistics=%7B%22appId%22%3A1%2C%22platform%22%3A3%2C%22version%22%3A%227.71.0%22%2C%22abtest%22%3A%22%22%7D&tag=%7B%22share_from%22%3A%22ogv_video_detail_action_normal_share%22%7D&ts=1711207923&sign=1690a893b01799e007a5f75570a6d013

@z0z0r4
Copy link
Collaborator

z0z0r4 commented Mar 23, 2024

基本上,我没时间...如果你打算做的话,上面这些是不同类型 oid 对应的 share_idshare_origin 也是对应的,可以写个 type 来分类处理

如果你没想法的话,直接只支持把网址缩短就行,那我就直接合并,上面留着备忘

如果你要做的话踢一下我,PR 放着先不合并 @TimG233

@z0z0r4 z0z0r4 added the feature 新功能 label Mar 23, 2024
不需要 try,不成功就应该报错
@TimG233
Copy link
Contributor Author

TimG233 commented Mar 25, 2024

ok感谢! 我下周有时间看一下怎么改改比较好

@TimG233
Copy link
Contributor Author

TimG233 commented Jul 3, 2024

之前各种事情有些忙碌,耽搁了一阵。
我感觉这个get_short_url的传参有点简单问题复杂化了。如果用户使用的目的就是简单的去拿一个能用的短链接,那么这么多参数其实他也不知道传什么,更不可能说自己再去查个oid出来,所以我还是比较倾向于之前那种(只要他能一直用)直接一个url传参进来的方式,这样使用起来对用户会友好很多。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 新功能
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[新功能] 生成 b23.tv 短链接
2 participants