[vidio] Add extractor (Closes #7195)
[youtube-dl] / youtube_dl / extractor / vidio.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 from .common import InfoExtractor
6
7 from ..utils import int_or_none
8
9
10 class VidioIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:www\.)?vidio\.com/watch/(?P<id>\d{6})-(?P<display_id>[^/?]+)'
12     _TEST = {
13         'url': 'http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015',
14         'info_dict': {
15             'id': '165683',
16             'title': 'DJ_AMBRED - Booyah (Live 2015)',
17             'ext': 'mp4',
18             'thumbnail': 'https://cdn0-a.production.vidio.static6.com/uploads/video/image/165683/dj_ambred-booyah-live-2015-bfb2ba.jpg',
19             'description': 'md5:27dc15f819b6a78a626490881adbadf8',
20             'duration': 149, 
21         },
22         'params': {
23             # m3u8 download
24             'skip_download': True
25         }
26     }
27
28     def _real_extract(self, url):
29         mobj = re.match(self._VALID_URL, url)
30         video_id, display_id = mobj.group('id', 'display_id')
31
32         webpage = self._download_webpage(url, display_id)
33
34         video_data = self._parse_json(self._html_search_regex(
35             r'data-json-clips\s*=\s*"\[(.+)\]"', webpage, 'video data'), display_id)
36
37         formats = self._extract_m3u8_formats(
38             video_data['sources'][0]['file'],
39             display_id, ext='mp4')
40
41         return {
42             'id': video_id,
43             'title': self._og_search_title(webpage),
44             'formats': formats,
45             'thumbnail': video_data.get('image'),
46             'description': self._og_search_description(webpage),
47             'duration': int_or_none(video_data.get('clip_duration')),
48         }