]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/dumpert.py
999fb5620df2976073122fb95fbad1bb133f357a
[youtubedl] / youtube_dl / extractor / dumpert.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import base64
5
6 from .common import InfoExtractor
7 from ..compat import compat_urllib_request
8 from ..utils import qualities
9
10
11 class DumpertIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?dumpert\.nl/mediabase/(?P<id>[0-9]+/[0-9a-zA-Z]+)'
13 _TEST = {
14 'url': 'http://www.dumpert.nl/mediabase/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': 're:^https?://.*\.jpg$',
22 }
23 }
24
25 def _real_extract(self, url):
26 video_id = self._match_id(url)
27
28 req = compat_urllib_request.Request(url)
29 req.add_header('Cookie', 'nsfw=1; cpc=10')
30 webpage = self._download_webpage(req, video_id)
31
32 files_base64 = self._search_regex(
33 r'data-files="([^"]+)"', webpage, 'data files')
34
35 files = self._parse_json(
36 base64.b64decode(files_base64.encode('utf-8')).decode('utf-8'),
37 video_id)
38
39 quality = qualities(['flv', 'mobile', 'tablet', '720p'])
40
41 formats = [{
42 'url': video_url,
43 'format_id': format_id,
44 'quality': quality(format_id),
45 } for format_id, video_url in files.items() if format_id != 'still']
46 self._sort_formats(formats)
47
48 title = self._html_search_meta(
49 'title', webpage) or self._og_search_title(webpage)
50 description = self._html_search_meta(
51 'description', webpage) or self._og_search_description(webpage)
52 thumbnail = files.get('still') or self._og_search_thumbnail(webpage)
53
54 return {
55 'id': video_id,
56 'title': title,
57 'description': description,
58 'thumbnail': thumbnail,
59 'formats': formats
60 }