f5a31058d5cd8b1f914e9968aeca98751fb90136
[youtube-dl] / youtube_dl / extractor / dumpert.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import base64
5 import re
6
7 from .common import InfoExtractor
8 from ..compat import compat_urllib_request
9 from ..utils import qualities
10
11
12 class DumpertIE(InfoExtractor):
13     _VALID_URL = r'(?P<protocol>https?)://(?:www\.)?dumpert\.nl/(?:mediabase|embed)/(?P<id>[0-9]+/[0-9a-zA-Z]+)'
14     _TESTS = [{
15         'url': 'http://www.dumpert.nl/mediabase/6646981/951bc60f/',
16         'md5': '1b9318d7d5054e7dcb9dc7654f21d643',
17         'info_dict': {
18             'id': '6646981/951bc60f',
19             'ext': 'mp4',
20             'title': 'Ik heb nieuws voor je',
21             'description': 'Niet schrikken hoor',
22             'thumbnail': 're:^https?://.*\.jpg$',
23         }
24     }, {
25         'url': 'http://www.dumpert.nl/embed/6675421/dc440fe7/',
26         'only_matching': True,
27     }]
28
29     def _real_extract(self, url):
30         mobj = re.match(self._VALID_URL, url)
31         video_id = mobj.group('id')
32         protocol = mobj.group('protocol')
33
34         url = '%s://www.dumpert.nl/mediabase/%s' % (protocol, video_id)
35         req = compat_urllib_request.Request(url)
36         req.add_header('Cookie', 'nsfw=1; cpc=10')
37         webpage = self._download_webpage(req, video_id)
38
39         files_base64 = self._search_regex(
40             r'data-files="([^"]+)"', webpage, 'data files')
41
42         files = self._parse_json(
43             base64.b64decode(files_base64.encode('utf-8')).decode('utf-8'),
44             video_id)
45
46         quality = qualities(['flv', 'mobile', 'tablet', '720p'])
47
48         formats = [{
49             'url': video_url,
50             'format_id': format_id,
51             'quality': quality(format_id),
52         } for format_id, video_url in files.items() if format_id != 'still']
53         self._sort_formats(formats)
54
55         title = self._html_search_meta(
56             'title', webpage) or self._og_search_title(webpage)
57         description = self._html_search_meta(
58             'description', webpage) or self._og_search_description(webpage)
59         thumbnail = files.get('still') or self._og_search_thumbnail(webpage)
60
61         return {
62             'id': video_id,
63             'title': title,
64             'description': description,
65             'thumbnail': thumbnail,
66             'formats': formats
67         }