diff --git a/gallery_dl/extractor/weibo.py b/gallery_dl/extractor/weibo.py index 54171986..07bed79d 100644 --- a/gallery_dl/extractor/weibo.py +++ b/gallery_dl/extractor/weibo.py @@ -86,8 +86,11 @@ class WeiboExtractor(Extractor): status["count"] = len(files) yield Message.Directory, status - for num, file in enumerate(files, 1): + num = 0 + for file in files: url = file["url"] + if not url: + continue if url.startswith("http:"): url = f"https:{url[5:]}" if "filename" not in file: @@ -98,6 +101,7 @@ class WeiboExtractor(Extractor): url = f"ytdl:{url}" file["_ytdl_manifest"] = "hls" file["extension"] = "mp4" + num += 1 file["status"] = status file["num"] = num yield Message.Url, url, file @@ -148,11 +152,21 @@ class WeiboExtractor(Extractor): media = max(info["playback_list"], key=lambda m: m["meta"]["quality_index"]) except Exception: - return {"url": (info.get("replay_hd") or - info.get("stream_url_hd") or - info.get("stream_url") or "")} + video = {"url": (info.get("replay_hd") or + info.get("stream_url_hd") or + info.get("stream_url") or "")} else: - return media["play_info"].copy() + video = media["play_info"].copy() + + if "//wblive-out." in video["url"] and \ + not text.ext_from_url(video["url"]): + try: + video["url"] = self.request_location(video["url"]) + except exception.HttpError as exc: + self.log.warning("%s: %s", exc.__class__.__name__, exc) + video["url"] = "" + + return video def _status_by_id(self, status_id): url = f"{self.root}/ajax/statuses/show?id={status_id}" diff --git a/test/results/weibo.py b/test/results/weibo.py index 75bec21f..44a42bb2 100644 --- a/test/results/weibo.py +++ b/test/results/weibo.py @@ -331,4 +331,19 @@ __tests__ = ( "#count" : 1, }, +{ + "#url" : "https://weibo.com/3317906495/5217357545080355", + "#comment" : "stream as 'wblive-out.api.weibo.com' URL (#8339)", + "#class" : weibo.WeiboStatusExtractor, + "#results" : "ytdl:https://live.video.weibocdn.com/5073cc59-42fc-4b9c-9a61-852d44b0ccc3_index.m3u8", +}, + +{ + "#url" : "https://weibo.com/7130470964/5217692969600188", + "#comment" : "stream without replay (#8339)", + "#class" : weibo.WeiboStatusExtractor, + "#count" : 0, + "#log" : "HttpError: '404 ' for 'https://wblive-out.api.weibo.com/2/wblive/room/play?id=1022:2321325216257942356128'", +}, + )