]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/vimple.py
Implement universal format sorting
[yt-dlp.git] / yt_dlp / extractor / vimple.py
1 from .common import InfoExtractor
2 from ..utils import int_or_none
3
4
5 class SprutoBaseIE(InfoExtractor):
6 def _extract_spruto(self, spruto, video_id):
7 playlist = spruto['playlist'][0]
8 title = playlist['title']
9 video_id = playlist.get('videoId') or video_id
10 thumbnail = playlist.get('posterUrl') or playlist.get('thumbnailUrl')
11 duration = int_or_none(playlist.get('duration'))
12
13 formats = [{
14 'url': f['url'],
15 } for f in playlist['video']]
16 self._sort_formats(formats)
17
18 return {
19 'id': video_id,
20 'title': title,
21 'thumbnail': thumbnail,
22 'duration': duration,
23 'formats': formats,
24 }
25
26
27 class VimpleIE(SprutoBaseIE):
28 IE_DESC = 'Vimple - one-click video hosting'
29 _VALID_URL = r'https?://(?:player\.vimple\.(?:ru|co)/iframe|vimple\.(?:ru|co))/(?P<id>[\da-f-]{32,36})'
30 _TESTS = [{
31 'url': 'http://vimple.ru/c0f6b1687dcd4000a97ebe70068039cf',
32 'md5': '2e750a330ed211d3fd41821c6ad9a279',
33 'info_dict': {
34 'id': 'c0f6b168-7dcd-4000-a97e-be70068039cf',
35 'ext': 'mp4',
36 'title': 'Sunset',
37 'duration': 20,
38 'thumbnail': r're:https?://.*?\.jpg',
39 },
40 }, {
41 'url': 'http://player.vimple.ru/iframe/52e1beec-1314-4a83-aeac-c61562eadbf9',
42 'only_matching': True,
43 }, {
44 'url': 'http://vimple.co/04506a053f124483b8fb05ed73899f19',
45 'only_matching': True,
46 }]
47
48 def _real_extract(self, url):
49 video_id = self._match_id(url)
50
51 webpage = self._download_webpage(
52 'http://player.vimple.ru/iframe/%s' % video_id, video_id)
53
54 spruto = self._parse_json(
55 self._search_regex(
56 r'sprutoData\s*:\s*({.+?}),\r\n', webpage, 'spruto data'),
57 video_id)
58
59 return self._extract_spruto(spruto, video_id)