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.

126 lines
4.4 KiB

10 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. float_or_none,
  8. )
  9. class VRTIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:deredactie|sporza|cobra(?:\.canvas)?)\.be/cm/(?:[^/]+/)+(?P<id>[^/]+)/*'
  11. _TESTS = [
  12. # deredactie.be
  13. {
  14. 'url': 'http://deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/EP_141025_JOL',
  15. 'md5': '4cebde1eb60a53782d4f3992cbd46ec8',
  16. 'info_dict': {
  17. 'id': '2129880',
  18. 'ext': 'flv',
  19. 'title': 'Het journaal L - 25/10/14',
  20. 'description': None,
  21. 'timestamp': 1414271750.949,
  22. 'upload_date': '20141025',
  23. 'duration': 929,
  24. }
  25. },
  26. # sporza.be
  27. {
  28. 'url': 'http://sporza.be/cm/sporza/videozone/programmas/extratime/EP_141020_Extra_time',
  29. 'md5': '11f53088da9bf8e7cfc42456697953ff',
  30. 'info_dict': {
  31. 'id': '2124639',
  32. 'ext': 'flv',
  33. 'title': 'Bekijk Extra Time van 20 oktober',
  34. 'description': 'md5:83ac5415a4f1816c6a93f8138aef2426',
  35. 'timestamp': 1413835980.560,
  36. 'upload_date': '20141020',
  37. 'duration': 3238,
  38. }
  39. },
  40. # cobra.be
  41. {
  42. 'url': 'http://cobra.be/cm/cobra/videozone/rubriek/film-videozone/141022-mv-ellis-cafecorsari',
  43. 'md5': '78a2b060a5083c4f055449a72477409d',
  44. 'info_dict': {
  45. 'id': '2126050',
  46. 'ext': 'flv',
  47. 'title': 'Bret Easton Ellis in Café Corsari',
  48. 'description': 'md5:f699986e823f32fd6036c1855a724ee9',
  49. 'timestamp': 1413967500.494,
  50. 'upload_date': '20141022',
  51. 'duration': 661,
  52. }
  53. },
  54. {
  55. # YouTube video
  56. 'url': 'http://deredactie.be/cm/vrtnieuws/videozone/nieuws/cultuurenmedia/1.2622957',
  57. 'only_matching': True,
  58. },
  59. {
  60. 'url': 'http://cobra.canvas.be/cm/cobra/videozone/rubriek/film-videozone/1.2377055',
  61. 'only_matching': True,
  62. }
  63. ]
  64. def _real_extract(self, url):
  65. video_id = self._match_id(url)
  66. webpage = self._download_webpage(url, video_id)
  67. video_id = self._search_regex(
  68. r'data-video-id="([^"]+)_[^"]+"', webpage, 'video id', fatal=False)
  69. src = self._search_regex(
  70. r'data-video-src="([^"]+)"', webpage, 'video src', default=None)
  71. video_type = self._search_regex(
  72. r'data-video-type="([^"]+)"', webpage, 'video type', default=None)
  73. if video_type == 'YouTubeVideo':
  74. return self.url_result(src, 'Youtube')
  75. formats = []
  76. mobj = re.search(
  77. r'data-video-iphone-server="(?P<server>[^"]+)"\s+data-video-iphone-path="(?P<path>[^"]+)"',
  78. webpage)
  79. if mobj:
  80. formats.extend(self._extract_m3u8_formats(
  81. '%s/%s' % (mobj.group('server'), mobj.group('path')),
  82. video_id, 'mp4', m3u8_id='hls', fatal=False))
  83. if src:
  84. if determine_ext(src) == 'm3u8':
  85. formats.extend(self._extract_m3u8_formats(
  86. src, video_id, 'mp4', entry_protocol='m3u8_native',
  87. m3u8_id='hls', fatal=False))
  88. else:
  89. formats.extend(self._extract_f4m_formats(
  90. '%s/manifest.f4m' % src, video_id, f4m_id='hds', fatal=False))
  91. if not formats and 'data-video-geoblocking="true"' in webpage:
  92. self.raise_geo_restricted('This video is only available in Belgium')
  93. self._sort_formats(formats)
  94. title = self._og_search_title(webpage)
  95. description = self._og_search_description(webpage, default=None)
  96. thumbnail = self._og_search_thumbnail(webpage)
  97. timestamp = float_or_none(self._search_regex(
  98. r'data-video-sitestat-pubdate="(\d+)"', webpage, 'timestamp', fatal=False), 1000)
  99. duration = float_or_none(self._search_regex(
  100. r'data-video-duration="(\d+)"', webpage, 'duration', fatal=False), 1000)
  101. return {
  102. 'id': video_id,
  103. 'title': title,
  104. 'description': description,
  105. 'thumbnail': thumbnail,
  106. 'timestamp': timestamp,
  107. 'duration': duration,
  108. 'formats': formats,
  109. }