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.

79 lines
2.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. remove_end,
  7. )
  8. class TelegraafIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?telegraaf\.nl/tv/(?:[^/]+/)+(?P<id>\d+)/[^/]+\.html'
  10. _TEST = {
  11. 'url': 'http://www.telegraaf.nl/tv/nieuws/binnenland/24353229/__Tikibad_ontruimd_wegens_brand__.html',
  12. 'info_dict': {
  13. 'id': '24353229',
  14. 'ext': 'mp4',
  15. 'title': 'Tikibad ontruimd wegens brand',
  16. 'description': 'md5:05ca046ff47b931f9b04855015e163a4',
  17. 'thumbnail': 're:^https?://.*\.jpg$',
  18. 'duration': 33,
  19. },
  20. 'params': {
  21. # m3u8 download
  22. 'skip_download': True,
  23. },
  24. }
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id)
  28. player_url = self._html_search_regex(
  29. r'<iframe[^>]+src="([^"]+")', webpage, 'player URL')
  30. player_page = self._download_webpage(
  31. player_url, video_id, note='Download player webpage')
  32. playlist_url = self._search_regex(
  33. r'playlist\s*:\s*"([^"]+)"', player_page, 'playlist URL')
  34. playlist_data = self._download_json(playlist_url, video_id)
  35. item = playlist_data['items'][0]
  36. formats = []
  37. locations = item['locations']
  38. for location in locations.get('adaptive', []):
  39. manifest_url = location['src']
  40. ext = determine_ext(manifest_url)
  41. if ext == 'm3u8':
  42. formats.extend(self._extract_m3u8_formats(
  43. manifest_url, video_id, ext='mp4', m3u8_id='hls'))
  44. elif ext == 'mpd':
  45. # TODO: Current DASH formats are broken - $Time$ pattern in
  46. # <SegmentTemplate> not implemented yet
  47. continue
  48. else:
  49. self.report_warning('Unknown adaptive format %s' % ext)
  50. for location in locations.get('progressive', []):
  51. formats.append({
  52. 'url': location['sources'][0]['src'],
  53. 'width': location.get('width'),
  54. 'height': location.get('height'),
  55. 'format_id': 'http-%s' % location['label'],
  56. })
  57. self._sort_formats(formats)
  58. title = remove_end(self._og_search_title(webpage), ' - VIDEO')
  59. description = self._og_search_description(webpage)
  60. duration = item.get('duration')
  61. thumbnail = item.get('poster')
  62. return {
  63. 'id': video_id,
  64. 'title': title,
  65. 'description': description,
  66. 'formats': formats,
  67. 'duration': duration,
  68. 'thumbnail': thumbnail,
  69. }