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.

177 lines
7.1 KiB

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. 'skip': 'HTTP Error 404: Not Found',
  26. },
  27. # sporza.be
  28. {
  29. 'url': 'http://sporza.be/cm/sporza/videozone/programmas/extratime/EP_141020_Extra_time',
  30. 'md5': '11f53088da9bf8e7cfc42456697953ff',
  31. 'info_dict': {
  32. 'id': '2124639',
  33. 'ext': 'flv',
  34. 'title': 'Bekijk Extra Time van 20 oktober',
  35. 'description': 'md5:83ac5415a4f1816c6a93f8138aef2426',
  36. 'timestamp': 1413835980.560,
  37. 'upload_date': '20141020',
  38. 'duration': 3238,
  39. },
  40. 'skip': 'HTTP Error 404: Not Found',
  41. },
  42. # cobra.be
  43. {
  44. 'url': 'http://cobra.be/cm/cobra/videozone/rubriek/film-videozone/141022-mv-ellis-cafecorsari',
  45. 'md5': '78a2b060a5083c4f055449a72477409d',
  46. 'info_dict': {
  47. 'id': '2126050',
  48. 'ext': 'flv',
  49. 'title': 'Bret Easton Ellis in Café Corsari',
  50. 'description': 'md5:f699986e823f32fd6036c1855a724ee9',
  51. 'timestamp': 1413967500.494,
  52. 'upload_date': '20141022',
  53. 'duration': 661,
  54. },
  55. 'skip': 'HTTP Error 404: Not Found',
  56. },
  57. {
  58. # YouTube video
  59. 'url': 'http://deredactie.be/cm/vrtnieuws/videozone/nieuws/cultuurenmedia/1.2622957',
  60. 'md5': 'b8b93da1df1cea6c8556255a796b7d61',
  61. 'info_dict': {
  62. 'id': 'Wji-BZ0oCwg',
  63. 'ext': 'mp4',
  64. 'title': 'ROGUE ONE: A STAR WARS STORY Official Teaser Trailer',
  65. 'description': 'md5:8e468944dce15567a786a67f74262583',
  66. 'uploader': 'Star Wars',
  67. 'uploader_id': 'starwars',
  68. 'upload_date': '20160407',
  69. },
  70. 'add_ie': ['Youtube'],
  71. },
  72. {
  73. 'url': 'http://cobra.canvas.be/cm/cobra/videozone/rubriek/film-videozone/1.2377055',
  74. 'md5': '',
  75. 'info_dict': {
  76. 'id': '2377055',
  77. 'ext': 'mp4',
  78. 'title': 'Cafe Derby',
  79. 'description': 'Lenny Van Wesemael debuteert met de langspeelfilm Café Derby. Een waar gebeurd maar ook verzonnen verhaal.',
  80. 'upload_date': '20150626',
  81. 'timestamp': 1435305240.769,
  82. },
  83. 'params': {
  84. # m3u8 download
  85. 'skip_download': True,
  86. }
  87. }
  88. ]
  89. def _real_extract(self, url):
  90. video_id = self._match_id(url)
  91. webpage = self._download_webpage(url, video_id)
  92. video_id = self._search_regex(
  93. r'data-video-id="([^"]+)_[^"]+"', webpage, 'video id', fatal=False)
  94. src = self._search_regex(
  95. r'data-video-src="([^"]+)"', webpage, 'video src', default=None)
  96. video_type = self._search_regex(
  97. r'data-video-type="([^"]+)"', webpage, 'video type', default=None)
  98. if video_type == 'YouTubeVideo':
  99. return self.url_result(src, 'Youtube')
  100. formats = []
  101. mobj = re.search(
  102. r'data-video-iphone-server="(?P<server>[^"]+)"\s+data-video-iphone-path="(?P<path>[^"]+)"',
  103. webpage)
  104. if mobj:
  105. formats.extend(self._extract_m3u8_formats(
  106. '%s/%s' % (mobj.group('server'), mobj.group('path')),
  107. video_id, 'mp4', m3u8_id='hls', fatal=False))
  108. if src:
  109. if determine_ext(src) == 'm3u8':
  110. formats.extend(self._extract_m3u8_formats(
  111. src, video_id, 'mp4', entry_protocol='m3u8_native',
  112. m3u8_id='hls', fatal=False))
  113. formats.extend(self._extract_f4m_formats(
  114. src.replace('playlist.m3u8', 'manifest.f4m'),
  115. video_id, f4m_id='hds', fatal=False))
  116. if 'data-video-geoblocking="true"' not in webpage:
  117. rtmp_formats = self._extract_smil_formats(
  118. src.replace('playlist.m3u8', 'jwplayer.smil'),
  119. video_id, fatal=False)
  120. formats.extend(rtmp_formats)
  121. for rtmp_format in rtmp_formats:
  122. rtmp_format_c = rtmp_format.copy()
  123. rtmp_format_c['url'] = '%s/%s' % (rtmp_format['url'], rtmp_format['play_path'])
  124. del rtmp_format_c['play_path']
  125. del rtmp_format_c['ext']
  126. http_format = rtmp_format_c.copy()
  127. http_format.update({
  128. 'url': rtmp_format_c['url'].replace('rtmp://', 'http://').replace('vod.', 'download.').replace('/_definst_/', '/').replace('mp4:', ''),
  129. 'format_id': rtmp_format['format_id'].replace('rtmp', 'http'),
  130. 'protocol': 'http',
  131. })
  132. rtsp_format = rtmp_format_c.copy()
  133. rtsp_format.update({
  134. 'url': rtsp_format['url'].replace('rtmp://', 'rtsp://'),
  135. 'format_id': rtmp_format['format_id'].replace('rtmp', 'rtsp'),
  136. 'protocol': 'rtsp',
  137. })
  138. formats.extend([http_format, rtsp_format])
  139. else:
  140. formats.extend(self._extract_f4m_formats(
  141. '%s/manifest.f4m' % src, video_id, f4m_id='hds', fatal=False))
  142. if not formats and 'data-video-geoblocking="true"' in webpage:
  143. self.raise_geo_restricted('This video is only available in Belgium')
  144. self._sort_formats(formats)
  145. title = self._og_search_title(webpage)
  146. description = self._og_search_description(webpage, default=None)
  147. thumbnail = self._og_search_thumbnail(webpage)
  148. timestamp = float_or_none(self._search_regex(
  149. r'data-video-sitestat-pubdate="(\d+)"', webpage, 'timestamp', fatal=False), 1000)
  150. duration = float_or_none(self._search_regex(
  151. r'data-video-duration="(\d+)"', webpage, 'duration', fatal=False), 1000)
  152. return {
  153. 'id': video_id,
  154. 'title': title,
  155. 'description': description,
  156. 'thumbnail': thumbnail,
  157. 'timestamp': timestamp,
  158. 'duration': duration,
  159. 'formats': formats,
  160. }