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.

118 lines
4.1 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'"nid"\s*:\s*"(\d+)"', webpage, 'video id')
  35. application = self._search_regex(
  36. r'"application"\s*:\s*"([^"]+)"', webpage, 'application', default='vier_vod')
  37. filename = self._search_regex(
  38. r'"filename"\s*:\s*"([^"]+)"', webpage, 'filename')
  39. playlist_url = 'http://vod.streamcloud.be/%s/mp4:_definst_/%s.mp4/playlist.m3u8' % (application, filename)
  40. formats = self._extract_m3u8_formats(playlist_url, display_id, 'mp4')
  41. title = self._og_search_title(webpage, default=display_id)
  42. description = self._og_search_description(webpage, default=None)
  43. thumbnail = self._og_search_thumbnail(webpage, default=None)
  44. return {
  45. 'id': video_id,
  46. 'display_id': display_id,
  47. 'title': title,
  48. 'description': description,
  49. 'thumbnail': thumbnail,
  50. 'formats': formats,
  51. }
  52. class VierVideosIE(InfoExtractor):
  53. IE_NAME = 'vier:videos'
  54. _VALID_URL = r'https?://(?:www\.)?vier\.be/(?P<program>[^/]+)/videos(?:\?.*\bpage=(?P<page>\d+)|$)'
  55. _TESTS = [{
  56. 'url': 'http://www.vier.be/demoestuin/videos',
  57. 'info_dict': {
  58. 'id': 'demoestuin',
  59. },
  60. 'playlist_mincount': 153,
  61. }, {
  62. 'url': 'http://www.vier.be/demoestuin/videos?page=6',
  63. 'info_dict': {
  64. 'id': 'demoestuin-page6',
  65. },
  66. 'playlist_mincount': 20,
  67. }, {
  68. 'url': 'http://www.vier.be/demoestuin/videos?page=7',
  69. 'info_dict': {
  70. 'id': 'demoestuin-page7',
  71. },
  72. 'playlist_mincount': 13,
  73. }]
  74. def _real_extract(self, url):
  75. mobj = re.match(self._VALID_URL, url)
  76. program = mobj.group('program')
  77. webpage = self._download_webpage(url, program)
  78. page_id = mobj.group('page')
  79. if page_id:
  80. page_id = int(page_id)
  81. start_page = page_id
  82. last_page = start_page + 1
  83. playlist_id = '%s-page%d' % (program, page_id)
  84. else:
  85. start_page = 0
  86. last_page = int(self._search_regex(
  87. r'videos\?page=(\d+)">laatste</a>',
  88. webpage, 'last page', default=0)) + 1
  89. playlist_id = program
  90. entries = []
  91. for current_page_id in range(start_page, last_page):
  92. current_page = self._download_webpage(
  93. 'http://www.vier.be/%s/videos?page=%d' % (program, current_page_id),
  94. program,
  95. 'Downloading page %d' % (current_page_id + 1)) if current_page_id != page_id else webpage
  96. page_entries = [
  97. self.url_result('http://www.vier.be' + video_url, 'Vier')
  98. for video_url in re.findall(
  99. r'<h3><a href="(/[^/]+/videos/[^/]+(?:/\d+)?)">', current_page)]
  100. entries.extend(page_entries)
  101. return self.playlist_result(entries, playlist_id)