aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/weibo.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2020-10-12 18:14:27 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2020-10-12 18:14:27 -0400
commite0c914765184ebbf99cffdecfe8cdbe10f42486e (patch)
tree4dd89f11195c3f58b3b62b9911bbdc40d0e44471 /gallery_dl/extractor/weibo.py
parent9074eee175f76b824fbb6695d56426105191c51c (diff)
New upstream version 1.15.1.upstream/1.15.1
Diffstat (limited to 'gallery_dl/extractor/weibo.py')
-rw-r--r--gallery_dl/extractor/weibo.py55
1 files changed, 30 insertions, 25 deletions
diff --git a/gallery_dl/extractor/weibo.py b/gallery_dl/extractor/weibo.py
index 0b1b2d9..a325f87 100644
--- a/gallery_dl/extractor/weibo.py
+++ b/gallery_dl/extractor/weibo.py
@@ -47,21 +47,31 @@ class WeiboExtractor(Extractor):
file["num"] = num
yield Message.Url, file["url"], file
+ def statuses(self):
+ """Returns an iterable containing all relevant 'status' objects"""
+
+ def _status_by_id(self, status_id):
+ url = "{}/detail/{}".format(self.root, status_id)
+ page = self.request(url, fatal=False).text
+ data = text.extract(page, "var $render_data = [", "][0] || {};")[0]
+ return json.loads(data)["status"] if data else None
+
def _files_from_status(self, status):
- images = status.pop("pics", ())
page_info = status.pop("page_info", ())
-
- for image in images:
- pid = image["pid"]
- if "large" in image:
- image = image["large"]
- geo = image.get("geo") or {}
- yield text.nameext_from_url(image["url"], {
- "url" : image["url"],
- "pid" : pid,
- "width" : text.parse_int(geo.get("width")),
- "height": text.parse_int(geo.get("height")),
- })
+ if "pics" in status:
+ if len(status["pics"]) < status["pic_num"]:
+ status = self._status_by_id(status["id"]) or status
+ for image in status.pop("pics"):
+ pid = image["pid"]
+ if "large" in image:
+ image = image["large"]
+ geo = image.get("geo") or {}
+ yield text.nameext_from_url(image["url"], {
+ "url" : image["url"],
+ "pid" : pid,
+ "width" : text.parse_int(geo.get("width")),
+ "height": text.parse_int(geo.get("height")),
+ })
if self.videos and "media_info" in page_info:
info = page_info["media_info"]
@@ -79,9 +89,6 @@ class WeiboExtractor(Extractor):
data["_ytdl_extra"] = {"protocol": "m3u8_native"}
yield data
- def statuses(self):
- """Returns an iterable containing all relevant 'status' objects"""
-
class WeiboUserExtractor(WeiboExtractor):
"""Extractor for all images of a user on weibo.cn"""
@@ -107,13 +114,13 @@ class WeiboUserExtractor(WeiboExtractor):
while True:
data = self.request(url, params=params).json()
+ cards = data["data"]["cards"]
- for card in data["data"]["cards"]:
+ if not cards:
+ return
+ for card in cards:
if "mblog" in card:
yield card["mblog"]
-
- if not data["data"]["cards"]:
- return
params["page"] += 1
@@ -145,9 +152,7 @@ class WeiboStatusExtractor(WeiboExtractor):
self.status_id = match.group(1)
def statuses(self):
- url = "{}/detail/{}".format(self.root, self.status_id)
- page = self.request(url, notfound="status").text
- data = text.extract(page, "var $render_data = [", "][0] || {};")[0]
- if not data:
+ status = self._status_by_id(self.status_id)
+ if not status:
raise exception.NotFoundError("status")
- return (json.loads(data)["status"],)
+ return (status,)