m13253 / BiliDan

Play videos on Bilibili.com with MPV and Danmaku2ASS
http://m13253.blogspot.com/2014/06/watch-bilibili-with-biligrab-danmaku2ass.html
Other
513 stars 69 forks source link

ERROR: Invalid URL: http://www.bilibili.com/av5697545/ #68

Closed WingGao closed 8 years ago

WingGao commented 8 years ago

ERROR: Invalid URL: http://www.bilibili.com/av5697545/

具体链接出处:http://www.bilibili.com/ranking_beta

m13253 commented 8 years ago

其实你漏了一个 "video/"。

是:http://www.bilibili.com/video/av5697545/

不过 B 站在 Nginx 端好心帮你补上了(笑

cnbeining commented 8 years ago

Wait:

So you actually typed the URL into the shell?....

m13253 commented 8 years ago

So you actually typed the URL into the shell?....

B站那个链接也打错了,楼主用的那个链接。

WingGao commented 8 years ago

主要是它开了一个新的排行榜页面,上面的链接都是这样的,我用js自动打开bilidan脚本才发现如上错误的。想着如果能在bilidan脚本里处理url的话是最好的。

m13253 commented 8 years ago

parse_url 函数 76 行,代码如下

        regex = re.compile('(http:/*[^/]+/video/)?av(\\d+)(/|/index.html|/index_(\\d+).html)?(\\?|#|$)')

是用一个正则把 av 号拉出来。你们看看这个正则怎么改比较好。

另外其实不要完整网址,只输入 avXXXX 或者 avXXXX/index_Y.html 也可以。

WingGao commented 8 years ago
regex = re.compile('(.*?bilibili\.com.*?)?av(\\d+)(/|/index.html|/index_(\\d+).html)?(\\?|#|$)')

这样怎么样?

运行结果

新不带video地址 => http://www.bilibili.com/av5697545/ regex.macth = ('http://www.bilibili.com/', '5697545', '/', None, '') 原video地址 => http://www.bilibili.com/video/av5697545/ regex.macth = ('http://www.bilibili.com/video/', '5697545', '/', None, '') 分P => http://www.bilibili.com/video/av5715137/index_2.html regex.macth = ('http://www.bilibili.com/video/', '5715137', '/index_2.html', '2', '') 精简avxxxx => av5697545 regex.macth = (None, '5697545', None, None, '') 精简avxxx/index => av5715137/index_2.html regex.macth = (None, '5715137', '/index_2.html', '2', '')

m13253 commented 8 years ago

这样怎么样?

一个好的正则要能 block 掉所有不合法的格式,这样如果遇到了系统升级啊之类的改变,要能正确报错。

我改成了:

regex = re.compile('(?:http:/*[^/]+/(?:video/)?)?av(\\d+)(?:/|/index.html|/index_(\\d+).html)?(?:\\?|#|$)')