]> asedeno.scripts.mit.edu Git - youtube-dl.git/blob - youtube_dl/extractor/xboxclips.py
[eroprofile] Skip test
[youtube-dl.git] / youtube_dl / extractor / xboxclips.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import (
8     compat_parse_qs,
9     compat_urllib_parse_urlparse,
10 )
11 from ..utils import (
12     int_or_none,
13     month_by_abbreviation,
14     parse_filesize,
15 )
16
17
18 class XboxClipsIE(InfoExtractor):
19     _VALID_URL = r'https?://(?:www\.)?(?:xboxclips\.com|gameclips\.io)/(?:video\.php\?.*vid=|[^/]+/)(?P<id>[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})'
20     _TESTS = [{
21         'url': 'http://xboxclips.com/video.php?uid=2533274823424419&gamertag=Iabdulelah&vid=074a69a9-5faf-46aa-b93b-9909c1720325',
22         'md5': 'fbe1ec805e920aeb8eced3c3e657df5d',
23         'info_dict': {
24             'id': '074a69a9-5faf-46aa-b93b-9909c1720325',
25             'ext': 'mp4',
26             'title': 'iAbdulElah playing Titanfall',
27             'filesize_approx': 26800000,
28             'upload_date': '20140807',
29             'duration': 56,
30         }
31     }, {
32         'url': 'https://gameclips.io/iAbdulElah/074a69a9-5faf-46aa-b93b-9909c1720325',
33         'only_matching': True,
34     }]
35
36     def _real_extract(self, url):
37         video_id = self._match_id(url)
38
39         if '/video.php' in url:
40             qs = compat_parse_qs(compat_urllib_parse_urlparse(url).query)
41             url = 'https://gameclips.io/%s/%s' % (qs['gamertag'][0], qs['vid'][0])
42
43         webpage = self._download_webpage(url, video_id)
44         info = self._parse_html5_media_entries(url, webpage, video_id)[0]
45
46         title = self._html_search_meta(['og:title', 'twitter:title'], webpage)
47         upload_date = None
48         mobj = re.search(
49             r'>Recorded: (\d{2})-(Jan|Feb|Mar|Apr|May|Ju[nl]|Aug|Sep|Oct|Nov|Dec)-(\d{4})',
50             webpage)
51         if mobj:
52             upload_date = '%s%.2d%s' % (mobj.group(3), month_by_abbreviation(mobj.group(2)), mobj.group(1))
53         filesize = parse_filesize(self._html_search_regex(
54             r'>Size: ([^<]+)<', webpage, 'file size', fatal=False))
55         duration = int_or_none(self._html_search_regex(
56             r'>Duration: (\d+) Seconds<', webpage, 'duration', fatal=False))
57         view_count = int_or_none(self._html_search_regex(
58             r'>Views: (\d+)<', webpage, 'view count', fatal=False))
59
60         info.update({
61             'id': video_id,
62             'title': title,
63             'upload_date': upload_date,
64             'filesize_approx': filesize,
65             'duration': duration,
66             'view_count': view_count,
67         })
68         return info