logo

youtube-dl

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

telegraaf.py (3086B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. int_or_none,
  7. parse_iso8601,
  8. try_get,
  9. )
  10. class TelegraafIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?telegraaf\.nl/video/(?P<id>\d+)'
  12. _TEST = {
  13. 'url': 'https://www.telegraaf.nl/video/734366489/historisch-scheepswrak-slaat-na-100-jaar-los',
  14. 'info_dict': {
  15. 'id': 'gaMItuoSeUg2',
  16. 'ext': 'mp4',
  17. 'title': 'Historisch scheepswrak slaat na 100 jaar los',
  18. 'description': 'md5:6f53b7c4f55596722ac24d6c0ec00cfb',
  19. 'thumbnail': r're:^https?://.*\.jpg',
  20. 'duration': 55,
  21. 'timestamp': 1572805527,
  22. 'upload_date': '20191103',
  23. },
  24. 'params': {
  25. # m3u8 download
  26. 'skip_download': True,
  27. },
  28. }
  29. def _real_extract(self, url):
  30. article_id = self._match_id(url)
  31. video_id = self._download_json(
  32. 'https://app.telegraaf.nl/graphql', article_id,
  33. headers={'User-Agent': 'De Telegraaf/6.8.11 (Android 11; en_US)'},
  34. query={
  35. 'query': '''{
  36. article(uid: %s) {
  37. videos {
  38. videoId
  39. }
  40. }
  41. }''' % article_id,
  42. })['data']['article']['videos'][0]['videoId']
  43. item = self._download_json(
  44. 'https://content.tmgvideo.nl/playlist/item=%s/playlist.json' % video_id,
  45. video_id)['items'][0]
  46. title = item['title']
  47. formats = []
  48. locations = item.get('locations') or {}
  49. for location in locations.get('adaptive', []):
  50. manifest_url = location.get('src')
  51. if not manifest_url:
  52. continue
  53. ext = determine_ext(manifest_url)
  54. if ext == 'm3u8':
  55. formats.extend(self._extract_m3u8_formats(
  56. manifest_url, video_id, ext='mp4', m3u8_id='hls', fatal=False))
  57. elif ext == 'mpd':
  58. formats.extend(self._extract_mpd_formats(
  59. manifest_url, video_id, mpd_id='dash', fatal=False))
  60. else:
  61. self.report_warning('Unknown adaptive format %s' % ext)
  62. for location in locations.get('progressive', []):
  63. src = try_get(location, lambda x: x['sources'][0]['src'])
  64. if not src:
  65. continue
  66. label = location.get('label')
  67. formats.append({
  68. 'url': src,
  69. 'width': int_or_none(location.get('width')),
  70. 'height': int_or_none(location.get('height')),
  71. 'format_id': 'http' + ('-%s' % label if label else ''),
  72. })
  73. self._sort_formats(formats)
  74. return {
  75. 'id': video_id,
  76. 'title': title,
  77. 'description': item.get('description'),
  78. 'formats': formats,
  79. 'duration': int_or_none(item.get('duration')),
  80. 'thumbnail': item.get('poster'),
  81. 'timestamp': parse_iso8601(item.get('datecreated'), ' '),
  82. }