[ie/twitter:spaces] Support video spaces (#10789)
[yt-dlp3.git] / yt_dlp / extractor / xboxclips.py
blobd726e62af2135a82931a31dc81696eeb4397a2e6
1 import re
3 from .common import InfoExtractor
4 from ..utils import (
5 int_or_none,
6 month_by_abbreviation,
7 parse_filesize,
8 parse_qs,
12 class XboxClipsIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?(?:xboxclips\.com|gameclips\.io)/(?:video\.php\?.*vid=|[^/]+/)(?P<id>[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})'
14 _TESTS = [{
15 'url': 'http://xboxclips.com/video.php?uid=2533274823424419&gamertag=Iabdulelah&vid=074a69a9-5faf-46aa-b93b-9909c1720325',
16 'md5': 'fbe1ec805e920aeb8eced3c3e657df5d',
17 'info_dict': {
18 'id': '074a69a9-5faf-46aa-b93b-9909c1720325',
19 'ext': 'mp4',
20 'title': 'iAbdulElah playing Titanfall',
21 'filesize_approx': 26800000,
22 'upload_date': '20140807',
23 'duration': 56,
25 }, {
26 'url': 'https://gameclips.io/iAbdulElah/074a69a9-5faf-46aa-b93b-9909c1720325',
27 'only_matching': True,
30 def _real_extract(self, url):
31 video_id = self._match_id(url)
33 if '/video.php' in url:
34 qs = parse_qs(url)
35 url = 'https://gameclips.io/{}/{}'.format(qs['gamertag'][0], qs['vid'][0])
37 webpage = self._download_webpage(url, video_id)
38 info = self._parse_html5_media_entries(url, webpage, video_id)[0]
40 title = self._html_search_meta(['og:title', 'twitter:title'], webpage)
41 upload_date = None
42 mobj = re.search(
43 r'>Recorded: (\d{2})-(Jan|Feb|Mar|Apr|May|Ju[nl]|Aug|Sep|Oct|Nov|Dec)-(\d{4})',
44 webpage)
45 if mobj:
46 upload_date = '%s%.2d%s' % (mobj.group(3), month_by_abbreviation(mobj.group(2)), mobj.group(1))
47 filesize = parse_filesize(self._html_search_regex(
48 r'>Size: ([^<]+)<', webpage, 'file size', fatal=False))
49 duration = int_or_none(self._html_search_regex(
50 r'>Duration: (\d+) Seconds<', webpage, 'duration', fatal=False))
51 view_count = int_or_none(self._html_search_regex(
52 r'>Views: (\d+)<', webpage, 'view count', fatal=False))
54 info.update({
55 'id': video_id,
56 'title': title,
57 'upload_date': upload_date,
58 'filesize_approx': filesize,
59 'duration': duration,
60 'view_count': view_count,
62 return info