Browse Source

Match new url scheme

master
wchen342 2 years ago
parent
commit
52ce95bdb9
Signed by: wchen342 GPG Key ID: 720B70365E800508
  1. 23
      bilibili.py

23
bilibili.py

@ -20,7 +20,7 @@ from youtube_dl.utils import DownloadError, UnavailableVideoError, MaxDownloadsR
DEFAULT_VALUES = {
'merge': True,
'delete_flv': False,
'max_retry': 5,
'max_retry': 10,
'output': "%(title)s-|||||||-%(id)s.%(ext)s",
'output_dir': os.getcwd(),
'debug': False,
@ -211,23 +211,34 @@ class Bilibili:
if self.p_start is None or self.p_end is None:
return [url]
else:
_VALID_URL = r'https?://(?:www\.|bangumi\.|)bilibili\.(?:tv|com)/(?:video/av|anime/(?P<anime_id>\d+)/play#)(?P<id>\d+)(?:/?\?p=(?P<page>\d+))?'
_VALID_URL = r'''(?x)
https?://
(?:(?:www|bangumi)\.)?
bilibili\.(?:tv|com)/
(?:
(?:
video/[aA][vV]|
anime/(?P<anime_id>\d+)/play\#
)(?P<id_bv>\d+)|
video/[bB][vV](?P<id>[^/?#&]+)
)(?:/?\?p=(?P<page>\d+))?
'''
mobj = re.match(_VALID_URL, url)
video_id = mobj.group('id')
video_id = mobj.group('id') or mobj.group('id_bv')
anime_id = mobj.group('anime_id')
page = mobj.group('page') or 1
url_list = []
pos = mobj.regs[3]
pos = mobj.regs[4]
# Get last position of video id, matching group 2
v_pos = mobj.regs[2]
v_pos = mobj.regs[3]
base_url = url[:v_pos[1] + 1]
if not base_url:
raise RuntimeError("Regex matching failed")
for i in range(int(self.p_start), int(self.p_end) + 1):
# We know 'page' is matching group 3
if pos[0] == -1 or pos[1] == -1: # No p= part
new_url = base_url + '/?p=' + str(i)
new_url = base_url + '?p=' + str(i)
else: # Has p= part
url_part1 = url[:pos[0]]
url_part2 = url[pos[1]:]

Loading…
Cancel
Save