From 48e821ab165ce3be525fd007a26427162a9fbb74 Mon Sep 17 00:00:00 2001 From: zhangzhanming Date: Wed, 28 Jun 2023 21:12:55 +0800 Subject: [PATCH] [extractor/JdItemVideo] Add Extractor. fix some problems --- yt_dlp/extractor/jditemvideo.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/yt_dlp/extractor/jditemvideo.py b/yt_dlp/extractor/jditemvideo.py index 18f385ddd8..a04c858a45 100644 --- a/yt_dlp/extractor/jditemvideo.py +++ b/yt_dlp/extractor/jditemvideo.py @@ -4,7 +4,7 @@ import random import time from .common import InfoExtractor -from ..utils import determine_ext, ExtractorError +from ..utils import determine_ext, ExtractorError, traverse_obj class JdItemVideoIE(InfoExtractor): @@ -52,8 +52,7 @@ class JdItemVideoIE(InfoExtractor): def _real_extract(self, url): item_id = self._match_id(url=url) resp = self._download_webpage(url_or_request=url, video_id=item_id) - pattern_data = self._html_search_regex(pattern=r'"mainVideoId":"(\d+?)"', string=resp, name='videoId', - default=None) + pattern_data = self._html_search_regex(pattern=r'"mainVideoId":"(\d+?)"', string=resp, name='videoId') if pattern_data is None: raise ExtractorError("There are no any video. %s" % url) @@ -75,11 +74,11 @@ class JdItemVideoIE(InfoExtractor): info_dict = { 'id': item_id, 'ext': ext, - 'title': detailRespJson.get("extInfo", {}).get("videoName") or "unknown_video_title", + 'title': traverse_obj(detailRespJson, ('extInfo', 'videoName'), default="unknown_video_title"), 'description': description, - 'size': detailRespJson.get("extInfo", {}).get("size"), - 'width': detailRespJson.get("extInfo", {}).get("vwidth"), - 'height': detailRespJson.get("extInfo", {}).get("vheight"), + 'size': traverse_obj(detailRespJson, ("extInfo","size")), + 'width': traverse_obj(detailRespJson, ("extInfo", "vwidth")), + 'height': traverse_obj(detailRespJson, ("extInfo", "vheight")), 'duration': detailRespJson.get("duration"), 'thumbnail': detailRespJson.get("imageUrl"), 'url': detailRespJson.get("playUrl")