From f9a8598f35ea735307b0d0c127d80e89224bad61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 19 Oct 2025 12:05:27 +0200 Subject: [PATCH] [weibo] add 'text' option (#8422) --- docs/configuration.rst | 11 +++++++++ docs/gallery-dl.conf | 1 + gallery_dl/extractor/weibo.py | 8 ++++++- test/results/weibo.py | 42 +++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 29fccf78..f05cb487 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -6626,6 +6626,17 @@ Description will be taken from the original posts, not the retweeted posts. +extractor.weibo.text +-------------------- +Type + ``bool`` +Default + ``false`` +Description + Extract full ``text`` & ``text_raw`` metadata + for statuses with truncated ``text``. + + extractor.weibo.videos ---------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index b04fb588..08b2b841 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -947,6 +947,7 @@ "livephoto": true, "movies" : false, "retweets" : false, + "text" : false, "videos" : true }, "xfolio": diff --git a/gallery_dl/extractor/weibo.py b/gallery_dl/extractor/weibo.py index 3c0f0776..428a4bf9 100644 --- a/gallery_dl/extractor/weibo.py +++ b/gallery_dl/extractor/weibo.py @@ -34,6 +34,7 @@ class WeiboExtractor(Extractor): def _init(self): self.livephoto = self.config("livephoto", True) self.retweets = self.config("retweets", False) + self.longtext = self.config("text", False) self.videos = self.config("videos", True) self.movies = self.config("movies", False) self.gifs = self.config("gifs", True) @@ -98,6 +99,10 @@ class WeiboExtractor(Extractor): files = [] self._extract_status(status, files) + if self.longtext and status.get("isLongText") and \ + status["text"].endswith('class="expand">展开'): + status = self._status_by_id(status["id"]) + status["date"] = text.parse_datetime( status["created_at"], "%a %b %d %H:%M:%S %z %Y") status["count"] = len(files) @@ -190,7 +195,8 @@ class WeiboExtractor(Extractor): return video def _status_by_id(self, status_id): - url = f"{self.root}/ajax/statuses/show?id={status_id}" + url = (f"{self.root}/ajax/statuses/show" + f"?id={status_id}&isGetLongText=true") return self.request_json(url) def _user_id(self): diff --git a/test/results/weibo.py b/test/results/weibo.py index 44a42bb2..3b3759ab 100644 --- a/test/results/weibo.py +++ b/test/results/weibo.py @@ -346,4 +346,46 @@ __tests__ = ( "#log" : "HttpError: '404 ' for 'https://wblive-out.api.weibo.com/2/wblive/room/play?id=1022:2321325216257942356128'", }, +{ + "#url" : "https://weibo.com/1893905030/Q9yKt97ID", + "#comment" : "truncated 'text' / 'isLongText: true' (#8422)", + "#class" : weibo.WeiboStatusExtractor, + "#results" : ( + "https://wx1.sinaimg.cn/large/70e2b286gy1i6fho7ydx0j20fa08lt8u.jpg", + "https://wx1.sinaimg.cn/large/70e2b286gy1i6fho7zwhmj20u00gvmzg.jpg", + "https://wx4.sinaimg.cn/large/70e2b286gy1i6fho80b47j21u8112wh3.jpg", + ), + + "status" : { + "id" : 5222785292174627, + "isLongText" : True, + "textLength" : 750, + "text" : """【加快生产速度!曝任天堂明年3月生产2500万台#Switch2#】据彭博社报道,#任天堂#已要求供应商在2026年3月底之前生产多达2500万台Switch 2。

知情人士透露,考虑到今年假期旺季(黑色星期五、圣诞节和新年假期)以及明年初的持续需求,任天堂已要求制造合作伙伴加快生产进度。尽管任天堂计划自2024年底开始组装Switch 2,但根据年底购物季的实际需求情况,最终产量目标仍有可能进行调整。

彭博社分析认为,任天堂的出货量很可能轻松超越分析师预测的1760万台,甚至超出公司自身更为保守的公开预期。根据组装厂商的发货估算,任天堂在本财年(截至2026年3月)预计将售出约2000万台Switch 2,剩余库存则将结转到下一财年。

市场研究机构Circana的数据显示,美国为任天堂最大市场,Switch 2的销售表现比2017年发售的初代Switch高出77%。按照这一趋势,任天堂很可能提前几个月就能超额完成其保守的销售目标。""", + "text_raw" : """\ +【加快生产速度!曝任天堂明年3月生产2500万台#Switch2#】据彭博社报道,#任天堂#已要求供应商在2026年3月底之前生产多达2500万台Switch 2。 + +知情人士透露,考虑到今年假期旺季(黑色星期五、圣诞节和新年假期)以及明年初的持续需求,任天堂已要求制造合作伙伴加快生产进度。尽管任天堂计划自2024年底开始组装Switch 2,但根据年底购物季的实际需求情况,最终产量目标仍有可能进行调整。 + +彭博社分析认为,任天堂的出货量很可能轻松超越分析师预测的1760万台,甚至超出公司自身更为保守的公开预期。根据组装厂商的发货估算,任天堂在本财年(截至2026年3月)预计将售出约2000万台Switch 2,剩余库存则将结转到下一财年。 + +市场研究机构Circana的数据显示,美国为任天堂最大市场,Switch 2的销售表现比2017年发售的初代Switch高出77%。按照这一趋势,任天堂很可能提前几个月就能超额完成其保守的销售目标。\ +""", + "longText" : { + "created_at" : "Fri Oct 17 17:15:11 +0800 2025", + "mblog_vip_type": 0, + "show_attitude_bar": 0, + "weibo_position": 1, + "content" : """\ +【加快生产速度!曝任天堂明年3月生产2500万台#Switch2#】据彭博社报道,#任天堂#已要求供应商在2026年3月底之前生产多达2500万台Switch 2。 + +知情人士透露,考虑到今年假期旺季(黑色星期五、圣诞节和新年假期)以及明年初的持续需求,任天堂已要求制造合作伙伴加快生产进度。尽管任天堂计划自2024年底开始组装Switch 2,但根据年底购物季的实际需求情况,最终产量目标仍有可能进行调整。 + +彭博社分析认为,任天堂的出货量很可能轻松超越分析师预测的1760万台,甚至超出公司自身更为保守的公开预期。根据组装厂商的发货估算,任天堂在本财年(截至2026年3月)预计将售出约2000万台Switch 2,剩余库存则将结转到下一财年。 + +市场研究机构Circana的数据显示,美国为任天堂最大市场,Switch 2的销售表现比2017年发售的初代Switch高出77%。按照这一趋势,任天堂很可能提前几个月就能超额完成其保守的销售目标。\ +""", + }, + }, +}, + )