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.

121 lines
4.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class VierIE(InfoExtractor):
  6. IE_NAME = 'vier'
  7. _VALID_URL = r'https?://(?:www\.)?vier\.be/(?:[^/]+/videos/(?P<display_id>[^/]+)(?:/(?P<id>\d+))?|video/v3/embed/(?P<embed_id>\d+))'
  8. _TESTS = [{
  9. 'url': 'http://www.vier.be/planb/videos/het-wordt-warm-de-moestuin/16129',
  10. 'info_dict': {
  11. 'id': '16129',
  12. 'display_id': 'het-wordt-warm-de-moestuin',
  13. 'ext': 'mp4',
  14. 'title': 'Het wordt warm in De Moestuin',
  15. 'description': 'De vele uren werk eisen hun tol. Wim droomt van assistentie...',
  16. },
  17. 'params': {
  18. # m3u8 download
  19. 'skip_download': True,
  20. },
  21. }, {
  22. 'url': 'http://www.vier.be/planb/videos/mieren-herders-van-de-bladluizen',
  23. 'only_matching': True,
  24. }, {
  25. 'url': 'http://www.vier.be/video/v3/embed/16129',
  26. 'only_matching': True,
  27. }]
  28. def _real_extract(self, url):
  29. mobj = re.match(self._VALID_URL, url)
  30. embed_id = mobj.group('embed_id')
  31. display_id = mobj.group('display_id') or embed_id
  32. webpage = self._download_webpage(url, display_id)
  33. video_id = self._search_regex(
  34. [r'data-nid="(\d+)"', r'"nid"\s*:\s*"(\d+)"'],
  35. webpage, 'video id')
  36. application = self._search_regex(
  37. [r'data-application="([^"]+)"', r'"application"\s*:\s*"([^"]+)"'],
  38. webpage, 'application', default='vier_vod')
  39. filename = self._search_regex(
  40. [r'data-filename="([^"]+)"', r'"filename"\s*:\s*"([^"]+)"'],
  41. webpage, 'filename')
  42. playlist_url = 'http://vod.streamcloud.be/%s/mp4:_definst_/%s.mp4/playlist.m3u8' % (application, filename)
  43. formats = self._extract_m3u8_formats(playlist_url, display_id, 'mp4')
  44. title = self._og_search_title(webpage, default=display_id)
  45. description = self._og_search_description(webpage, default=None)
  46. thumbnail = self._og_search_thumbnail(webpage, default=None)
  47. return {
  48. 'id': video_id,
  49. 'display_id': display_id,
  50. 'title': title,
  51. 'description': description,
  52. 'thumbnail': thumbnail,
  53. 'formats': formats,
  54. }
  55. class VierVideosIE(InfoExtractor):
  56. IE_NAME = 'vier:videos'
  57. _VALID_URL = r'https?://(?:www\.)?vier\.be/(?P<program>[^/]+)/videos(?:\?.*\bpage=(?P<page>\d+)|$)'
  58. _TESTS = [{
  59. 'url': 'http://www.vier.be/demoestuin/videos',
  60. 'info_dict': {
  61. 'id': 'demoestuin',
  62. },
  63. 'playlist_mincount': 153,
  64. }, {
  65. 'url': 'http://www.vier.be/demoestuin/videos?page=6',
  66. 'info_dict': {
  67. 'id': 'demoestuin-page6',
  68. },
  69. 'playlist_mincount': 20,
  70. }, {
  71. 'url': 'http://www.vier.be/demoestuin/videos?page=7',
  72. 'info_dict': {
  73. 'id': 'demoestuin-page7',
  74. },
  75. 'playlist_mincount': 13,
  76. }]
  77. def _real_extract(self, url):
  78. mobj = re.match(self._VALID_URL, url)
  79. program = mobj.group('program')
  80. webpage = self._download_webpage(url, program)
  81. page_id = mobj.group('page')
  82. if page_id:
  83. page_id = int(page_id)
  84. start_page = page_id
  85. last_page = start_page + 1
  86. playlist_id = '%s-page%d' % (program, page_id)
  87. else:
  88. start_page = 0
  89. last_page = int(self._search_regex(
  90. r'videos\?page=(\d+)">laatste</a>',
  91. webpage, 'last page', default=0)) + 1
  92. playlist_id = program
  93. entries = []
  94. for current_page_id in range(start_page, last_page):
  95. current_page = self._download_webpage(
  96. 'http://www.vier.be/%s/videos?page=%d' % (program, current_page_id),
  97. program,
  98. 'Downloading page %d' % (current_page_id + 1)) if current_page_id != page_id else webpage
  99. page_entries = [
  100. self.url_result('http://www.vier.be' + video_url, 'Vier')
  101. for video_url in re.findall(
  102. r'<h3><a href="(/[^/]+/videos/[^/]+(?:/\d+)?)">', current_page)]
  103. entries.extend(page_entries)
  104. return self.playlist_result(entries, playlist_id)