umg.py 3.1 KB

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