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