From b478a0ac3f57f587ca3302469feaec8a0f034f9b Mon Sep 17 00:00:00 2001 From: 01001110 Date: Thu, 23 Mar 2023 20:00:44 +0800 Subject: [PATCH] [chelseafc] Add new extractor --- youtube_dl/extractor/chelseafc.py | 73 ++++++++++++++++++++++++++++++ youtube_dl/extractor/extractors.py | 1 + 2 files changed, 74 insertions(+) create mode 100644 youtube_dl/extractor/chelseafc.py diff --git a/youtube_dl/extractor/chelseafc.py b/youtube_dl/extractor/chelseafc.py new file mode 100644 index 000000000..5402ca801 --- /dev/null +++ b/youtube_dl/extractor/chelseafc.py @@ -0,0 +1,73 @@ +# coding: utf-8 +from __future__ import unicode_literals + +import json + +from .common import InfoExtractor +from ..utils import unified_timestamp, parse_duration + + +class ChelseafcIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?chelseafc\.com(?:/[a-z]+)?/video/(?P[a-z0-9]+(?:-[a-z0-9]+)*)' + _TESTS = [{ + 'url': 'https://www.chelseafc.com/en/video/full-match-chelsea-2-2-everton', + 'md5': '0f7cd37de17faa71566bfd9074315c85', + 'info_dict': { + 'id': 'full-match-chelsea-2-2-everton', + 'ext': 'mp4', + 'title': 'Full Match: Chelsea 2-2 Everton', + 'description': 'Full match highlights from Chelsea\'s 2-2 Premier League draw with Everton at Stamford Bridge. ', + 'duration': 2842.0, + 'timestamp': 1679184000, + 'upload_date': '20230319', + 'thumbnail': r're:https?://.*\.png' + } + }, + { + 'url': 'https://www.chelseafc.com/en/video/manchester-city-vs-chelsea-2-0-or-highlights-or-efl-cup', + 'md5': '01078658408ee98b1cf286d3b8f4b7ca', + 'info_dict': { + 'id': 'manchester-city-vs-chelsea-2-0-or-highlights-or-efl-cup', + 'ext': 'mp4', + 'title': 'Manchester City 2-0 Chelsea | Highlights | EFL Cup', + 'description': 'Highlights from our EFL Cup match against Man City.', + 'duration': 120.0, + 'timestamp': 1668042000, + 'upload_date': '20221110', + 'thumbnail': r're:https?://.*\.jpg' + } + }] + + def _real_extract(self, url): + video_id = self._match_id(url) + + webpage = self._download_webpage(url, video_id) + + raw_data = self._html_search_regex( + # TODO improve regex + r'(?:]+(?:data-component="VideoDetails".*?)+data-props="([^"]*))', + webpage, + 'data' + ) + data = json.loads(raw_data)['videoDetail'] + + manifest_url = data['signedUrl'] + formats = self._extract_m3u8_formats(manifest_url, video_id, 'mp4') + + 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'] + + return { + 'id': video_id, + 'title': title, + 'description': descripiton, + 'formats': formats, + 'duration': duration, + 'timestamp': timestamp, + 'tags': tags, + 'thumbnail': thumbnail + } diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 3a87f9e33..2a4620049 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -1682,3 +1682,4 @@ from .pr0gramm import ( Pr0grammIE, Pr0grammStaticIE, ) +from .chelseafc import ChelseafcIE