]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/dumpert.py
Update changelog.
[youtubedl] / youtube_dl / extractor / dumpert.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 int_or_none,
7 qualities,
8 )
9
10
11 class DumpertIE(InfoExtractor):
12 _VALID_URL = r'(?P<protocol>https?)://(?:(?:www|legacy)\.)?dumpert\.nl/(?:mediabase|embed|item)/(?P<id>[0-9]+[/_][0-9a-zA-Z]+)'
13 _TESTS = [{
14 'url': 'https://www.dumpert.nl/item/6646981_951bc60f',
15 'md5': '1b9318d7d5054e7dcb9dc7654f21d643',
16 'info_dict': {
17 'id': '6646981/951bc60f',
18 'ext': 'mp4',
19 'title': 'Ik heb nieuws voor je',
20 'description': 'Niet schrikken hoor',
21 'thumbnail': r're:^https?://.*\.jpg$',
22 }
23 }, {
24 'url': 'https://www.dumpert.nl/embed/6675421_dc440fe7',
25 'only_matching': True,
26 }, {
27 'url': 'http://legacy.dumpert.nl/mediabase/6646981/951bc60f',
28 'only_matching': True,
29 }, {
30 'url': 'http://legacy.dumpert.nl/embed/6675421/dc440fe7',
31 'only_matching': True,
32 }]
33
34 def _real_extract(self, url):
35 video_id = self._match_id(url).replace('_', '/')
36 item = self._download_json(
37 'http://api-live.dumpert.nl/mobile_api/json/info/' + video_id.replace('/', '_'),
38 video_id)['items'][0]
39 title = item['title']
40 media = next(m for m in item['media'] if m.get('mediatype') == 'VIDEO')
41
42 quality = qualities(['flv', 'mobile', 'tablet', '720p'])
43 formats = []
44 for variant in media.get('variants', []):
45 uri = variant.get('uri')
46 if not uri:
47 continue
48 version = variant.get('version')
49 formats.append({
50 'url': uri,
51 'format_id': version,
52 'quality': quality(version),
53 })
54 self._sort_formats(formats)
55
56 thumbnails = []
57 stills = item.get('stills') or {}
58 for t in ('thumb', 'still'):
59 for s in ('', '-medium', '-large'):
60 still_id = t + s
61 still_url = stills.get(still_id)
62 if not still_url:
63 continue
64 thumbnails.append({
65 'id': still_id,
66 'url': still_url,
67 })
68
69 stats = item.get('stats') or {}
70
71 return {
72 'id': video_id,
73 'title': title,
74 'description': item.get('description'),
75 'thumbnails': thumbnails,
76 'formats': formats,
77 'duration': int_or_none(media.get('duration')),
78 'like_count': int_or_none(stats.get('kudos_total')),
79 'view_count': int_or_none(stats.get('views_total')),
80 }