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.

119 lines
4.1 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. self._sort_formats(formats)
  46. title = self._og_search_title(webpage, default=display_id)
  47. description = self._og_search_description(webpage, default=None)
  48. thumbnail = self._og_search_thumbnail(webpage, default=None)
  49. return {
  50. 'id': video_id,
  51. 'display_id': display_id,
  52. 'title': title,
  53. 'description': description,
  54. 'thumbnail': thumbnail,
  55. 'formats': formats,
  56. }
  57. class VierVideosIE(InfoExtractor):
  58. IE_NAME = 'vier:videos'
  59. _VALID_URL = r'https?://(?:www\.)?vier\.be/(?P<program>[^/]+)/videos(?:\?.*\bpage=(?P<page>\d+)|$)'
  60. _TESTS = [{
  61. 'url': 'http://www.vier.be/demoestuin/videos',
  62. 'info_dict': {
  63. 'id': 'demoestuin',
  64. },
  65. 'playlist_mincount': 153,
  66. }, {
  67. 'url': 'http://www.vier.be/demoestuin/videos?page=6',
  68. 'info_dict': {
  69. 'id': 'demoestuin-page6',
  70. },
  71. 'playlist_mincount': 20,
  72. }, {
  73. 'url': 'http://www.vier.be/demoestuin/videos?page=7',
  74. 'info_dict': {
  75. 'id': 'demoestuin-page7',
  76. },
  77. 'playlist_mincount': 13,
  78. }]
  79. def _real_extract(self, url):
  80. mobj = re.match(self._VALID_URL, url)
  81. program = mobj.group('program')
  82. page_id = mobj.group('page')
  83. if page_id:
  84. page_id = int(page_id)
  85. start_page = page_id
  86. playlist_id = '%s-page%d' % (program, page_id)
  87. else:
  88. start_page = 0
  89. playlist_id = program
  90. entries = []
  91. for current_page_id in itertools.count(start_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))
  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. if page_id or '>Meer<' not in current_page:
  102. break
  103. return self.playlist_result(entries, playlist_id)