mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-21 18:22:30 +01:00
[bilibili] support large articles
This commit is contained in:
parent
6eef3e3495
commit
fc59e0fb14
@ -9,7 +9,7 @@
|
|||||||
"""Extractors for https://www.bilibili.com/"""
|
"""Extractors for https://www.bilibili.com/"""
|
||||||
|
|
||||||
from .common import Extractor, Message
|
from .common import Extractor, Message
|
||||||
from .. import text, exception
|
from .. import text, util, exception
|
||||||
|
|
||||||
|
|
||||||
class BilibiliExtractor(Extractor):
|
class BilibiliExtractor(Extractor):
|
||||||
@ -50,16 +50,21 @@ class BilibiliArticleExtractor(BilibiliExtractor):
|
|||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
article = self.api.article(self.item)
|
article = self.api.article(self.item)
|
||||||
article["username"] = article["modules"]["module_author"]["name"]
|
|
||||||
article["id"] = article["id_str"]
|
|
||||||
|
|
||||||
dynamic_major = article["modules"]["module_dynamic"]["major"]
|
# Flatten modules list
|
||||||
if dynamic_major["type"] == "MAJOR_TYPE_OPUS":
|
modules = {}
|
||||||
urls = [pic["url"] for pic in dynamic_major["opus"]["pics"]]
|
for module in article["detail"]["modules"]:
|
||||||
else:
|
del module['module_type']
|
||||||
urls = []
|
modules.update(module)
|
||||||
self.log.warning("%s: Unsupported article type '%s'",
|
article["detail"]["modules"] = modules
|
||||||
article["id"], dynamic_major["type"])
|
|
||||||
|
article["username"] = modules["module_author"]["name"]
|
||||||
|
|
||||||
|
urls = []
|
||||||
|
for paragraph in modules['module_content']['paragraphs']:
|
||||||
|
pics = paragraph.get('pic', {}).get('pics', [])
|
||||||
|
for pic in pics:
|
||||||
|
urls.append(pic['url'])
|
||||||
|
|
||||||
yield Message.Directory, article
|
yield Message.Directory, article
|
||||||
for article["num"], url in enumerate(urls, 1):
|
for article["num"], url in enumerate(urls, 1):
|
||||||
@ -94,9 +99,7 @@ class BilibiliAPI():
|
|||||||
break
|
break
|
||||||
|
|
||||||
def article(self, article_id):
|
def article(self, article_id):
|
||||||
endpoint = "/detail"
|
url = "https://www.bilibili.com/opus/{}".format(article_id)
|
||||||
params = {
|
response = self.extractor.request(url)
|
||||||
"id": article_id,
|
return util.json_loads(text.extr(
|
||||||
"features": "itemOpusStyle",
|
response.text, "window.__INITIAL_STATE__=", ";"))
|
||||||
}
|
|
||||||
return self._call(endpoint, params)["data"]["item"]
|
|
||||||
|
Loading…
Reference in New Issue
Block a user