logo

youtube-dl

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

umg.py (3302B)


  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://graphql.universal-music.de/',
  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. formats.extend(self._extract_m3u8_formats(
  53. hls_url_template % format_id, video_id, 'mp4',
  54. 'm3u8_native', m3u8_id='hls', fatal=False))
  55. for f in video_data.get('formats', []):
  56. f_url = f.get('url')
  57. mime_type = f.get('mimeType')
  58. if not f_url or mime_type == 'application/mxf':
  59. continue
  60. fmt = {
  61. 'url': f_url,
  62. 'width': int_or_none(f.get('width')),
  63. 'height': int_or_none(f.get('height')),
  64. 'filesize': parse_filesize(f.get('fileSize')),
  65. }
  66. f_type = f.get('type')
  67. if f_type == 'Image':
  68. thumbnails.append(fmt)
  69. elif f_type == 'Video':
  70. format_id = f.get('formatId')
  71. if format_id:
  72. fmt['format_id'] = format_id
  73. if mime_type == 'video/mp4':
  74. add_m3u8_format(format_id)
  75. urlh = self._request_webpage(f_url, video_id, fatal=False)
  76. if urlh:
  77. first_byte = urlh.read(1)
  78. if first_byte not in (b'F', b'\x00'):
  79. continue
  80. formats.append(fmt)
  81. if not formats:
  82. for format_id in (867, 836, 940):
  83. add_m3u8_format(format_id)
  84. self._sort_formats(formats, ('width', 'height', 'filesize', 'tbr'))
  85. return {
  86. 'id': video_id,
  87. 'title': title,
  88. 'duration': int_or_none(video_data.get('duration')),
  89. 'timestamp': parse_iso8601(video_data.get('createdDate'), ' '),
  90. 'thumbnails': thumbnails,
  91. 'formats': formats,
  92. }