From 6a9848f94a1a2c9f5886cfa5de9425e6c532a964 Mon Sep 17 00:00:00 2001 From: 01001110 Date: Sun, 2 Apr 2023 18:32:21 +0800 Subject: [PATCH] Modify extractor according to suggestions --- youtube_dl/extractor/chelseafc.py | 35 +++++++++++++++++-------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/youtube_dl/extractor/chelseafc.py b/youtube_dl/extractor/chelseafc.py index 5d4776c7b..b999354b5 100644 --- a/youtube_dl/extractor/chelseafc.py +++ b/youtube_dl/extractor/chelseafc.py @@ -1,10 +1,13 @@ # coding: utf-8 from __future__ import unicode_literals -import json - from .common import InfoExtractor -from ..utils import unified_timestamp, parse_duration +from ..utils import ( + parse_duration, + traverse_obj, + unified_timestamp, + url_or_none, +) class ChelseafcIE(InfoExtractor): @@ -56,25 +59,25 @@ class ChelseafcIE(InfoExtractor): 'data' ) - data = json.loads(raw_data)['videoDetail'] + data = self._parse_json(raw_data, video_id) + manifest_url = data['videoDetail']['signedUrl'] - manifest_url = data['signedUrl'] - formats = self._extract_m3u8_formats(manifest_url, video_id, 'mp4') + data = data['videoDetail'] title = data['title'] - descripiton = data['description'] - timestamp = unified_timestamp(data['releaseDate']) - duration = parse_duration(data['duration']) - tags = [tag['title'] for tag in data['tags']] - thumbnail = data['image']['file']['url'] + + formats = self._extract_m3u8_formats(manifest_url, video_id, 'mp4') + self._sort_formats(formats) + + txt_or_none = lambda x: x.strip() or None return { 'id': video_id, 'title': title, - 'description': descripiton, + 'description': txt_or_none(data.get('description')), 'formats': formats, - 'duration': duration, - 'timestamp': timestamp, - 'tags': tags, - 'thumbnail': thumbnail + 'duration': parse_duration(data.get('duration')), + 'timestamp': unified_timestamp(data.get('releaseDate')), + 'tags': traverse_obj(data, ('tags', Ellipsis, 'title'), expected_type=txt_or_none), + 'thumbnail': traverse_obj(data, ('image', 'file', 'url'), expected_type=url_or_none), }