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.

235 lines
8.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import itertools
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. urlencode_postdata,
  8. int_or_none,
  9. unified_strdate,
  10. )
  11. class VierIE(InfoExtractor):
  12. IE_NAME = 'vier'
  13. IE_DESC = 'vier.be and vijf.be'
  14. _VALID_URL = r'https?://(?:www\.)?(?P<site>vier|vijf)\.be/(?:[^/]+/videos/(?P<display_id>[^/]+)(?:/(?P<id>\d+))?|video/v3/embed/(?P<embed_id>\d+))'
  15. _NETRC_MACHINE = 'vier'
  16. _TESTS = [{
  17. 'url': 'http://www.vier.be/planb/videos/het-wordt-warm-de-moestuin/16129',
  18. 'md5': 'e4ae2054a6b040ef1e289e20d111b46e',
  19. 'info_dict': {
  20. 'id': '16129',
  21. 'display_id': 'het-wordt-warm-de-moestuin',
  22. 'ext': 'mp4',
  23. 'title': 'Het wordt warm in De Moestuin',
  24. 'description': 'De vele uren werk eisen hun tol. Wim droomt van assistentie...',
  25. 'upload_date': '20121025',
  26. 'series': 'Plan B',
  27. 'tags': ['De Moestuin', 'Moestuin', 'meisjes', 'Tomaat', 'Wim', 'Droom'],
  28. },
  29. }, {
  30. 'url': 'http://www.vijf.be/temptationisland/videos/zo-grappig-temptation-island-hosts-moeten-kiezen-tussen-onmogelijke-dilemmas/2561614',
  31. 'info_dict': {
  32. 'id': '2561614',
  33. 'display_id': 'zo-grappig-temptation-island-hosts-moeten-kiezen-tussen-onmogelijke-dilemmas',
  34. 'ext': 'mp4',
  35. 'title': 'md5:84f45fe48b8c1fa296a7f6d208d080a7',
  36. 'description': 'md5:0356d4981e58b8cbee19355cbd51a8fe',
  37. 'upload_date': '20170228',
  38. 'series': 'Temptation Island',
  39. 'tags': list,
  40. },
  41. 'params': {
  42. 'skip_download': True,
  43. },
  44. }, {
  45. 'url': 'http://www.vier.be/janigaat/videos/jani-gaat-naar-tokio-aflevering-4/2674839',
  46. 'info_dict': {
  47. 'id': '2674839',
  48. 'display_id': 'jani-gaat-naar-tokio-aflevering-4',
  49. 'ext': 'mp4',
  50. 'title': 'Jani gaat naar Tokio - Aflevering 4',
  51. 'description': 'md5:aa8d611541db6ae9e863125704511f88',
  52. 'upload_date': '20170501',
  53. 'series': 'Jani gaat',
  54. 'episode_number': 4,
  55. 'tags': ['Jani Gaat', 'Volledige Aflevering'],
  56. },
  57. 'params': {
  58. 'skip_download': True,
  59. },
  60. 'skip': 'Requires account credentials',
  61. }, {
  62. # Requires account credentials but bypassed extraction via v3/embed page
  63. # without metadata
  64. 'url': 'http://www.vier.be/janigaat/videos/jani-gaat-naar-tokio-aflevering-4/2674839',
  65. 'info_dict': {
  66. 'id': '2674839',
  67. 'display_id': 'jani-gaat-naar-tokio-aflevering-4',
  68. 'ext': 'mp4',
  69. 'title': 'jani-gaat-naar-tokio-aflevering-4',
  70. },
  71. 'params': {
  72. 'skip_download': True,
  73. },
  74. 'expected_warnings': ['Log in to extract metadata'],
  75. }, {
  76. # Without video id in URL
  77. 'url': 'http://www.vier.be/planb/videos/dit-najaar-plan-b',
  78. 'only_matching': True,
  79. }, {
  80. 'url': 'http://www.vier.be/video/v3/embed/16129',
  81. 'only_matching': True,
  82. }]
  83. def _real_initialize(self):
  84. self._logged_in = False
  85. def _login(self, site):
  86. username, password = self._get_login_info()
  87. if username is None or password is None:
  88. return
  89. login_page = self._download_webpage(
  90. 'http://www.%s.be/user/login' % site,
  91. None, note='Logging in', errnote='Unable to log in',
  92. data=urlencode_postdata({
  93. 'form_id': 'user_login',
  94. 'name': username,
  95. 'pass': password,
  96. }),
  97. headers={'Content-Type': 'application/x-www-form-urlencoded'})
  98. login_error = self._html_search_regex(
  99. r'(?s)<div class="messages error">\s*<div>\s*<h2.+?</h2>(.+?)<',
  100. login_page, 'login error', default=None)
  101. if login_error:
  102. self.report_warning('Unable to log in: %s' % login_error)
  103. else:
  104. self._logged_in = True
  105. def _real_extract(self, url):
  106. mobj = re.match(self._VALID_URL, url)
  107. embed_id = mobj.group('embed_id')
  108. display_id = mobj.group('display_id') or embed_id
  109. video_id = mobj.group('id') or embed_id
  110. site = mobj.group('site')
  111. if not self._logged_in:
  112. self._login(site)
  113. webpage = self._download_webpage(url, display_id)
  114. if r'id="user-login"' in webpage:
  115. self.report_warning(
  116. 'Log in to extract metadata', video_id=display_id)
  117. webpage = self._download_webpage(
  118. 'http://www.%s.be/video/v3/embed/%s' % (site, video_id),
  119. display_id)
  120. video_id = self._search_regex(
  121. [r'data-nid="(\d+)"', r'"nid"\s*:\s*"(\d+)"'],
  122. webpage, 'video id', default=video_id or display_id)
  123. application = self._search_regex(
  124. [r'data-application="([^"]+)"', r'"application"\s*:\s*"([^"]+)"'],
  125. webpage, 'application', default=site + '_vod')
  126. filename = self._search_regex(
  127. [r'data-filename="([^"]+)"', r'"filename"\s*:\s*"([^"]+)"'],
  128. webpage, 'filename')
  129. playlist_url = 'http://vod.streamcloud.be/%s/_definst_/mp4:%s.mp4/playlist.m3u8' % (application, filename)
  130. formats = self._extract_wowza_formats(
  131. playlist_url, display_id, skip_protocols=['dash'])
  132. self._sort_formats(formats)
  133. title = self._og_search_title(webpage, default=display_id)
  134. description = self._html_search_regex(
  135. r'(?s)<div\b[^>]+\bclass=(["\'])[^>]*?\bfield-type-text-with-summary\b[^>]*?\1[^>]*>.*?<p>(?P<value>.+?)</p>',
  136. webpage, 'description', default=None, group='value')
  137. thumbnail = self._og_search_thumbnail(webpage, default=None)
  138. upload_date = unified_strdate(self._html_search_regex(
  139. r'(?s)<div\b[^>]+\bclass=(["\'])[^>]*?\bfield-name-post-date\b[^>]*?\1[^>]*>.*?(?P<value>\d{2}/\d{2}/\d{4})',
  140. webpage, 'upload date', default=None, group='value'))
  141. series = self._search_regex(
  142. r'data-program=(["\'])(?P<value>(?:(?!\1).)+)\1', webpage,
  143. 'series', default=None, group='value')
  144. episode_number = int_or_none(self._search_regex(
  145. r'(?i)aflevering (\d+)', title, 'episode number', default=None))
  146. tags = re.findall(r'<a\b[^>]+\bhref=["\']/tags/[^>]+>([^<]+)<', webpage)
  147. return {
  148. 'id': video_id,
  149. 'display_id': display_id,
  150. 'title': title,
  151. 'description': description,
  152. 'thumbnail': thumbnail,
  153. 'upload_date': upload_date,
  154. 'series': series,
  155. 'episode_number': episode_number,
  156. 'tags': tags,
  157. 'formats': formats,
  158. }
  159. class VierVideosIE(InfoExtractor):
  160. IE_NAME = 'vier:videos'
  161. _VALID_URL = r'https?://(?:www\.)?(?P<site>vier|vijf)\.be/(?P<program>[^/]+)/videos(?:\?.*\bpage=(?P<page>\d+)|$)'
  162. _TESTS = [{
  163. 'url': 'http://www.vier.be/demoestuin/videos',
  164. 'info_dict': {
  165. 'id': 'demoestuin',
  166. },
  167. 'playlist_mincount': 153,
  168. }, {
  169. 'url': 'http://www.vijf.be/temptationisland/videos',
  170. 'info_dict': {
  171. 'id': 'temptationisland',
  172. },
  173. 'playlist_mincount': 159,
  174. }, {
  175. 'url': 'http://www.vier.be/demoestuin/videos?page=6',
  176. 'info_dict': {
  177. 'id': 'demoestuin-page6',
  178. },
  179. 'playlist_mincount': 20,
  180. }, {
  181. 'url': 'http://www.vier.be/demoestuin/videos?page=7',
  182. 'info_dict': {
  183. 'id': 'demoestuin-page7',
  184. },
  185. 'playlist_mincount': 13,
  186. }]
  187. def _real_extract(self, url):
  188. mobj = re.match(self._VALID_URL, url)
  189. program = mobj.group('program')
  190. site = mobj.group('site')
  191. page_id = mobj.group('page')
  192. if page_id:
  193. page_id = int(page_id)
  194. start_page = page_id
  195. playlist_id = '%s-page%d' % (program, page_id)
  196. else:
  197. start_page = 0
  198. playlist_id = program
  199. entries = []
  200. for current_page_id in itertools.count(start_page):
  201. current_page = self._download_webpage(
  202. 'http://www.%s.be/%s/videos?page=%d' % (site, program, current_page_id),
  203. program,
  204. 'Downloading page %d' % (current_page_id + 1))
  205. page_entries = [
  206. self.url_result('http://www.' + site + '.be' + video_url, 'Vier')
  207. for video_url in re.findall(
  208. r'<h[23]><a href="(/[^/]+/videos/[^/]+(?:/\d+)?)">', current_page)]
  209. entries.extend(page_entries)
  210. if page_id or '>Meer<' not in current_page:
  211. break
  212. return self.playlist_result(entries, playlist_id)