logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

drbonanza.py (1981B)


  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. js_to_json,
  6. parse_duration,
  7. unescapeHTML,
  8. )
  9. class DRBonanzaIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?dr\.dk/bonanza/[^/]+/\d+/[^/]+/(?P<id>\d+)/(?P<display_id>[^/?#&]+)'
  11. _TEST = {
  12. 'url': 'http://www.dr.dk/bonanza/serie/154/matador/40312/matador---0824-komme-fremmede-',
  13. 'info_dict': {
  14. 'id': '40312',
  15. 'display_id': 'matador---0824-komme-fremmede-',
  16. 'ext': 'mp4',
  17. 'title': 'MATADOR - 08:24. "Komme fremmede".',
  18. 'description': 'md5:77b4c1ac4d4c1b9d610ab4395212ff84',
  19. 'thumbnail': r're:^https?://.*\.(?:gif|jpg)$',
  20. 'duration': 4613,
  21. },
  22. }
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id, display_id = mobj.group('id', 'display_id')
  26. webpage = self._download_webpage(url, display_id)
  27. info = self._parse_html5_media_entries(
  28. url, webpage, display_id, m3u8_id='hls',
  29. m3u8_entry_protocol='m3u8_native')[0]
  30. self._sort_formats(info['formats'])
  31. asset = self._parse_json(
  32. self._search_regex(
  33. r'(?s)currentAsset\s*=\s*({.+?})\s*</script', webpage, 'asset'),
  34. display_id, transform_source=js_to_json)
  35. title = unescapeHTML(asset['AssetTitle']).strip()
  36. def extract(field):
  37. return self._search_regex(
  38. r'<div[^>]+>\s*<p>%s:<p>\s*</div>\s*<div[^>]+>\s*<p>([^<]+)</p>' % field,
  39. webpage, field, default=None)
  40. info.update({
  41. 'id': asset.get('AssetId') or video_id,
  42. 'display_id': display_id,
  43. 'title': title,
  44. 'description': extract('Programinfo'),
  45. 'duration': parse_duration(extract('Tid')),
  46. 'thumbnail': asset.get('AssetImageUrl'),
  47. })
  48. return info