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.

78 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', fatal=False))
  44. elif ext == 'mpd':
  45. formats.extend(self._extract_mpd_formats(
  46. manifest_url, video_id, mpd_id='dash', fatal=False))
  47. else:
  48. self.report_warning('Unknown adaptive format %s' % ext)
  49. for location in locations.get('progressive', []):
  50. formats.append({
  51. 'url': location['sources'][0]['src'],
  52. 'width': location.get('width'),
  53. 'height': location.get('height'),
  54. 'format_id': 'http-%s' % location['label'],
  55. })
  56. self._sort_formats(formats)
  57. title = remove_end(self._og_search_title(webpage), ' - VIDEO')
  58. description = self._og_search_description(webpage)
  59. duration = item.get('duration')
  60. thumbnail = item.get('poster')
  61. return {
  62. 'id': video_id,
  63. 'title': title,
  64. 'description': description,
  65. 'formats': formats,
  66. 'duration': duration,
  67. 'thumbnail': thumbnail,
  68. }