dumpert.py 2.2 KB

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