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.

103 lines
3.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. parse_filesize,
  7. parse_iso8601,
  8. )
  9. class UMGDeIE(InfoExtractor):
  10. IE_NAME = 'umg:de'
  11. IE_DESC = 'Universal Music Deutschland'
  12. _VALID_URL = r'https?://(?:www\.)?universal-music\.de/[^/]+/videos/[^/?#]+-(?P<id>\d+)'
  13. _TEST = {
  14. 'url': 'https://www.universal-music.de/sido/videos/jedes-wort-ist-gold-wert-457803',
  15. 'md5': 'ebd90f48c80dcc82f77251eb1902634f',
  16. 'info_dict': {
  17. 'id': '457803',
  18. 'ext': 'mp4',
  19. 'title': 'Jedes Wort ist Gold wert',
  20. 'timestamp': 1513591800,
  21. 'upload_date': '20171218',
  22. }
  23. }
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. video_data = self._download_json(
  27. 'https://api.universal-music.de/graphql',
  28. video_id, query={
  29. 'query': '''{
  30. universalMusic(channel:16) {
  31. video(id:%s) {
  32. headline
  33. formats {
  34. formatId
  35. url
  36. type
  37. width
  38. height
  39. mimeType
  40. fileSize
  41. }
  42. duration
  43. createdDate
  44. }
  45. }
  46. }''' % video_id})['data']['universalMusic']['video']
  47. title = video_data['headline']
  48. hls_url_template = 'http://mediadelivery.universal-music-services.de/vod/mp4:autofill/storage/' + '/'.join(list(video_id)) + '/content/%s/file/playlist.m3u8'
  49. thumbnails = []
  50. formats = []
  51. def add_m3u8_format(format_id):
  52. m3u8_formats = self._extract_m3u8_formats(
  53. hls_url_template % format_id, video_id, 'mp4',
  54. 'm3u8_native', m3u8_id='hls', fatal='False')
  55. if m3u8_formats and m3u8_formats[0].get('height'):
  56. formats.extend(m3u8_formats)
  57. for f in video_data.get('formats', []):
  58. f_url = f.get('url')
  59. mime_type = f.get('mimeType')
  60. if not f_url or mime_type == 'application/mxf':
  61. continue
  62. fmt = {
  63. 'url': f_url,
  64. 'width': int_or_none(f.get('width')),
  65. 'height': int_or_none(f.get('height')),
  66. 'filesize': parse_filesize(f.get('fileSize')),
  67. }
  68. f_type = f.get('type')
  69. if f_type == 'Image':
  70. thumbnails.append(fmt)
  71. elif f_type == 'Video':
  72. format_id = f.get('formatId')
  73. if format_id:
  74. fmt['format_id'] = format_id
  75. if mime_type == 'video/mp4':
  76. add_m3u8_format(format_id)
  77. urlh = self._request_webpage(f_url, video_id, fatal=False)
  78. if urlh:
  79. first_byte = urlh.read(1)
  80. if first_byte not in (b'F', b'\x00'):
  81. continue
  82. formats.append(fmt)
  83. if not formats:
  84. for format_id in (867, 836, 940):
  85. add_m3u8_format(format_id)
  86. self._sort_formats(formats, ('width', 'height', 'filesize', 'tbr'))
  87. return {
  88. 'id': video_id,
  89. 'title': title,
  90. 'duration': int_or_none(video_data.get('duration')),
  91. 'timestamp': parse_iso8601(video_data.get('createdDate'), ' '),
  92. 'thumbnails': thumbnails,
  93. 'formats': formats,
  94. }