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.

153 lines
5.7 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. float_or_none,
  7. )
  8. class VRTIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:deredactie|sporza|cobra(?:\.canvas)?)\.be/cm/(?:[^/]+/)+(?P<id>[^/]+)/*'
  10. _TESTS = [
  11. # deredactie.be
  12. {
  13. 'url': 'http://deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/EP_141025_JOL',
  14. 'md5': '4cebde1eb60a53782d4f3992cbd46ec8',
  15. 'info_dict': {
  16. 'id': '2129880',
  17. 'ext': 'flv',
  18. 'title': 'Het journaal L - 25/10/14',
  19. 'description': None,
  20. 'timestamp': 1414271750.949,
  21. 'upload_date': '20141025',
  22. 'duration': 929,
  23. },
  24. 'skip': 'HTTP Error 404: Not Found',
  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. 'skip': 'HTTP Error 404: Not Found',
  40. },
  41. # cobra.be
  42. {
  43. 'url': 'http://cobra.be/cm/cobra/videozone/rubriek/film-videozone/141022-mv-ellis-cafecorsari',
  44. 'md5': '78a2b060a5083c4f055449a72477409d',
  45. 'info_dict': {
  46. 'id': '2126050',
  47. 'ext': 'flv',
  48. 'title': 'Bret Easton Ellis in Café Corsari',
  49. 'description': 'md5:f699986e823f32fd6036c1855a724ee9',
  50. 'timestamp': 1413967500.494,
  51. 'upload_date': '20141022',
  52. 'duration': 661,
  53. },
  54. 'skip': 'HTTP Error 404: Not Found',
  55. },
  56. {
  57. # YouTube video
  58. 'url': 'http://deredactie.be/cm/vrtnieuws/videozone/nieuws/cultuurenmedia/1.2622957',
  59. 'md5': 'b8b93da1df1cea6c8556255a796b7d61',
  60. 'info_dict': {
  61. 'id': 'Wji-BZ0oCwg',
  62. 'ext': 'mp4',
  63. 'title': 'ROGUE ONE: A STAR WARS STORY Official Teaser Trailer',
  64. 'description': 'md5:8e468944dce15567a786a67f74262583',
  65. 'uploader': 'Star Wars',
  66. 'uploader_id': 'starwars',
  67. 'upload_date': '20160407',
  68. },
  69. 'add_ie': ['Youtube'],
  70. },
  71. {
  72. 'url': 'http://cobra.canvas.be/cm/cobra/videozone/rubriek/film-videozone/1.2377055',
  73. 'info_dict': {
  74. 'id': '2377055',
  75. 'ext': 'mp4',
  76. 'title': 'Cafe Derby',
  77. 'description': 'Lenny Van Wesemael debuteert met de langspeelfilm Café Derby. Een waar gebeurd maar ook verzonnen verhaal.',
  78. 'upload_date': '20150626',
  79. 'timestamp': 1435305240.769,
  80. },
  81. 'params': {
  82. # m3u8 download
  83. 'skip_download': True,
  84. }
  85. }
  86. ]
  87. def _real_extract(self, url):
  88. video_id = self._match_id(url)
  89. webpage = self._download_webpage(url, video_id)
  90. video_id = self._search_regex(
  91. r'data-video-id="([^"]+)_[^"]+"', webpage, 'video id', fatal=False)
  92. src = self._search_regex(
  93. r'data-video-src="([^"]+)"', webpage, 'video src', default=None)
  94. video_type = self._search_regex(
  95. r'data-video-type="([^"]+)"', webpage, 'video type', default=None)
  96. if video_type == 'YouTubeVideo':
  97. return self.url_result(src, 'Youtube')
  98. formats = []
  99. mobj = re.search(
  100. r'data-video-iphone-server="(?P<server>[^"]+)"\s+data-video-iphone-path="(?P<path>[^"]+)"',
  101. webpage)
  102. if mobj:
  103. formats.extend(self._extract_m3u8_formats(
  104. '%s/%s' % (mobj.group('server'), mobj.group('path')),
  105. video_id, 'mp4', m3u8_id='hls', fatal=False))
  106. if src:
  107. formats = self._extract_wowza_formats(src, video_id)
  108. if 'data-video-geoblocking="true"' not in webpage:
  109. for f in formats:
  110. if f['url'].startswith('rtsp://'):
  111. http_format = f.copy()
  112. http_format.update({
  113. 'url': f['url'].replace('rtsp://', 'http://').replace('vod.', 'download.').replace('/_definst_/', '/').replace('mp4:', ''),
  114. 'format_id': f['format_id'].replace('rtsp', 'http'),
  115. 'protocol': 'http',
  116. })
  117. formats.append(http_format)
  118. if not formats and 'data-video-geoblocking="true"' in webpage:
  119. self.raise_geo_restricted('This video is only available in Belgium')
  120. self._sort_formats(formats)
  121. title = self._og_search_title(webpage)
  122. description = self._og_search_description(webpage, default=None)
  123. thumbnail = self._og_search_thumbnail(webpage)
  124. timestamp = float_or_none(self._search_regex(
  125. r'data-video-sitestat-pubdate="(\d+)"', webpage, 'timestamp', fatal=False), 1000)
  126. duration = float_or_none(self._search_regex(
  127. r'data-video-duration="(\d+)"', webpage, 'duration', fatal=False), 1000)
  128. return {
  129. 'id': video_id,
  130. 'title': title,
  131. 'description': description,
  132. 'thumbnail': thumbnail,
  133. 'timestamp': timestamp,
  134. 'duration': duration,
  135. 'formats': formats,
  136. }