You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.9 KiB

  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://www.telegraaf.nl/graphql', article_id, query={
  33. 'query': '''{
  34. article(uid: %s) {
  35. videos {
  36. videoId
  37. }
  38. }
  39. }''' % article_id,
  40. })['data']['article']['videos'][0]['videoId']
  41. item = self._download_json(
  42. 'https://content.tmgvideo.nl/playlist/item=%s/playlist.json' % video_id,
  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('Unknown adaptive format %s' % 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' + ('-%s' % label if label else ''),
  70. })
  71. self._sort_formats(formats)
  72. return {
  73. 'id': video_id,
  74. 'title': title,
  75. 'description': item.get('description'),
  76. 'formats': formats,
  77. 'duration': int_or_none(item.get('duration')),
  78. 'thumbnail': item.get('poster'),
  79. 'timestamp': parse_iso8601(item.get('datecreated'), ' '),
  80. }