diff --git a/src/you_get/extractor.py b/src/you_get/extractor.py index bd71717e72..fa2518dbbe 100644 --- a/src/you_get/extractor.py +++ b/src/you_get/extractor.py @@ -254,12 +254,6 @@ def download(self, **kwargs): x.write(srt) print('Done.') - if self.danmaku is not None and not dry_run: - filename = '{}.cmt.xml'.format(get_filename(self.title)) - print('Downloading {} ...\n'.format(filename)) - with open(os.path.join(kwargs['output_dir'], filename), 'w', encoding='utf8') as fp: - fp.write(self.danmaku) - if self.lyrics is not None and not dry_run: filename = '{}.lrc'.format(get_filename(self.title)) print('Downloading {} ...\n'.format(filename)) diff --git a/src/you_get/extractors/bilibili.py b/src/you_get/extractors/bilibili.py index ea67f92fcf..8d694275be 100644 --- a/src/you_get/extractors/bilibili.py +++ b/src/you_get/extractors/bilibili.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +import json +import re from ..common import * from ..extractor import VideoExtractor @@ -172,7 +174,7 @@ def prepare(self, **kwargs): # redirect: bangumi/play/ss -> bangumi/play/ep # redirect: bangumi.bilibili.com/anime -> bangumi/play/ep elif re.match(r'https?://(www\.)?bilibili\.com/bangumi/play/ss(\d+)', self.url) or \ - re.match(r'https?://bangumi\.bilibili\.com/anime/(\d+)/play', self.url): + re.match(r'https?://bangumi\.bilibili\.com/anime/(\d+)/play', self.url): initial_state_text = match1(html_content, r'__INITIAL_STATE__=(.*?);\(function\(\)') # FIXME initial_state = json.loads(initial_state_text) ep_id = initial_state['epList'][0]['id'] @@ -339,21 +341,15 @@ def prepare(self, **kwargs): # bangumi elif sort == 'bangumi': - initial_state_text = match1(html_content, r'__INITIAL_STATE__=(.*?);\(function\(\)') # FIXME - initial_state = json.loads(initial_state_text) - - # warn if this bangumi has more than 1 video - epn = len(initial_state['epList']) - if epn > 1 and not kwargs.get('playlist'): - log.w('This bangumi currently has %s videos. (use --playlist to download all videos.)' % epn) + eposide = kwargs['eposide_data'] # set video title - self.title = initial_state['h1Title'] + self.title = eposide['long_title'] # construct playinfos - ep_id = initial_state['epInfo']['id'] - avid = initial_state['epInfo']['aid'] - cid = initial_state['epInfo']['cid'] + ep_id = eposide['ep_id'] + avid = eposide['aid'] + cid = eposide['cid'] playinfos = [] api_url = self.bilibili_bangumi_api(avid, cid, ep_id) api_content = get_content(api_url, headers=self.bilibili_headers(referer=self.url)) @@ -630,7 +626,7 @@ def download_playlist_by_url(self, url, **kwargs): elif match1(html_content, r'')+13:urlcontent.find('')])['graph_version'] @@ -717,13 +713,17 @@ def download_playlist_by_url(self, url, **kwargs): self.download(**kwargs) elif sort == 'bangumi': - initial_state_text = match1(html_content, r'__INITIAL_STATE__=(.*?);\(function\(\)') # FIXME - initial_state = json.loads(initial_state_text) - epn, i = len(initial_state['epList']), 0 - for ep in initial_state['epList']: + epId = re.search(r'"videoId":"ep(.*?)"', html_content).group(1) + eposide_content = get_content(url="https://api.bilibili.com/pgc/view/web/ep/list?ep_id=%s" % (epId), + headers=self.bilibili_headers(referer=self.url)) + eposide_json = json.loads(eposide_content)["result"]["episodes"] + epn, i = len(eposide_json), 0 + for ep in eposide_json: i += 1; log.w('Extracting %s of %s videos ...' % (i, epn)) ep_id = ep['id'] epurl = 'https://www.bilibili.com/bangumi/play/ep%s/' % ep_id + kwargs['eposide_data'] = ep + ep['long_title']= ("%02d" % i) + ep['long_title'] self.__class__().download_by_url(epurl, **kwargs) elif sort == 'bangumi_md': diff --git a/src/you_get/util/fs.py b/src/you_get/util/fs.py index c04a10a74d..3ecd20e6e7 100644 --- a/src/you_get/util/fs.py +++ b/src/you_get/util/fs.py @@ -43,5 +43,5 @@ def legitimize(text, os=detect_os()): if text.startswith("."): text = text[1:] - text = text[:80] # Trim to 82 Unicode characters long + text = text[:160] # Trim to 82 Unicode characters long return text