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.0 KiB

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