From 4bf5bc2403e421187d53aab7a3d8ed528bad736c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 31 May 2022 15:14:37 +0200 Subject: [PATCH] [weibo] support 'livephoto' entries (#2146) --- docs/configuration.rst | 10 ++++++++++ docs/gallery-dl.conf | 1 + gallery_dl/extractor/weibo.py | 19 +++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 3cde0741..dc43b3f4 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -2450,6 +2450,16 @@ Description Note: This requires 1 additional HTTP request per submission. +extractor.weibo.livephoto +------------------------- +Type + ``bool`` +Default + ``true`` +Description + Download ``livephoto`` files. + + extractor.weibo.retweets ------------------------ Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index af8bba6a..76babeae 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -301,6 +301,7 @@ }, "weibo": { + "livephoto": true, "retweets": true, "videos": true }, diff --git a/gallery_dl/extractor/weibo.py b/gallery_dl/extractor/weibo.py index 2b76967f..25b092da 100644 --- a/gallery_dl/extractor/weibo.py +++ b/gallery_dl/extractor/weibo.py @@ -28,6 +28,7 @@ class WeiboExtractor(Extractor): Extractor.__init__(self, match) self.retweets = self.config("retweets", True) self.videos = self.config("videos", True) + self.livephoto = self.config("livephoto", True) cookies = _cookie_cache() if cookies is not None: @@ -92,7 +93,8 @@ class WeiboExtractor(Extractor): files = self._files_from_status(status) for num, file in enumerate(files, 1): - text.nameext_from_url(file["url"], file) + if "filename" not in file: + text.nameext_from_url(file["url"], file) file["status"] = status file["num"] = num yield Message.Url, file["url"], file @@ -106,7 +108,14 @@ class WeiboExtractor(Extractor): if pic_ids: pics = status["pic_infos"] for pic_id in pic_ids: - yield pics[pic_id]["largest"].copy() + pic = pics[pic_id] + yield pic["largest"].copy() + + if pic.get("type") == "livephoto" and self.livephoto: + file = {"url": pic["video"]} + file["filehame"], _, file["extension"] = \ + pic["video"].rpartition("%2F")[2].rpartition(".") + yield file if "page_info" in status: page_info = status["page_info"] @@ -195,6 +204,12 @@ class WeiboStatusExtractor(WeiboExtractor): "options": (("retweets", "original"),), "keyword": {"status": {"id": 4600167083287033}}, }), + # livephoto (#2146) + ("https://weibo.com/5643044717/KkuDZ4jAA", { + "range": "2,4,6", + "pattern": r"https://video\.weibo\.com/media/play\?livephoto=" + r"https%3A%2F%2Fus.sinaimg.cn%2F\w+\.mov", + }), ("https://m.weibo.cn/status/4339748116375525"), ("https://m.weibo.cn/5746766133/4339748116375525"), )