dumpert.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. determine_ext,
  4. int_or_none,
  5. qualities,
  6. )
  7. class DumpertIE(InfoExtractor):
  8. _VALID_URL = r'''(?x)
  9. (?P<protocol>https?)://(?:(?:www|legacy)\.)?dumpert\.nl/(?:
  10. (?:mediabase|embed|item)/|
  11. [^#]*[?&]selectedId=
  12. )(?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. 'duration': 9,
  23. 'view_count': int,
  24. 'like_count': int,
  25. },
  26. }, {
  27. 'url': 'https://www.dumpert.nl/embed/6675421_dc440fe7',
  28. 'only_matching': True,
  29. }, {
  30. 'url': 'http://legacy.dumpert.nl/mediabase/6646981/951bc60f',
  31. 'only_matching': True,
  32. }, {
  33. 'url': 'http://legacy.dumpert.nl/embed/6675421/dc440fe7',
  34. 'only_matching': True,
  35. }, {
  36. 'url': 'https://www.dumpert.nl/item/100031688_b317a185',
  37. 'info_dict': {
  38. 'id': '100031688/b317a185',
  39. 'ext': 'mp4',
  40. 'title': 'Epic schijnbeweging',
  41. 'description': '<p>Die zag je niet eh</p>',
  42. 'thumbnail': r're:^https?://.*\.(?:jpg|png)$',
  43. 'duration': 12,
  44. 'view_count': int,
  45. 'like_count': int,
  46. },
  47. 'params': {'skip_download': 'm3u8'},
  48. }, {
  49. 'url': 'https://www.dumpert.nl/toppers?selectedId=100031688_b317a185',
  50. 'only_matching': True,
  51. }, {
  52. 'url': 'https://www.dumpert.nl/latest?selectedId=100031688_b317a185',
  53. 'only_matching': True,
  54. }, {
  55. 'url': 'https://www.dumpert.nl/?selectedId=100031688_b317a185',
  56. 'only_matching': True,
  57. }, {
  58. 'url': 'https://www.dumpert.nl/toppers/dag?selectedId=100086074_f5cef3ac',
  59. 'only_matching': True,
  60. }]
  61. def _real_extract(self, url):
  62. video_id = self._match_id(url).replace('_', '/')
  63. item = self._download_json(
  64. 'http://api-live.dumpert.nl/mobile_api/json/info/' + video_id.replace('/', '_'),
  65. video_id)['items'][0]
  66. title = item['title']
  67. media = next(m for m in item['media'] if m.get('mediatype') == 'VIDEO')
  68. quality = qualities(['flv', 'mobile', 'tablet', '720p', '1080p'])
  69. formats = []
  70. for variant in media.get('variants', []):
  71. uri = variant.get('uri')
  72. if not uri:
  73. continue
  74. version = variant.get('version')
  75. preference = quality(version)
  76. if determine_ext(uri) == 'm3u8':
  77. formats.extend(self._extract_m3u8_formats(
  78. uri, video_id, 'mp4', m3u8_id=version, quality=preference))
  79. else:
  80. formats.append({
  81. 'url': uri,
  82. 'format_id': version,
  83. 'quality': preference,
  84. })
  85. thumbnails = []
  86. stills = item.get('stills') or {}
  87. for t in ('thumb', 'still'):
  88. for s in ('', '-medium', '-large'):
  89. still_id = t + s
  90. still_url = stills.get(still_id)
  91. if not still_url:
  92. continue
  93. thumbnails.append({
  94. 'id': still_id,
  95. 'url': still_url,
  96. })
  97. stats = item.get('stats') or {}
  98. return {
  99. 'id': video_id,
  100. 'title': title,
  101. 'description': item.get('description'),
  102. 'thumbnails': thumbnails,
  103. 'formats': formats,
  104. 'duration': int_or_none(media.get('duration')),
  105. 'like_count': int_or_none(stats.get('kudos_total')),
  106. 'view_count': int_or_none(stats.get('views_total')),
  107. }