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.

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