You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
5.0 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. parse_iso8601,
  8. )
  9. class DRBonanzaIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?dr\.dk/bonanza/(?:[^/]+/)+(?:[^/])+?(?:assetId=(?P<id>\d+))?(?:[#&]|$)'
  11. _TESTS = [{
  12. 'url': 'http://www.dr.dk/bonanza/serie/portraetter/Talkshowet.htm?assetId=65517',
  13. 'info_dict': {
  14. 'id': '65517',
  15. 'ext': 'mp4',
  16. 'title': 'Talkshowet - Leonard Cohen',
  17. 'description': 'md5:8f34194fb30cd8c8a30ad8b27b70c0ca',
  18. 'thumbnail': 're:^https?://.*\.(?:gif|jpg)$',
  19. 'timestamp': 1295537932,
  20. 'upload_date': '20110120',
  21. 'duration': 3664,
  22. },
  23. 'params': {
  24. 'skip_download': True, # requires rtmp
  25. },
  26. }, {
  27. 'url': 'http://www.dr.dk/bonanza/radio/serie/sport/fodbold.htm?assetId=59410',
  28. 'md5': '6dfe039417e76795fb783c52da3de11d',
  29. 'info_dict': {
  30. 'id': '59410',
  31. 'ext': 'mp3',
  32. 'title': 'EM fodbold 1992 Danmark - Tyskland finale Transmission',
  33. 'description': 'md5:501e5a195749480552e214fbbed16c4e',
  34. 'thumbnail': 're:^https?://.*\.(?:gif|jpg)$',
  35. 'timestamp': 1223274900,
  36. 'upload_date': '20081006',
  37. 'duration': 7369,
  38. },
  39. }]
  40. def _real_extract(self, url):
  41. url_id = self._match_id(url)
  42. webpage = self._download_webpage(url, url_id)
  43. if url_id:
  44. info = json.loads(self._html_search_regex(r'({.*?%s.*})' % url_id, webpage, 'json'))
  45. else:
  46. # Just fetch the first video on that page
  47. info = json.loads(self._html_search_regex(r'bonanzaFunctions.newPlaylist\(({.*})\)', webpage, 'json'))
  48. asset_id = str(info['AssetId'])
  49. title = info['Title'].rstrip(' \'\"-,.:;!?')
  50. duration = int_or_none(info.get('Duration'), scale=1000)
  51. # First published online. "FirstPublished" contains the date for original airing.
  52. timestamp = parse_iso8601(
  53. re.sub(r'\.\d+$', '', info['Created']))
  54. def parse_filename_info(url):
  55. match = re.search(r'/\d+_(?P<width>\d+)x(?P<height>\d+)x(?P<bitrate>\d+)K\.(?P<ext>\w+)$', url)
  56. if match:
  57. return {
  58. 'width': int(match.group('width')),
  59. 'height': int(match.group('height')),
  60. 'vbr': int(match.group('bitrate')),
  61. 'ext': match.group('ext')
  62. }
  63. match = re.search(r'/\d+_(?P<bitrate>\d+)K\.(?P<ext>\w+)$', url)
  64. if match:
  65. return {
  66. 'vbr': int(match.group('bitrate')),
  67. 'ext': match.group(2)
  68. }
  69. return {}
  70. video_types = ['VideoHigh', 'VideoMid', 'VideoLow']
  71. preferencemap = {
  72. 'VideoHigh': -1,
  73. 'VideoMid': -2,
  74. 'VideoLow': -3,
  75. 'Audio': -4,
  76. }
  77. formats = []
  78. for file in info['Files']:
  79. if info['Type'] == "Video":
  80. if file['Type'] in video_types:
  81. format = parse_filename_info(file['Location'])
  82. format.update({
  83. 'url': file['Location'],
  84. 'format_id': file['Type'].replace('Video', ''),
  85. 'preference': preferencemap.get(file['Type'], -10),
  86. })
  87. if format['url'].startswith('rtmp'):
  88. rtmp_url = format['url']
  89. format['rtmp_live'] = True # --resume does not work
  90. if '/bonanza/' in rtmp_url:
  91. format['play_path'] = rtmp_url.split('/bonanza/')[1]
  92. formats.append(format)
  93. elif file['Type'] == "Thumb":
  94. thumbnail = file['Location']
  95. elif info['Type'] == "Audio":
  96. if file['Type'] == "Audio":
  97. format = parse_filename_info(file['Location'])
  98. format.update({
  99. 'url': file['Location'],
  100. 'format_id': file['Type'],
  101. 'vcodec': 'none',
  102. })
  103. formats.append(format)
  104. elif file['Type'] == "Thumb":
  105. thumbnail = file['Location']
  106. description = '%s\n%s\n%s\n' % (
  107. info['Description'], info['Actors'], info['Colophon'])
  108. self._sort_formats(formats)
  109. display_id = re.sub(r'[^\w\d-]', '', re.sub(r' ', '-', title.lower())) + '-' + asset_id
  110. display_id = re.sub(r'-+', '-', display_id)
  111. return {
  112. 'id': asset_id,
  113. 'display_id': display_id,
  114. 'title': title,
  115. 'formats': formats,
  116. 'description': description,
  117. 'thumbnail': thumbnail,
  118. 'timestamp': timestamp,
  119. 'duration': duration,
  120. }