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.

462 lines
18 KiB

10 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
10 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. import itertools
  6. from .common import InfoExtractor
  7. from ..utils import (
  8. determine_ext,
  9. error_to_compat_str,
  10. ExtractorError,
  11. int_or_none,
  12. parse_iso8601,
  13. sanitized_Request,
  14. str_to_int,
  15. unescapeHTML,
  16. mimetype2ext,
  17. )
  18. class DailymotionBaseInfoExtractor(InfoExtractor):
  19. @staticmethod
  20. def _build_request(url):
  21. """Build a request with the family filter disabled"""
  22. request = sanitized_Request(url)
  23. request.add_header('Cookie', 'family_filter=off; ff=off')
  24. return request
  25. def _download_webpage_handle_no_ff(self, url, *args, **kwargs):
  26. request = self._build_request(url)
  27. return self._download_webpage_handle(request, *args, **kwargs)
  28. def _download_webpage_no_ff(self, url, *args, **kwargs):
  29. request = self._build_request(url)
  30. return self._download_webpage(request, *args, **kwargs)
  31. class DailymotionIE(DailymotionBaseInfoExtractor):
  32. _VALID_URL = r'(?i)https?://(?:(www|touch)\.)?dailymotion\.[a-z]{2,3}/(?:(?:(?:embed|swf|#)/)?video|swf)/(?P<id>[^/?_]+)'
  33. IE_NAME = 'dailymotion'
  34. _FORMATS = [
  35. ('stream_h264_ld_url', 'ld'),
  36. ('stream_h264_url', 'standard'),
  37. ('stream_h264_hq_url', 'hq'),
  38. ('stream_h264_hd_url', 'hd'),
  39. ('stream_h264_hd1080_url', 'hd180'),
  40. ]
  41. _TESTS = [{
  42. 'url': 'http://www.dailymotion.com/video/x5kesuj_office-christmas-party-review-jason-bateman-olivia-munn-t-j-miller_news',
  43. 'md5': '074b95bdee76b9e3654137aee9c79dfe',
  44. 'info_dict': {
  45. 'id': 'x5kesuj',
  46. 'ext': 'mp4',
  47. 'title': 'Office Christmas Party Review – Jason Bateman, Olivia Munn, T.J. Miller',
  48. 'description': 'Office Christmas Party Review - Jason Bateman, Olivia Munn, T.J. Miller',
  49. 'thumbnail': r're:^https?:.*\.(?:jpg|png)$',
  50. 'duration': 187,
  51. 'timestamp': 1493651285,
  52. 'upload_date': '20170501',
  53. 'uploader': 'Deadline',
  54. 'uploader_id': 'x1xm8ri',
  55. 'age_limit': 0,
  56. 'view_count': int,
  57. },
  58. }, {
  59. 'url': 'https://www.dailymotion.com/video/x2iuewm_steam-machine-models-pricing-listed-on-steam-store-ign-news_videogames',
  60. 'md5': '2137c41a8e78554bb09225b8eb322406',
  61. 'info_dict': {
  62. 'id': 'x2iuewm',
  63. 'ext': 'mp4',
  64. 'title': 'Steam Machine Models, Pricing Listed on Steam Store - IGN News',
  65. 'description': 'Several come bundled with the Steam Controller.',
  66. 'thumbnail': r're:^https?:.*\.(?:jpg|png)$',
  67. 'duration': 74,
  68. 'timestamp': 1425657362,
  69. 'upload_date': '20150306',
  70. 'uploader': 'IGN',
  71. 'uploader_id': 'xijv66',
  72. 'age_limit': 0,
  73. 'view_count': int,
  74. },
  75. 'skip': 'video gone',
  76. }, {
  77. # Vevo video
  78. 'url': 'http://www.dailymotion.com/video/x149uew_katy-perry-roar-official_musi',
  79. 'info_dict': {
  80. 'title': 'Roar (Official)',
  81. 'id': 'USUV71301934',
  82. 'ext': 'mp4',
  83. 'uploader': 'Katy Perry',
  84. 'upload_date': '20130905',
  85. },
  86. 'params': {
  87. 'skip_download': True,
  88. },
  89. 'skip': 'VEVO is only available in some countries',
  90. }, {
  91. # age-restricted video
  92. 'url': 'http://www.dailymotion.com/video/xyh2zz_leanna-decker-cyber-girl-of-the-year-desires-nude-playboy-plus_redband',
  93. 'md5': '0d667a7b9cebecc3c89ee93099c4159d',
  94. 'info_dict': {
  95. 'id': 'xyh2zz',
  96. 'ext': 'mp4',
  97. 'title': 'Leanna Decker - Cyber Girl Of The Year Desires Nude [Playboy Plus]',
  98. 'uploader': 'HotWaves1012',
  99. 'age_limit': 18,
  100. },
  101. 'skip': 'video gone',
  102. }, {
  103. # geo-restricted, player v5
  104. 'url': 'http://www.dailymotion.com/video/xhza0o',
  105. 'only_matching': True,
  106. }, {
  107. # with subtitles
  108. 'url': 'http://www.dailymotion.com/video/x20su5f_the-power-of-nightmares-1-the-rise-of-the-politics-of-fear-bbc-2004_news',
  109. 'only_matching': True,
  110. }, {
  111. 'url': 'http://www.dailymotion.com/swf/video/x3n92nf',
  112. 'only_matching': True,
  113. }, {
  114. 'url': 'http://www.dailymotion.com/swf/x3ss1m_funny-magic-trick-barry-and-stuart_fun',
  115. 'only_matching': True,
  116. }]
  117. @staticmethod
  118. def _extract_urls(webpage):
  119. # Look for embedded Dailymotion player
  120. matches = re.findall(
  121. r'<(?:(?:embed|iframe)[^>]+?src=|input[^>]+id=[\'"]dmcloudUrlEmissionSelect[\'"][^>]+value=)(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/(?:embed|swf)/video/.+?)\1', webpage)
  122. return list(map(lambda m: unescapeHTML(m[1]), matches))
  123. def _real_extract(self, url):
  124. video_id = self._match_id(url)
  125. webpage = self._download_webpage_no_ff(
  126. 'https://www.dailymotion.com/video/%s' % video_id, video_id)
  127. age_limit = self._rta_search(webpage)
  128. description = self._og_search_description(webpage) or self._html_search_meta(
  129. 'description', webpage, 'description')
  130. view_count_str = self._search_regex(
  131. (r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserPlays:([\s\d,.]+)"',
  132. r'video_views_count[^>]+>\s+([\s\d\,.]+)'),
  133. webpage, 'view count', fatal=False)
  134. if view_count_str:
  135. view_count_str = re.sub(r'\s', '', view_count_str)
  136. view_count = str_to_int(view_count_str)
  137. comment_count = int_or_none(self._search_regex(
  138. r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserComments:(\d+)"',
  139. webpage, 'comment count', default=None))
  140. player_v5 = self._search_regex(
  141. [r'buildPlayer\(({.+?})\);\n', # See https://github.com/rg3/youtube-dl/issues/7826
  142. r'playerV5\s*=\s*dmp\.create\([^,]+?,\s*({.+?})\);',
  143. r'buildPlayer\(({.+?})\);',
  144. r'var\s+config\s*=\s*({.+?});'],
  145. webpage, 'player v5', default=None)
  146. if player_v5:
  147. player = self._parse_json(player_v5, video_id)
  148. metadata = player['metadata']
  149. self._check_error(metadata)
  150. formats = []
  151. for quality, media_list in metadata['qualities'].items():
  152. for media in media_list:
  153. media_url = media.get('url')
  154. if not media_url:
  155. continue
  156. type_ = media.get('type')
  157. if type_ == 'application/vnd.lumberjack.manifest':
  158. continue
  159. ext = mimetype2ext(type_) or determine_ext(media_url)
  160. if ext == 'm3u8':
  161. formats.extend(self._extract_m3u8_formats(
  162. media_url, video_id, 'mp4', preference=-1,
  163. m3u8_id='hls', fatal=False))
  164. elif ext == 'f4m':
  165. formats.extend(self._extract_f4m_formats(
  166. media_url, video_id, preference=-1, f4m_id='hds', fatal=False))
  167. else:
  168. f = {
  169. 'url': media_url,
  170. 'format_id': 'http-%s' % quality,
  171. 'ext': ext,
  172. }
  173. m = re.search(r'H264-(?P<width>\d+)x(?P<height>\d+)', media_url)
  174. if m:
  175. f.update({
  176. 'width': int(m.group('width')),
  177. 'height': int(m.group('height')),
  178. })
  179. formats.append(f)
  180. self._sort_formats(formats)
  181. title = metadata['title']
  182. duration = int_or_none(metadata.get('duration'))
  183. timestamp = int_or_none(metadata.get('created_time'))
  184. thumbnail = metadata.get('poster_url')
  185. uploader = metadata.get('owner', {}).get('screenname')
  186. uploader_id = metadata.get('owner', {}).get('id')
  187. subtitles = {}
  188. subtitles_data = metadata.get('subtitles', {}).get('data', {})
  189. if subtitles_data and isinstance(subtitles_data, dict):
  190. for subtitle_lang, subtitle in subtitles_data.items():
  191. subtitles[subtitle_lang] = [{
  192. 'ext': determine_ext(subtitle_url),
  193. 'url': subtitle_url,
  194. } for subtitle_url in subtitle.get('urls', [])]
  195. return {
  196. 'id': video_id,
  197. 'title': title,
  198. 'description': description,
  199. 'thumbnail': thumbnail,
  200. 'duration': duration,
  201. 'timestamp': timestamp,
  202. 'uploader': uploader,
  203. 'uploader_id': uploader_id,
  204. 'age_limit': age_limit,
  205. 'view_count': view_count,
  206. 'comment_count': comment_count,
  207. 'formats': formats,
  208. 'subtitles': subtitles,
  209. }
  210. # vevo embed
  211. vevo_id = self._search_regex(
  212. r'<link rel="video_src" href="[^"]*?vevo.com[^"]*?video=(?P<id>[\w]*)',
  213. webpage, 'vevo embed', default=None)
  214. if vevo_id:
  215. return self.url_result('vevo:%s' % vevo_id, 'Vevo')
  216. # fallback old player
  217. embed_page = self._download_webpage_no_ff(
  218. 'https://www.dailymotion.com/embed/video/%s' % video_id,
  219. video_id, 'Downloading embed page')
  220. timestamp = parse_iso8601(self._html_search_meta(
  221. 'video:release_date', webpage, 'upload date'))
  222. info = self._parse_json(
  223. self._search_regex(
  224. r'var info = ({.*?}),$', embed_page,
  225. 'video info', flags=re.MULTILINE),
  226. video_id)
  227. self._check_error(info)
  228. formats = []
  229. for (key, format_id) in self._FORMATS:
  230. video_url = info.get(key)
  231. if video_url is not None:
  232. m_size = re.search(r'H264-(\d+)x(\d+)', video_url)
  233. if m_size is not None:
  234. width, height = map(int_or_none, (m_size.group(1), m_size.group(2)))
  235. else:
  236. width, height = None, None
  237. formats.append({
  238. 'url': video_url,
  239. 'ext': 'mp4',
  240. 'format_id': format_id,
  241. 'width': width,
  242. 'height': height,
  243. })
  244. self._sort_formats(formats)
  245. # subtitles
  246. video_subtitles = self.extract_subtitles(video_id, webpage)
  247. title = self._og_search_title(webpage, default=None)
  248. if title is None:
  249. title = self._html_search_regex(
  250. r'(?s)<span\s+id="video_title"[^>]*>(.*?)</span>', webpage,
  251. 'title')
  252. return {
  253. 'id': video_id,
  254. 'formats': formats,
  255. 'uploader': info['owner.screenname'],
  256. 'timestamp': timestamp,
  257. 'title': title,
  258. 'description': description,
  259. 'subtitles': video_subtitles,
  260. 'thumbnail': info['thumbnail_url'],
  261. 'age_limit': age_limit,
  262. 'view_count': view_count,
  263. 'duration': info['duration']
  264. }
  265. def _check_error(self, info):
  266. error = info.get('error')
  267. if info.get('error') is not None:
  268. title = error['title']
  269. # See https://developer.dailymotion.com/api#access-error
  270. if error.get('code') == 'DM007':
  271. self.raise_geo_restricted(msg=title)
  272. raise ExtractorError(
  273. '%s said: %s' % (self.IE_NAME, title), expected=True)
  274. def _get_subtitles(self, video_id, webpage):
  275. try:
  276. sub_list = self._download_webpage(
  277. 'https://api.dailymotion.com/video/%s/subtitles?fields=id,language,url' % video_id,
  278. video_id, note=False)
  279. except ExtractorError as err:
  280. self._downloader.report_warning('unable to download video subtitles: %s' % error_to_compat_str(err))
  281. return {}
  282. info = json.loads(sub_list)
  283. if (info['total'] > 0):
  284. sub_lang_list = dict((l['language'], [{'url': l['url'], 'ext': 'srt'}]) for l in info['list'])
  285. return sub_lang_list
  286. self._downloader.report_warning('video doesn\'t have subtitles')
  287. return {}
  288. class DailymotionPlaylistIE(DailymotionBaseInfoExtractor):
  289. IE_NAME = 'dailymotion:playlist'
  290. _VALID_URL = r'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>.+?)/'
  291. _MORE_PAGES_INDICATOR = r'(?s)<div class="pages[^"]*">.*?<a\s+class="[^"]*?icon-arrow_right[^"]*?"'
  292. _PAGE_TEMPLATE = 'https://www.dailymotion.com/playlist/%s/%s'
  293. _TESTS = [{
  294. 'url': 'http://www.dailymotion.com/playlist/xv4bw_nqtv_sport/1#video=xl8v3q',
  295. 'info_dict': {
  296. 'title': 'SPORT',
  297. 'id': 'xv4bw_nqtv_sport',
  298. },
  299. 'playlist_mincount': 20,
  300. }]
  301. def _extract_entries(self, id):
  302. video_ids = set()
  303. processed_urls = set()
  304. for pagenum in itertools.count(1):
  305. page_url = self._PAGE_TEMPLATE % (id, pagenum)
  306. webpage, urlh = self._download_webpage_handle_no_ff(
  307. page_url, id, 'Downloading page %s' % pagenum)
  308. if urlh.geturl() in processed_urls:
  309. self.report_warning('Stopped at duplicated page %s, which is the same as %s' % (
  310. page_url, urlh.geturl()), id)
  311. break
  312. processed_urls.add(urlh.geturl())
  313. for video_id in re.findall(r'data-xid="(.+?)"', webpage):
  314. if video_id not in video_ids:
  315. yield self.url_result(
  316. 'http://www.dailymotion.com/video/%s' % video_id,
  317. DailymotionIE.ie_key(), video_id)
  318. video_ids.add(video_id)
  319. if re.search(self._MORE_PAGES_INDICATOR, webpage) is None:
  320. break
  321. def _real_extract(self, url):
  322. mobj = re.match(self._VALID_URL, url)
  323. playlist_id = mobj.group('id')
  324. webpage = self._download_webpage(url, playlist_id)
  325. return {
  326. '_type': 'playlist',
  327. 'id': playlist_id,
  328. 'title': self._og_search_title(webpage),
  329. 'entries': self._extract_entries(playlist_id),
  330. }
  331. class DailymotionUserIE(DailymotionPlaylistIE):
  332. IE_NAME = 'dailymotion:user'
  333. _VALID_URL = r'https?://(?:www\.)?dailymotion\.[a-z]{2,3}/(?!(?:embed|swf|#|video|playlist)/)(?:(?:old/)?user/)?(?P<user>[^/]+)'
  334. _PAGE_TEMPLATE = 'http://www.dailymotion.com/user/%s/%s'
  335. _TESTS = [{
  336. 'url': 'https://www.dailymotion.com/user/nqtv',
  337. 'info_dict': {
  338. 'id': 'nqtv',
  339. 'title': 'Rémi Gaillard',
  340. },
  341. 'playlist_mincount': 100,
  342. }, {
  343. 'url': 'http://www.dailymotion.com/user/UnderProject',
  344. 'info_dict': {
  345. 'id': 'UnderProject',
  346. 'title': 'UnderProject',
  347. },
  348. 'playlist_mincount': 1800,
  349. 'expected_warnings': [
  350. 'Stopped at duplicated page',
  351. ],
  352. 'skip': 'Takes too long time',
  353. }]
  354. def _real_extract(self, url):
  355. mobj = re.match(self._VALID_URL, url)
  356. user = mobj.group('user')
  357. webpage = self._download_webpage(
  358. 'https://www.dailymotion.com/user/%s' % user, user)
  359. full_user = unescapeHTML(self._html_search_regex(
  360. r'<a class="nav-image" title="([^"]+)" href="/%s">' % re.escape(user),
  361. webpage, 'user'))
  362. return {
  363. '_type': 'playlist',
  364. 'id': user,
  365. 'title': full_user,
  366. 'entries': self._extract_entries(user),
  367. }
  368. class DailymotionCloudIE(DailymotionBaseInfoExtractor):
  369. _VALID_URL_PREFIX = r'https?://api\.dmcloud\.net/(?:player/)?embed/'
  370. _VALID_URL = r'%s[^/]+/(?P<id>[^/?]+)' % _VALID_URL_PREFIX
  371. _VALID_EMBED_URL = r'%s[^/]+/[^\'"]+' % _VALID_URL_PREFIX
  372. _TESTS = [{
  373. # From http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html
  374. # Tested at FranceTvInfo_2
  375. 'url': 'http://api.dmcloud.net/embed/4e7343f894a6f677b10006b4/556e03339473995ee145930c?auth=1464865870-0-jyhsm84b-ead4c701fb750cf9367bf4447167a3db&autoplay=1',
  376. 'only_matching': True,
  377. }, {
  378. # http://www.francetvinfo.fr/societe/larguez-les-amarres-le-cobaturage-se-developpe_980101.html
  379. 'url': 'http://api.dmcloud.net/player/embed/4e7343f894a6f677b10006b4/559545469473996d31429f06?auth=1467430263-0-90tglw2l-a3a4b64ed41efe48d7fccad85b8b8fda&autoplay=1',
  380. 'only_matching': True,
  381. }]
  382. @classmethod
  383. def _extract_dmcloud_url(cls, webpage):
  384. mobj = re.search(r'<iframe[^>]+src=[\'"](%s)[\'"]' % cls._VALID_EMBED_URL, webpage)
  385. if mobj:
  386. return mobj.group(1)
  387. mobj = re.search(
  388. r'<input[^>]+id=[\'"]dmcloudUrlEmissionSelect[\'"][^>]+value=[\'"](%s)[\'"]' % cls._VALID_EMBED_URL,
  389. webpage)
  390. if mobj:
  391. return mobj.group(1)
  392. def _real_extract(self, url):
  393. video_id = self._match_id(url)
  394. webpage = self._download_webpage_no_ff(url, video_id)
  395. title = self._html_search_regex(r'<title>([^>]+)</title>', webpage, 'title')
  396. video_info = self._parse_json(self._search_regex(
  397. r'var\s+info\s*=\s*([^;]+);', webpage, 'video info'), video_id)
  398. # TODO: parse ios_url, which is in fact a manifest
  399. video_url = video_info['mp4_url']
  400. return {
  401. 'id': video_id,
  402. 'url': video_url,
  403. 'title': title,
  404. 'thumbnail': video_info.get('thumbnail_url'),
  405. }