telegraaf.py 2.9 KB

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