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