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.

1573 lines
60 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. import base64
  2. import datetime
  3. import itertools
  4. import netrc
  5. import os
  6. import re
  7. import socket
  8. import time
  9. import email.utils
  10. import xml.etree.ElementTree
  11. import random
  12. import math
  13. import operator
  14. import hashlib
  15. import binascii
  16. import urllib
  17. from .utils import *
  18. from .extractor.common import InfoExtractor, SearchInfoExtractor
  19. from .extractor.ard import ARDIE
  20. from .extractor.arte import ArteTvIE
  21. from .extractor.bliptv import BlipTVIE, BlipTVUserIE
  22. from .extractor.comedycentral import ComedyCentralIE
  23. from .extractor.collegehumor import CollegeHumorIE
  24. from .extractor.dailymotion import DailymotionIE
  25. from .extractor.depositfiles import DepositFilesIE
  26. from .extractor.escapist import EscapistIE
  27. from .extractor.facebook import FacebookIE
  28. from .extractor.gametrailers import GametrailersIE
  29. from .extractor.generic import GenericIE
  30. from .extractor.googleplus import GooglePlusIE
  31. from .extractor.googlesearch import GoogleSearchIE
  32. from .extractor.infoq import InfoQIE
  33. from .extractor.metacafe import MetacafeIE
  34. from .extractor.mtv import MTVIE
  35. from .extractor.myvideo import MyVideoIE
  36. from .extractor.nba import NBAIE
  37. from .extractor.statigram import StatigramIE
  38. from .extractor.photobucket import PhotobucketIE
  39. from .extractor.soundcloud import SoundcloudIE, SoundcloudSetIE
  40. from .extractor.stanfordoc import StanfordOpenClassroomIE
  41. from .extractor.vimeo import VimeoIE
  42. from .extractor.xvideos import XVideosIE
  43. from .extractor.yahoo import YahooIE, YahooSearchIE
  44. from .extractor.youtube import YoutubeIE, YoutubePlaylistIE, YoutubeSearchIE, YoutubeUserIE, YoutubeChannelIE
  45. from .extractor.zdf import ZDFIE
  46. class MixcloudIE(InfoExtractor):
  47. """Information extractor for www.mixcloud.com"""
  48. _WORKING = False # New API, but it seems good http://www.mixcloud.com/developers/documentation/
  49. _VALID_URL = r'^(?:https?://)?(?:www\.)?mixcloud\.com/([\w\d-]+)/([\w\d-]+)'
  50. IE_NAME = u'mixcloud'
  51. def report_download_json(self, file_id):
  52. """Report JSON download."""
  53. self.to_screen(u'Downloading json')
  54. def get_urls(self, jsonData, fmt, bitrate='best'):
  55. """Get urls from 'audio_formats' section in json"""
  56. file_url = None
  57. try:
  58. bitrate_list = jsonData[fmt]
  59. if bitrate is None or bitrate == 'best' or bitrate not in bitrate_list:
  60. bitrate = max(bitrate_list) # select highest
  61. url_list = jsonData[fmt][bitrate]
  62. except TypeError: # we have no bitrate info.
  63. url_list = jsonData[fmt]
  64. return url_list
  65. def check_urls(self, url_list):
  66. """Returns 1st active url from list"""
  67. for url in url_list:
  68. try:
  69. compat_urllib_request.urlopen(url)
  70. return url
  71. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  72. url = None
  73. return None
  74. def _print_formats(self, formats):
  75. print('Available formats:')
  76. for fmt in formats.keys():
  77. for b in formats[fmt]:
  78. try:
  79. ext = formats[fmt][b][0]
  80. print('%s\t%s\t[%s]' % (fmt, b, ext.split('.')[-1]))
  81. except TypeError: # we have no bitrate info
  82. ext = formats[fmt][0]
  83. print('%s\t%s\t[%s]' % (fmt, '??', ext.split('.')[-1]))
  84. break
  85. def _real_extract(self, url):
  86. mobj = re.match(self._VALID_URL, url)
  87. if mobj is None:
  88. raise ExtractorError(u'Invalid URL: %s' % url)
  89. # extract uploader & filename from url
  90. uploader = mobj.group(1).decode('utf-8')
  91. file_id = uploader + "-" + mobj.group(2).decode('utf-8')
  92. # construct API request
  93. file_url = 'http://www.mixcloud.com/api/1/cloudcast/' + '/'.join(url.split('/')[-3:-1]) + '.json'
  94. # retrieve .json file with links to files
  95. request = compat_urllib_request.Request(file_url)
  96. try:
  97. self.report_download_json(file_url)
  98. jsonData = compat_urllib_request.urlopen(request).read()
  99. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  100. raise ExtractorError(u'Unable to retrieve file: %s' % compat_str(err))
  101. # parse JSON
  102. json_data = json.loads(jsonData)
  103. player_url = json_data['player_swf_url']
  104. formats = dict(json_data['audio_formats'])
  105. req_format = self._downloader.params.get('format', None)
  106. bitrate = None
  107. if self._downloader.params.get('listformats', None):
  108. self._print_formats(formats)
  109. return
  110. if req_format is None or req_format == 'best':
  111. for format_param in formats.keys():
  112. url_list = self.get_urls(formats, format_param)
  113. # check urls
  114. file_url = self.check_urls(url_list)
  115. if file_url is not None:
  116. break # got it!
  117. else:
  118. if req_format not in formats:
  119. raise ExtractorError(u'Format is not available')
  120. url_list = self.get_urls(formats, req_format)
  121. file_url = self.check_urls(url_list)
  122. format_param = req_format
  123. return [{
  124. 'id': file_id.decode('utf-8'),
  125. 'url': file_url.decode('utf-8'),
  126. 'uploader': uploader.decode('utf-8'),
  127. 'upload_date': None,
  128. 'title': json_data['name'],
  129. 'ext': file_url.split('.')[-1].decode('utf-8'),
  130. 'format': (format_param is None and u'NA' or format_param.decode('utf-8')),
  131. 'thumbnail': json_data['thumbnail_url'],
  132. 'description': json_data['description'],
  133. 'player_url': player_url.decode('utf-8'),
  134. }]
  135. class YoukuIE(InfoExtractor):
  136. _VALID_URL = r'(?:http://)?v\.youku\.com/v_show/id_(?P<ID>[A-Za-z0-9]+)\.html'
  137. def _gen_sid(self):
  138. nowTime = int(time.time() * 1000)
  139. random1 = random.randint(1000,1998)
  140. random2 = random.randint(1000,9999)
  141. return "%d%d%d" %(nowTime,random1,random2)
  142. def _get_file_ID_mix_string(self, seed):
  143. mixed = []
  144. source = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\:._-1234567890")
  145. seed = float(seed)
  146. for i in range(len(source)):
  147. seed = (seed * 211 + 30031 ) % 65536
  148. index = math.floor(seed / 65536 * len(source) )
  149. mixed.append(source[int(index)])
  150. source.remove(source[int(index)])
  151. #return ''.join(mixed)
  152. return mixed
  153. def _get_file_id(self, fileId, seed):
  154. mixed = self._get_file_ID_mix_string(seed)
  155. ids = fileId.split('*')
  156. realId = []
  157. for ch in ids:
  158. if ch:
  159. realId.append(mixed[int(ch)])
  160. return ''.join(realId)
  161. def _real_extract(self, url):
  162. mobj = re.match(self._VALID_URL, url)
  163. if mobj is None:
  164. raise ExtractorError(u'Invalid URL: %s' % url)
  165. video_id = mobj.group('ID')
  166. info_url = 'http://v.youku.com/player/getPlayList/VideoIDS/' + video_id
  167. jsondata = self._download_webpage(info_url, video_id)
  168. self.report_extraction(video_id)
  169. try:
  170. config = json.loads(jsondata)
  171. video_title = config['data'][0]['title']
  172. seed = config['data'][0]['seed']
  173. format = self._downloader.params.get('format', None)
  174. supported_format = list(config['data'][0]['streamfileids'].keys())
  175. if format is None or format == 'best':
  176. if 'hd2' in supported_format:
  177. format = 'hd2'
  178. else:
  179. format = 'flv'
  180. ext = u'flv'
  181. elif format == 'worst':
  182. format = 'mp4'
  183. ext = u'mp4'
  184. else:
  185. format = 'flv'
  186. ext = u'flv'
  187. fileid = config['data'][0]['streamfileids'][format]
  188. keys = [s['k'] for s in config['data'][0]['segs'][format]]
  189. except (UnicodeDecodeError, ValueError, KeyError):
  190. raise ExtractorError(u'Unable to extract info section')
  191. files_info=[]
  192. sid = self._gen_sid()
  193. fileid = self._get_file_id(fileid, seed)
  194. #column 8,9 of fileid represent the segment number
  195. #fileid[7:9] should be changed
  196. for index, key in enumerate(keys):
  197. temp_fileid = '%s%02X%s' % (fileid[0:8], index, fileid[10:])
  198. download_url = 'http://f.youku.com/player/getFlvPath/sid/%s_%02X/st/flv/fileid/%s?k=%s' % (sid, index, temp_fileid, key)
  199. info = {
  200. 'id': '%s_part%02d' % (video_id, index),
  201. 'url': download_url,
  202. 'uploader': None,
  203. 'upload_date': None,
  204. 'title': video_title,
  205. 'ext': ext,
  206. }
  207. files_info.append(info)
  208. return files_info
  209. class XNXXIE(InfoExtractor):
  210. """Information extractor for xnxx.com"""
  211. _VALID_URL = r'^(?:https?://)?video\.xnxx\.com/video([0-9]+)/(.*)'
  212. IE_NAME = u'xnxx'
  213. VIDEO_URL_RE = r'flv_url=(.*?)&amp;'
  214. VIDEO_TITLE_RE = r'<title>(.*?)\s+-\s+XNXX.COM'
  215. VIDEO_THUMB_RE = r'url_bigthumb=(.*?)&amp;'
  216. def _real_extract(self, url):
  217. mobj = re.match(self._VALID_URL, url)
  218. if mobj is None:
  219. raise ExtractorError(u'Invalid URL: %s' % url)
  220. video_id = mobj.group(1)
  221. # Get webpage content
  222. webpage = self._download_webpage(url, video_id)
  223. video_url = self._search_regex(self.VIDEO_URL_RE,
  224. webpage, u'video URL')
  225. video_url = compat_urllib_parse.unquote(video_url)
  226. video_title = self._html_search_regex(self.VIDEO_TITLE_RE,
  227. webpage, u'title')
  228. video_thumbnail = self._search_regex(self.VIDEO_THUMB_RE,
  229. webpage, u'thumbnail', fatal=False)
  230. return [{
  231. 'id': video_id,
  232. 'url': video_url,
  233. 'uploader': None,
  234. 'upload_date': None,
  235. 'title': video_title,
  236. 'ext': 'flv',
  237. 'thumbnail': video_thumbnail,
  238. 'description': None,
  239. }]
  240. class JustinTVIE(InfoExtractor):
  241. """Information extractor for justin.tv and twitch.tv"""
  242. # TODO: One broadcast may be split into multiple videos. The key
  243. # 'broadcast_id' is the same for all parts, and 'broadcast_part'
  244. # starts at 1 and increases. Can we treat all parts as one video?
  245. _VALID_URL = r"""(?x)^(?:http://)?(?:www\.)?(?:twitch|justin)\.tv/
  246. (?:
  247. (?P<channelid>[^/]+)|
  248. (?:(?:[^/]+)/b/(?P<videoid>[^/]+))|
  249. (?:(?:[^/]+)/c/(?P<chapterid>[^/]+))
  250. )
  251. /?(?:\#.*)?$
  252. """
  253. _JUSTIN_PAGE_LIMIT = 100
  254. IE_NAME = u'justin.tv'
  255. def report_download_page(self, channel, offset):
  256. """Report attempt to download a single page of videos."""
  257. self.to_screen(u'%s: Downloading video information from %d to %d' %
  258. (channel, offset, offset + self._JUSTIN_PAGE_LIMIT))
  259. # Return count of items, list of *valid* items
  260. def _parse_page(self, url, video_id):
  261. webpage = self._download_webpage(url, video_id,
  262. u'Downloading video info JSON',
  263. u'unable to download video info JSON')
  264. response = json.loads(webpage)
  265. if type(response) != list:
  266. error_text = response.get('error', 'unknown error')
  267. raise ExtractorError(u'Justin.tv API: %s' % error_text)
  268. info = []
  269. for clip in response:
  270. video_url = clip['video_file_url']
  271. if video_url:
  272. video_extension = os.path.splitext(video_url)[1][1:]
  273. video_date = re.sub('-', '', clip['start_time'][:10])
  274. video_uploader_id = clip.get('user_id', clip.get('channel_id'))
  275. video_id = clip['id']
  276. video_title = clip.get('title', video_id)
  277. info.append({
  278. 'id': video_id,
  279. 'url': video_url,
  280. 'title': video_title,
  281. 'uploader': clip.get('channel_name', video_uploader_id),
  282. 'uploader_id': video_uploader_id,
  283. 'upload_date': video_date,
  284. 'ext': video_extension,
  285. })
  286. return (len(response), info)
  287. def _real_extract(self, url):
  288. mobj = re.match(self._VALID_URL, url)
  289. if mobj is None:
  290. raise ExtractorError(u'invalid URL: %s' % url)
  291. api_base = 'http://api.justin.tv'
  292. paged = False
  293. if mobj.group('channelid'):
  294. paged = True
  295. video_id = mobj.group('channelid')
  296. api = api_base + '/channel/archives/%s.json' % video_id
  297. elif mobj.group('chapterid'):
  298. chapter_id = mobj.group('chapterid')
  299. webpage = self._download_webpage(url, chapter_id)
  300. m = re.search(r'PP\.archive_id = "([0-9]+)";', webpage)
  301. if not m:
  302. raise ExtractorError(u'Cannot find archive of a chapter')
  303. archive_id = m.group(1)
  304. api = api_base + '/broadcast/by_chapter/%s.xml' % chapter_id
  305. chapter_info_xml = self._download_webpage(api, chapter_id,
  306. note=u'Downloading chapter information',
  307. errnote=u'Chapter information download failed')
  308. doc = xml.etree.ElementTree.fromstring(chapter_info_xml)
  309. for a in doc.findall('.//archive'):
  310. if archive_id == a.find('./id').text:
  311. break
  312. else:
  313. raise ExtractorError(u'Could not find chapter in chapter information')
  314. video_url = a.find('./video_file_url').text
  315. video_ext = video_url.rpartition('.')[2] or u'flv'
  316. chapter_api_url = u'https://api.twitch.tv/kraken/videos/c' + chapter_id
  317. chapter_info_json = self._download_webpage(chapter_api_url, u'c' + chapter_id,
  318. note='Downloading chapter metadata',
  319. errnote='Download of chapter metadata failed')
  320. chapter_info = json.loads(chapter_info_json)
  321. bracket_start = int(doc.find('.//bracket_start').text)
  322. bracket_end = int(doc.find('.//bracket_end').text)
  323. # TODO determine start (and probably fix up file)
  324. # youtube-dl -v http://www.twitch.tv/firmbelief/c/1757457
  325. #video_url += u'?start=' + TODO:start_timestamp
  326. # bracket_start is 13290, but we want 51670615
  327. self._downloader.report_warning(u'Chapter detected, but we can just download the whole file. '
  328. u'Chapter starts at %s and ends at %s' % (formatSeconds(bracket_start), formatSeconds(bracket_end)))
  329. info = {
  330. 'id': u'c' + chapter_id,
  331. 'url': video_url,
  332. 'ext': video_ext,
  333. 'title': chapter_info['title'],
  334. 'thumbnail': chapter_info['preview'],
  335. 'description': chapter_info['description'],
  336. 'uploader': chapter_info['channel']['display_name'],
  337. 'uploader_id': chapter_info['channel']['name'],
  338. }
  339. return [info]
  340. else:
  341. video_id = mobj.group('videoid')
  342. api = api_base + '/broadcast/by_archive/%s.json' % video_id
  343. self.report_extraction(video_id)
  344. info = []
  345. offset = 0
  346. limit = self._JUSTIN_PAGE_LIMIT
  347. while True:
  348. if paged:
  349. self.report_download_page(video_id, offset)
  350. page_url = api + ('?offset=%d&limit=%d' % (offset, limit))
  351. page_count, page_info = self._parse_page(page_url, video_id)
  352. info.extend(page_info)
  353. if not paged or page_count != limit:
  354. break
  355. offset += limit
  356. return info
  357. class FunnyOrDieIE(InfoExtractor):
  358. _VALID_URL = r'^(?:https?://)?(?:www\.)?funnyordie\.com/videos/(?P<id>[0-9a-f]+)/.*$'
  359. def _real_extract(self, url):
  360. mobj = re.match(self._VALID_URL, url)
  361. if mobj is None:
  362. raise ExtractorError(u'invalid URL: %s' % url)
  363. video_id = mobj.group('id')
  364. webpage = self._download_webpage(url, video_id)
  365. video_url = self._html_search_regex(r'<video[^>]*>\s*<source[^>]*>\s*<source src="(?P<url>[^"]+)"',
  366. webpage, u'video URL', flags=re.DOTALL)
  367. title = self._html_search_regex((r"<h1 class='player_page_h1'.*?>(?P<title>.*?)</h1>",
  368. r'<title>(?P<title>[^<]+?)</title>'), webpage, 'title', flags=re.DOTALL)
  369. video_description = self._html_search_regex(r'<meta property="og:description" content="(?P<desc>.*?)"',
  370. webpage, u'description', fatal=False, flags=re.DOTALL)
  371. info = {
  372. 'id': video_id,
  373. 'url': video_url,
  374. 'ext': 'mp4',
  375. 'title': title,
  376. 'description': video_description,
  377. }
  378. return [info]
  379. class SteamIE(InfoExtractor):
  380. _VALID_URL = r"""http://store\.steampowered\.com/
  381. (agecheck/)?
  382. (?P<urltype>video|app)/ #If the page is only for videos or for a game
  383. (?P<gameID>\d+)/?
  384. (?P<videoID>\d*)(?P<extra>\??) #For urltype == video we sometimes get the videoID
  385. """
  386. _VIDEO_PAGE_TEMPLATE = 'http://store.steampowered.com/video/%s/'
  387. _AGECHECK_TEMPLATE = 'http://store.steampowered.com/agecheck/video/%s/?snr=1_agecheck_agecheck__age-gate&ageDay=1&ageMonth=January&ageYear=1970'
  388. @classmethod
  389. def suitable(cls, url):
  390. """Receives a URL and returns True if suitable for this IE."""
  391. return re.match(cls._VALID_URL, url, re.VERBOSE) is not None
  392. def _real_extract(self, url):
  393. m = re.match(self._VALID_URL, url, re.VERBOSE)
  394. gameID = m.group('gameID')
  395. videourl = self._VIDEO_PAGE_TEMPLATE % gameID
  396. webpage = self._download_webpage(videourl, gameID)
  397. if re.search('<h2>Please enter your birth date to continue:</h2>', webpage) is not None:
  398. videourl = self._AGECHECK_TEMPLATE % gameID
  399. self.report_age_confirmation()
  400. webpage = self._download_webpage(videourl, gameID)
  401. self.report_extraction(gameID)
  402. game_title = self._html_search_regex(r'<h2 class="pageheader">(.*?)</h2>',
  403. webpage, 'game title')
  404. urlRE = r"'movie_(?P<videoID>\d+)': \{\s*FILENAME: \"(?P<videoURL>[\w:/\.\?=]+)\"(,\s*MOVIE_NAME: \"(?P<videoName>[\w:/\.\?=\+-]+)\")?\s*\},"
  405. mweb = re.finditer(urlRE, webpage)
  406. namesRE = r'<span class="title">(?P<videoName>.+?)</span>'
  407. titles = re.finditer(namesRE, webpage)
  408. thumbsRE = r'<img class="movie_thumb" src="(?P<thumbnail>.+?)">'
  409. thumbs = re.finditer(thumbsRE, webpage)
  410. videos = []
  411. for vid,vtitle,thumb in zip(mweb,titles,thumbs):
  412. video_id = vid.group('videoID')
  413. title = vtitle.group('videoName')
  414. video_url = vid.group('videoURL')
  415. video_thumb = thumb.group('thumbnail')
  416. if not video_url:
  417. raise ExtractorError(u'Cannot find video url for %s' % video_id)
  418. info = {
  419. 'id':video_id,
  420. 'url':video_url,
  421. 'ext': 'flv',
  422. 'title': unescapeHTML(title),
  423. 'thumbnail': video_thumb
  424. }
  425. videos.append(info)
  426. return [self.playlist_result(videos, gameID, game_title)]
  427. class UstreamIE(InfoExtractor):
  428. _VALID_URL = r'https?://www\.ustream\.tv/recorded/(?P<videoID>\d+)'
  429. IE_NAME = u'ustream'
  430. def _real_extract(self, url):
  431. m = re.match(self._VALID_URL, url)
  432. video_id = m.group('videoID')
  433. video_url = u'http://tcdn.ustream.tv/video/%s' % video_id
  434. webpage = self._download_webpage(url, video_id)
  435. self.report_extraction(video_id)
  436. video_title = self._html_search_regex(r'data-title="(?P<title>.+)"',
  437. webpage, u'title')
  438. uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>',
  439. webpage, u'uploader', fatal=False, flags=re.DOTALL)
  440. thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"',
  441. webpage, u'thumbnail', fatal=False)
  442. info = {
  443. 'id': video_id,
  444. 'url': video_url,
  445. 'ext': 'flv',
  446. 'title': video_title,
  447. 'uploader': uploader,
  448. 'thumbnail': thumbnail,
  449. }
  450. return info
  451. class WorldStarHipHopIE(InfoExtractor):
  452. _VALID_URL = r'https?://(?:www|m)\.worldstar(?:candy|hiphop)\.com/videos/video\.php\?v=(?P<id>.*)'
  453. IE_NAME = u'WorldStarHipHop'
  454. def _real_extract(self, url):
  455. m = re.match(self._VALID_URL, url)
  456. video_id = m.group('id')
  457. webpage_src = self._download_webpage(url, video_id)
  458. video_url = self._search_regex(r'so\.addVariable\("file","(.*?)"\)',
  459. webpage_src, u'video URL')
  460. if 'mp4' in video_url:
  461. ext = 'mp4'
  462. else:
  463. ext = 'flv'
  464. video_title = self._html_search_regex(r"<title>(.*)</title>",
  465. webpage_src, u'title')
  466. # Getting thumbnail and if not thumbnail sets correct title for WSHH candy video.
  467. thumbnail = self._html_search_regex(r'rel="image_src" href="(.*)" />',
  468. webpage_src, u'thumbnail', fatal=False)
  469. if not thumbnail:
  470. _title = r"""candytitles.*>(.*)</span>"""
  471. mobj = re.search(_title, webpage_src)
  472. if mobj is not None:
  473. video_title = mobj.group(1)
  474. results = [{
  475. 'id': video_id,
  476. 'url' : video_url,
  477. 'title' : video_title,
  478. 'thumbnail' : thumbnail,
  479. 'ext' : ext,
  480. }]
  481. return results
  482. class RBMARadioIE(InfoExtractor):
  483. _VALID_URL = r'https?://(?:www\.)?rbmaradio\.com/shows/(?P<videoID>[^/]+)$'
  484. def _real_extract(self, url):
  485. m = re.match(self._VALID_URL, url)
  486. video_id = m.group('videoID')
  487. webpage = self._download_webpage(url, video_id)
  488. json_data = self._search_regex(r'window\.gon.*?gon\.show=(.+?);$',
  489. webpage, u'json data', flags=re.MULTILINE)
  490. try:
  491. data = json.loads(json_data)
  492. except ValueError as e:
  493. raise ExtractorError(u'Invalid JSON: ' + str(e))
  494. video_url = data['akamai_url'] + '&cbr=256'
  495. url_parts = compat_urllib_parse_urlparse(video_url)
  496. video_ext = url_parts.path.rpartition('.')[2]
  497. info = {
  498. 'id': video_id,
  499. 'url': video_url,
  500. 'ext': video_ext,
  501. 'title': data['title'],
  502. 'description': data.get('teaser_text'),
  503. 'location': data.get('country_of_origin'),
  504. 'uploader': data.get('host', {}).get('name'),
  505. 'uploader_id': data.get('host', {}).get('slug'),
  506. 'thumbnail': data.get('image', {}).get('large_url_2x'),
  507. 'duration': data.get('duration'),
  508. }
  509. return [info]
  510. class YouPornIE(InfoExtractor):
  511. """Information extractor for youporn.com."""
  512. _VALID_URL = r'^(?:https?://)?(?:\w+\.)?youporn\.com/watch/(?P<videoid>[0-9]+)/(?P<title>[^/]+)'
  513. def _print_formats(self, formats):
  514. """Print all available formats"""
  515. print(u'Available formats:')
  516. print(u'ext\t\tformat')
  517. print(u'---------------------------------')
  518. for format in formats:
  519. print(u'%s\t\t%s' % (format['ext'], format['format']))
  520. def _specific(self, req_format, formats):
  521. for x in formats:
  522. if(x["format"]==req_format):
  523. return x
  524. return None
  525. def _real_extract(self, url):
  526. mobj = re.match(self._VALID_URL, url)
  527. if mobj is None:
  528. raise ExtractorError(u'Invalid URL: %s' % url)
  529. video_id = mobj.group('videoid')
  530. req = compat_urllib_request.Request(url)
  531. req.add_header('Cookie', 'age_verified=1')
  532. webpage = self._download_webpage(req, video_id)
  533. # Get JSON parameters
  534. json_params = self._search_regex(r'var currentVideo = new Video\((.*)\);', webpage, u'JSON parameters')
  535. try:
  536. params = json.loads(json_params)
  537. except:
  538. raise ExtractorError(u'Invalid JSON')
  539. self.report_extraction(video_id)
  540. try:
  541. video_title = params['title']
  542. upload_date = unified_strdate(params['release_date_f'])
  543. video_description = params['description']
  544. video_uploader = params['submitted_by']
  545. thumbnail = params['thumbnails'][0]['image']
  546. except KeyError:
  547. raise ExtractorError('Missing JSON parameter: ' + sys.exc_info()[1])
  548. # Get all of the formats available
  549. DOWNLOAD_LIST_RE = r'(?s)<ul class="downloadList">(?P<download_list>.*?)</ul>'
  550. download_list_html = self._search_regex(DOWNLOAD_LIST_RE,
  551. webpage, u'download list').strip()
  552. # Get all of the links from the page
  553. LINK_RE = r'(?s)<a href="(?P<url>[^"]+)">'
  554. links = re.findall(LINK_RE, download_list_html)
  555. if(len(links) == 0):
  556. raise ExtractorError(u'ERROR: no known formats available for video')
  557. self.to_screen(u'Links found: %d' % len(links))
  558. formats = []
  559. for link in links:
  560. # A link looks like this:
  561. # http://cdn1.download.youporn.phncdn.com/201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4?nvb=20121113051249&nva=20121114051249&ir=1200&sr=1200&hash=014b882080310e95fb6a0
  562. # A path looks like this:
  563. # /201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4
  564. video_url = unescapeHTML( link )
  565. path = compat_urllib_parse_urlparse( video_url ).path
  566. extension = os.path.splitext( path )[1][1:]
  567. format = path.split('/')[4].split('_')[:2]
  568. size = format[0]
  569. bitrate = format[1]
  570. format = "-".join( format )
  571. # title = u'%s-%s-%s' % (video_title, size, bitrate)
  572. formats.append({
  573. 'id': video_id,
  574. 'url': video_url,
  575. 'uploader': video_uploader,
  576. 'upload_date': upload_date,
  577. 'title': video_title,
  578. 'ext': extension,
  579. 'format': format,
  580. 'thumbnail': thumbnail,
  581. 'description': video_description
  582. })
  583. if self._downloader.params.get('listformats', None):
  584. self._print_formats(formats)
  585. return
  586. req_format = self._downloader.params.get('format', None)
  587. self.to_screen(u'Format: %s' % req_format)
  588. if req_format is None or req_format == 'best':
  589. return [formats[0]]
  590. elif req_format == 'worst':
  591. return [formats[-1]]
  592. elif req_format in ('-1', 'all'):
  593. return formats
  594. else:
  595. format = self._specific( req_format, formats )
  596. if result is None:
  597. raise ExtractorError(u'Requested format not available')
  598. return [format]
  599. class PornotubeIE(InfoExtractor):
  600. """Information extractor for pornotube.com."""
  601. _VALID_URL = r'^(?:https?://)?(?:\w+\.)?pornotube\.com(/c/(?P<channel>[0-9]+))?(/m/(?P<videoid>[0-9]+))(/(?P<title>.+))$'
  602. def _real_extract(self, url):
  603. mobj = re.match(self._VALID_URL, url)
  604. if mobj is None:
  605. raise ExtractorError(u'Invalid URL: %s' % url)
  606. video_id = mobj.group('videoid')
  607. video_title = mobj.group('title')
  608. # Get webpage content
  609. webpage = self._download_webpage(url, video_id)
  610. # Get the video URL
  611. VIDEO_URL_RE = r'url: "(?P<url>http://video[0-9].pornotube.com/.+\.flv)",'
  612. video_url = self._search_regex(VIDEO_URL_RE, webpage, u'video url')
  613. video_url = compat_urllib_parse.unquote(video_url)
  614. #Get the uploaded date
  615. VIDEO_UPLOADED_RE = r'<div class="video_added_by">Added (?P<date>[0-9\/]+) by'
  616. upload_date = self._html_search_regex(VIDEO_UPLOADED_RE, webpage, u'upload date', fatal=False)
  617. if upload_date: upload_date = unified_strdate(upload_date)
  618. info = {'id': video_id,
  619. 'url': video_url,
  620. 'uploader': None,
  621. 'upload_date': upload_date,
  622. 'title': video_title,
  623. 'ext': 'flv',
  624. 'format': 'flv'}
  625. return [info]
  626. class YouJizzIE(InfoExtractor):
  627. """Information extractor for youjizz.com."""
  628. _VALID_URL = r'^(?:https?://)?(?:\w+\.)?youjizz\.com/videos/(?P<videoid>[^.]+).html$'
  629. def _real_extract(self, url):
  630. mobj = re.match(self._VALID_URL, url)
  631. if mobj is None:
  632. raise ExtractorError(u'Invalid URL: %s' % url)
  633. video_id = mobj.group('videoid')
  634. # Get webpage content
  635. webpage = self._download_webpage(url, video_id)
  636. # Get the video title
  637. video_title = self._html_search_regex(r'<title>(?P<title>.*)</title>',
  638. webpage, u'title').strip()
  639. # Get the embed page
  640. result = re.search(r'https?://www.youjizz.com/videos/embed/(?P<videoid>[0-9]+)', webpage)
  641. if result is None:
  642. raise ExtractorError(u'ERROR: unable to extract embed page')
  643. embed_page_url = result.group(0).strip()
  644. video_id = result.group('videoid')
  645. webpage = self._download_webpage(embed_page_url, video_id)
  646. # Get the video URL
  647. video_url = self._search_regex(r'so.addVariable\("file",encodeURIComponent\("(?P<source>[^"]+)"\)\);',
  648. webpage, u'video URL')
  649. info = {'id': video_id,
  650. 'url': video_url,
  651. 'title': video_title,
  652. 'ext': 'flv',
  653. 'format': 'flv',
  654. 'player_url': embed_page_url}
  655. return [info]
  656. class EightTracksIE(InfoExtractor):
  657. IE_NAME = '8tracks'
  658. _VALID_URL = r'https?://8tracks.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
  659. def _real_extract(self, url):
  660. mobj = re.match(self._VALID_URL, url)
  661. if mobj is None:
  662. raise ExtractorError(u'Invalid URL: %s' % url)
  663. playlist_id = mobj.group('id')
  664. webpage = self._download_webpage(url, playlist_id)
  665. json_like = self._search_regex(r"PAGE.mix = (.*?);\n", webpage, u'trax information', flags=re.DOTALL)
  666. data = json.loads(json_like)
  667. session = str(random.randint(0, 1000000000))
  668. mix_id = data['id']
  669. track_count = data['tracks_count']
  670. first_url = 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session, mix_id)
  671. next_url = first_url
  672. res = []
  673. for i in itertools.count():
  674. api_json = self._download_webpage(next_url, playlist_id,
  675. note=u'Downloading song information %s/%s' % (str(i+1), track_count),
  676. errnote=u'Failed to download song information')
  677. api_data = json.loads(api_json)
  678. track_data = api_data[u'set']['track']
  679. info = {
  680. 'id': track_data['id'],
  681. 'url': track_data['track_file_stream_url'],
  682. 'title': track_data['performer'] + u' - ' + track_data['name'],
  683. 'raw_title': track_data['name'],
  684. 'uploader_id': data['user']['login'],
  685. 'ext': 'm4a',
  686. }
  687. res.append(info)
  688. if api_data['set']['at_last_track']:
  689. break
  690. next_url = 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % (session, mix_id, track_data['id'])
  691. return res
  692. class KeekIE(InfoExtractor):
  693. _VALID_URL = r'http://(?:www\.)?keek\.com/(?:!|\w+/keeks/)(?P<videoID>\w+)'
  694. IE_NAME = u'keek'
  695. def _real_extract(self, url):
  696. m = re.match(self._VALID_URL, url)
  697. video_id = m.group('videoID')
  698. video_url = u'http://cdn.keek.com/keek/video/%s' % video_id
  699. thumbnail = u'http://cdn.keek.com/keek/thumbnail/%s/w100/h75' % video_id
  700. webpage = self._download_webpage(url, video_id)
  701. video_title = self._html_search_regex(r'<meta property="og:title" content="(?P<title>.*?)"',
  702. webpage, u'title')
  703. uploader = self._html_search_regex(r'<div class="user-name-and-bio">[\S\s]+?<h2>(?P<uploader>.+?)</h2>',
  704. webpage, u'uploader', fatal=False)
  705. info = {
  706. 'id': video_id,
  707. 'url': video_url,
  708. 'ext': 'mp4',
  709. 'title': video_title,
  710. 'thumbnail': thumbnail,
  711. 'uploader': uploader
  712. }
  713. return [info]
  714. class TEDIE(InfoExtractor):
  715. _VALID_URL=r'''http://www\.ted\.com/
  716. (
  717. ((?P<type_playlist>playlists)/(?P<playlist_id>\d+)) # We have a playlist
  718. |
  719. ((?P<type_talk>talks)) # We have a simple talk
  720. )
  721. (/lang/(.*?))? # The url may contain the language
  722. /(?P<name>\w+) # Here goes the name and then ".html"
  723. '''
  724. @classmethod
  725. def suitable(cls, url):
  726. """Receives a URL and returns True if suitable for this IE."""
  727. return re.match(cls._VALID_URL, url, re.VERBOSE) is not None
  728. def _real_extract(self, url):
  729. m=re.match(self._VALID_URL, url, re.VERBOSE)
  730. if m.group('type_talk'):
  731. return [self._talk_info(url)]
  732. else :
  733. playlist_id=m.group('playlist_id')
  734. name=m.group('name')
  735. self.to_screen(u'Getting info of playlist %s: "%s"' % (playlist_id,name))
  736. return [self._playlist_videos_info(url,name,playlist_id)]
  737. def _playlist_videos_info(self,url,name,playlist_id=0):
  738. '''Returns the videos of the playlist'''
  739. video_RE=r'''
  740. <li\ id="talk_(\d+)"([.\s]*?)data-id="(?P<video_id>\d+)"
  741. ([.\s]*?)data-playlist_item_id="(\d+)"
  742. ([.\s]*?)data-mediaslug="(?P<mediaSlug>.+?)"
  743. '''
  744. video_name_RE=r'<p\ class="talk-title"><a href="(?P<talk_url>/talks/(.+).html)">(?P<fullname>.+?)</a></p>'
  745. webpage=self._download_webpage(url, playlist_id, 'Downloading playlist webpage')
  746. m_videos=re.finditer(video_RE,webpage,re.VERBOSE)
  747. m_names=re.finditer(video_name_RE,webpage)
  748. playlist_title = self._html_search_regex(r'div class="headline">\s*?<h1>\s*?<span>(.*?)</span>',
  749. webpage, 'playlist title')
  750. playlist_entries = []
  751. for m_video, m_name in zip(m_videos,m_names):
  752. video_id=m_video.group('video_id')
  753. talk_url='http://www.ted.com%s' % m_name.group('talk_url')
  754. playlist_entries.append(self.url_result(talk_url, 'TED'))
  755. return self.playlist_result(playlist_entries, playlist_id = playlist_id, playlist_title = playlist_title)
  756. def _talk_info(self, url, video_id=0):
  757. """Return the video for the talk in the url"""
  758. m = re.match(self._VALID_URL, url,re.VERBOSE)
  759. video_name = m.group('name')
  760. webpage = self._download_webpage(url, video_id, 'Downloading \"%s\" page' % video_name)
  761. self.report_extraction(video_name)
  762. # If the url includes the language we get the title translated
  763. title = self._html_search_regex(r'<span id="altHeadline" >(?P<title>.*)</span>',
  764. webpage, 'title')
  765. json_data = self._search_regex(r'<script.*?>var talkDetails = ({.*?})</script>',
  766. webpage, 'json data')
  767. info = json.loads(json_data)
  768. desc = self._html_search_regex(r'<div class="talk-intro">.*?<p.*?>(.*?)</p>',
  769. webpage, 'description', flags = re.DOTALL)
  770. thumbnail = self._search_regex(r'</span>[\s.]*</div>[\s.]*<img src="(.*?)"',
  771. webpage, 'thumbnail')
  772. info = {
  773. 'id': info['id'],
  774. 'url': info['htmlStreams'][-1]['file'],
  775. 'ext': 'mp4',
  776. 'title': title,
  777. 'thumbnail': thumbnail,
  778. 'description': desc,
  779. }
  780. return info
  781. class MySpassIE(InfoExtractor):
  782. _VALID_URL = r'http://www.myspass.de/.*'
  783. def _real_extract(self, url):
  784. META_DATA_URL_TEMPLATE = 'http://www.myspass.de/myspass/includes/apps/video/getvideometadataxml.php?id=%s'
  785. # video id is the last path element of the URL
  786. # usually there is a trailing slash, so also try the second but last
  787. url_path = compat_urllib_parse_urlparse(url).path
  788. url_parent_path, video_id = os.path.split(url_path)
  789. if not video_id:
  790. _, video_id = os.path.split(url_parent_path)
  791. # get metadata
  792. metadata_url = META_DATA_URL_TEMPLATE % video_id
  793. metadata_text = self._download_webpage(metadata_url, video_id)
  794. metadata = xml.etree.ElementTree.fromstring(metadata_text.encode('utf-8'))
  795. # extract values from metadata
  796. url_flv_el = metadata.find('url_flv')
  797. if url_flv_el is None:
  798. raise ExtractorError(u'Unable to extract download url')
  799. video_url = url_flv_el.text
  800. extension = os.path.splitext(video_url)[1][1:]
  801. title_el = metadata.find('title')
  802. if title_el is None:
  803. raise ExtractorError(u'Unable to extract title')
  804. title = title_el.text
  805. format_id_el = metadata.find('format_id')
  806. if format_id_el is None:
  807. format = ext
  808. else:
  809. format = format_id_el.text
  810. description_el = metadata.find('description')
  811. if description_el is not None:
  812. description = description_el.text
  813. else:
  814. description = None
  815. imagePreview_el = metadata.find('imagePreview')
  816. if imagePreview_el is not None:
  817. thumbnail = imagePreview_el.text
  818. else:
  819. thumbnail = None
  820. info = {
  821. 'id': video_id,
  822. 'url': video_url,
  823. 'title': title,
  824. 'ext': extension,
  825. 'format': format,
  826. 'thumbnail': thumbnail,
  827. 'description': description
  828. }
  829. return [info]
  830. class SpiegelIE(InfoExtractor):
  831. _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<videoID>[0-9]+)(?:\.html)?(?:#.*)?$'
  832. def _real_extract(self, url):
  833. m = re.match(self._VALID_URL, url)
  834. video_id = m.group('videoID')
  835. webpage = self._download_webpage(url, video_id)
  836. video_title = self._html_search_regex(r'<div class="module-title">(.*?)</div>',
  837. webpage, u'title')
  838. xml_url = u'http://video2.spiegel.de/flash/' + video_id + u'.xml'
  839. xml_code = self._download_webpage(xml_url, video_id,
  840. note=u'Downloading XML', errnote=u'Failed to download XML')
  841. idoc = xml.etree.ElementTree.fromstring(xml_code)
  842. last_type = idoc[-1]
  843. filename = last_type.findall('./filename')[0].text
  844. duration = float(last_type.findall('./duration')[0].text)
  845. video_url = 'http://video2.spiegel.de/flash/' + filename
  846. video_ext = filename.rpartition('.')[2]
  847. info = {
  848. 'id': video_id,
  849. 'url': video_url,
  850. 'ext': video_ext,
  851. 'title': video_title,
  852. 'duration': duration,
  853. }
  854. return [info]
  855. class LiveLeakIE(InfoExtractor):
  856. _VALID_URL = r'^(?:http?://)?(?:\w+\.)?liveleak\.com/view\?(?:.*?)i=(?P<video_id>[\w_]+)(?:.*)'
  857. IE_NAME = u'liveleak'
  858. def _real_extract(self, url):
  859. mobj = re.match(self._VALID_URL, url)
  860. if mobj is None:
  861. raise ExtractorError(u'Invalid URL: %s' % url)
  862. video_id = mobj.group('video_id')
  863. webpage = self._download_webpage(url, video_id)
  864. video_url = self._search_regex(r'file: "(.*?)",',
  865. webpage, u'video URL')
  866. video_title = self._html_search_regex(r'<meta property="og:title" content="(?P<title>.*?)"',
  867. webpage, u'title').replace('LiveLeak.com -', '').strip()
  868. video_description = self._html_search_regex(r'<meta property="og:description" content="(?P<desc>.*?)"',
  869. webpage, u'description', fatal=False)
  870. video_uploader = self._html_search_regex(r'By:.*?(\w+)</a>',
  871. webpage, u'uploader', fatal=False)
  872. info = {
  873. 'id': video_id,
  874. 'url': video_url,
  875. 'ext': 'mp4',
  876. 'title': video_title,
  877. 'description': video_description,
  878. 'uploader': video_uploader
  879. }
  880. return [info]
  881. class TumblrIE(InfoExtractor):
  882. _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/((post)|(video))/(?P<id>\d*)/(.*?)'
  883. def _real_extract(self, url):
  884. m_url = re.match(self._VALID_URL, url)
  885. video_id = m_url.group('id')
  886. blog = m_url.group('blog_name')
  887. url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
  888. webpage = self._download_webpage(url, video_id)
  889. re_video = r'src=\\x22(?P<video_url>http://%s\.tumblr\.com/video_file/%s/(.*?))\\x22 type=\\x22video/(?P<ext>.*?)\\x22' % (blog, video_id)
  890. video = re.search(re_video, webpage)
  891. if video is None:
  892. raise ExtractorError(u'Unable to extract video')
  893. video_url = video.group('video_url')
  894. ext = video.group('ext')
  895. video_thumbnail = self._search_regex(r'posters(.*?)\[\\x22(?P<thumb>.*?)\\x22',
  896. webpage, u'thumbnail', fatal=False) # We pick the first poster
  897. if video_thumbnail: video_thumbnail = video_thumbnail.replace('\\', '')
  898. # The only place where you can get a title, it's not complete,
  899. # but searching in other places doesn't work for all videos
  900. video_title = self._html_search_regex(r'<title>(?P<title>.*?)</title>',
  901. webpage, u'title', flags=re.DOTALL)
  902. return [{'id': video_id,
  903. 'url': video_url,
  904. 'title': video_title,
  905. 'thumbnail': video_thumbnail,
  906. 'ext': ext
  907. }]
  908. class BandcampIE(InfoExtractor):
  909. _VALID_URL = r'http://.*?\.bandcamp\.com/track/(?P<title>.*)'
  910. def _real_extract(self, url):
  911. mobj = re.match(self._VALID_URL, url)
  912. title = mobj.group('title')
  913. webpage = self._download_webpage(url, title)
  914. # We get the link to the free download page
  915. m_download = re.search(r'freeDownloadPage: "(.*?)"', webpage)
  916. if m_download is None:
  917. raise ExtractorError(u'No free songs found')
  918. download_link = m_download.group(1)
  919. id = re.search(r'var TralbumData = {(.*?)id: (?P<id>\d*?)$',
  920. webpage, re.MULTILINE|re.DOTALL).group('id')
  921. download_webpage = self._download_webpage(download_link, id,
  922. 'Downloading free downloads page')
  923. # We get the dictionary of the track from some javascrip code
  924. info = re.search(r'items: (.*?),$',
  925. download_webpage, re.MULTILINE).group(1)
  926. info = json.loads(info)[0]
  927. # We pick mp3-320 for now, until format selection can be easily implemented.
  928. mp3_info = info[u'downloads'][u'mp3-320']
  929. # If we try to use this url it says the link has expired
  930. initial_url = mp3_info[u'url']
  931. re_url = r'(?P<server>http://(.*?)\.bandcamp\.com)/download/track\?enc=mp3-320&fsig=(?P<fsig>.*?)&id=(?P<id>.*?)&ts=(?P<ts>.*)$'
  932. m_url = re.match(re_url, initial_url)
  933. #We build the url we will use to get the final track url
  934. # This url is build in Bandcamp in the script download_bunde_*.js
  935. request_url = '%s/statdownload/track?enc=mp3-320&fsig=%s&id=%s&ts=%s&.rand=665028774616&.vrs=1' % (m_url.group('server'), m_url.group('fsig'), id, m_url.group('ts'))
  936. final_url_webpage = self._download_webpage(request_url, id, 'Requesting download url')
  937. # If we could correctly generate the .rand field the url would be
  938. #in the "download_url" key
  939. final_url = re.search(r'"retry_url":"(.*?)"', final_url_webpage).group(1)
  940. track_info = {'id':id,
  941. 'title' : info[u'title'],
  942. 'ext' : 'mp3',
  943. 'url' : final_url,
  944. 'thumbnail' : info[u'thumb_url'],
  945. 'uploader' : info[u'artist']
  946. }
  947. return [track_info]
  948. class RedTubeIE(InfoExtractor):
  949. """Information Extractor for redtube"""
  950. _VALID_URL = r'(?:http://)?(?:www\.)?redtube\.com/(?P<id>[0-9]+)'
  951. def _real_extract(self,url):
  952. mobj = re.match(self._VALID_URL, url)
  953. if mobj is None:
  954. raise ExtractorError(u'Invalid URL: %s' % url)
  955. video_id = mobj.group('id')
  956. video_extension = 'mp4'
  957. webpage = self._download_webpage(url, video_id)
  958. self.report_extraction(video_id)
  959. video_url = self._html_search_regex(r'<source src="(.+?)" type="video/mp4">',
  960. webpage, u'video URL')
  961. video_title = self._html_search_regex('<h1 class="videoTitle slidePanelMovable">(.+?)</h1>',
  962. webpage, u'title')
  963. return [{
  964. 'id': video_id,
  965. 'url': video_url,
  966. 'ext': video_extension,
  967. 'title': video_title,
  968. }]
  969. class InaIE(InfoExtractor):
  970. """Information Extractor for Ina.fr"""
  971. _VALID_URL = r'(?:http://)?(?:www\.)?ina\.fr/video/(?P<id>I[0-9]+)/.*'
  972. def _real_extract(self,url):
  973. mobj = re.match(self._VALID_URL, url)
  974. video_id = mobj.group('id')
  975. mrss_url='http://player.ina.fr/notices/%s.mrss' % video_id
  976. video_extension = 'mp4'
  977. webpage = self._download_webpage(mrss_url, video_id)
  978. self.report_extraction(video_id)
  979. video_url = self._html_search_regex(r'<media:player url="(?P<mp4url>http://mp4.ina.fr/[^"]+\.mp4)',
  980. webpage, u'video URL')
  981. video_title = self._search_regex(r'<title><!\[CDATA\[(?P<titre>.*?)]]></title>',
  982. webpage, u'title')
  983. return [{
  984. 'id': video_id,
  985. 'url': video_url,
  986. 'ext': video_extension,
  987. 'title': video_title,
  988. }]
  989. class HowcastIE(InfoExtractor):
  990. """Information Extractor for Howcast.com"""
  991. _VALID_URL = r'(?:https?://)?(?:www\.)?howcast\.com/videos/(?P<id>\d+)'
  992. def _real_extract(self, url):
  993. mobj = re.match(self._VALID_URL, url)
  994. video_id = mobj.group('id')
  995. webpage_url = 'http://www.howcast.com/videos/' + video_id
  996. webpage = self._download_webpage(webpage_url, video_id)
  997. self.report_extraction(video_id)
  998. video_url = self._search_regex(r'\'?file\'?: "(http://mobile-media\.howcast\.com/[0-9]+\.mp4)',
  999. webpage, u'video URL')
  1000. video_title = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') property=\'og:title\'',
  1001. webpage, u'title')
  1002. video_description = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') name=\'description\'',
  1003. webpage, u'description', fatal=False)
  1004. thumbnail = self._html_search_regex(r'<meta content=\'(.+?)\' property=\'og:image\'',
  1005. webpage, u'thumbnail', fatal=False)
  1006. return [{
  1007. 'id': video_id,
  1008. 'url': video_url,
  1009. 'ext': 'mp4',
  1010. 'title': video_title,
  1011. 'description': video_description,
  1012. 'thumbnail': thumbnail,
  1013. }]
  1014. class VineIE(InfoExtractor):
  1015. """Information Extractor for Vine.co"""
  1016. _VALID_URL = r'(?:https?://)?(?:www\.)?vine\.co/v/(?P<id>\w+)'
  1017. def _real_extract(self, url):
  1018. mobj = re.match(self._VALID_URL, url)
  1019. video_id = mobj.group('id')
  1020. webpage_url = 'https://vine.co/v/' + video_id
  1021. webpage = self._download_webpage(webpage_url, video_id)
  1022. self.report_extraction(video_id)
  1023. video_url = self._html_search_regex(r'<meta property="twitter:player:stream" content="(.+?)"',
  1024. webpage, u'video URL')
  1025. video_title = self._html_search_regex(r'<meta property="og:title" content="(.+?)"',
  1026. webpage, u'title')
  1027. thumbnail = self._html_search_regex(r'<meta property="og:image" content="(.+?)(\?.*?)?"',
  1028. webpage, u'thumbnail', fatal=False)
  1029. uploader = self._html_search_regex(r'<div class="user">.*?<h2>(.+?)</h2>',
  1030. webpage, u'uploader', fatal=False, flags=re.DOTALL)
  1031. return [{
  1032. 'id': video_id,
  1033. 'url': video_url,
  1034. 'ext': 'mp4',
  1035. 'title': video_title,
  1036. 'thumbnail': thumbnail,
  1037. 'uploader': uploader,
  1038. }]
  1039. class FlickrIE(InfoExtractor):
  1040. """Information Extractor for Flickr videos"""
  1041. _VALID_URL = r'(?:https?://)?(?:www\.)?flickr\.com/photos/(?P<uploader_id>[\w\-_@]+)/(?P<id>\d+).*'
  1042. def _real_extract(self, url):
  1043. mobj = re.match(self._VALID_URL, url)
  1044. video_id = mobj.group('id')
  1045. video_uploader_id = mobj.group('uploader_id')
  1046. webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id
  1047. webpage = self._download_webpage(webpage_url, video_id)
  1048. secret = self._search_regex(r"photo_secret: '(\w+)'", webpage, u'secret')
  1049. first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self'
  1050. first_xml = self._download_webpage(first_url, video_id, 'Downloading first data webpage')
  1051. node_id = self._html_search_regex(r'<Item id="id">(\d+-\d+)</Item>',
  1052. first_xml, u'node_id')
  1053. second_url = 'https://secure.flickr.com/video_playlist.gne?node_id=' + node_id + '&tech=flash&mode=playlist&bitrate=700&secret=' + secret + '&rd=video.yahoo.com&noad=1'
  1054. second_xml = self._download_webpage(second_url, video_id, 'Downloading second data webpage')
  1055. self.report_extraction(video_id)
  1056. mobj = re.search(r'<STREAM APP="(.+?)" FULLPATH="(.+?)"', second_xml)
  1057. if mobj is None:
  1058. raise ExtractorError(u'Unable to extract video url')
  1059. video_url = mobj.group(1) + unescapeHTML(mobj.group(2))
  1060. video_title = self._html_search_regex(r'<meta property="og:title" content=(?:"([^"]+)"|\'([^\']+)\')',
  1061. webpage, u'video title')
  1062. video_description = self._html_search_regex(r'<meta property="og:description" content=(?:"([^"]+)"|\'([^\']+)\')',
  1063. webpage, u'description', fatal=False)
  1064. thumbnail = self._html_search_regex(r'<meta property="og:image" content=(?:"([^"]+)"|\'([^\']+)\')',
  1065. webpage, u'thumbnail', fatal=False)
  1066. return [{
  1067. 'id': video_id,
  1068. 'url': video_url,
  1069. 'ext': 'mp4',
  1070. 'title': video_title,
  1071. 'description': video_description,
  1072. 'thumbnail': thumbnail,
  1073. 'uploader_id': video_uploader_id,
  1074. }]
  1075. class TeamcocoIE(InfoExtractor):
  1076. _VALID_URL = r'http://teamcoco\.com/video/(?P<url_title>.*)'
  1077. def _real_extract(self, url):
  1078. mobj = re.match(self._VALID_URL, url)
  1079. if mobj is None:
  1080. raise ExtractorError(u'Invalid URL: %s' % url)
  1081. url_title = mobj.group('url_title')
  1082. webpage = self._download_webpage(url, url_title)
  1083. video_id = self._html_search_regex(r'<article class="video" data-id="(\d+?)"',
  1084. webpage, u'video id')
  1085. self.report_extraction(video_id)
  1086. video_title = self._html_search_regex(r'<meta property="og:title" content="(.+?)"',
  1087. webpage, u'title')
  1088. thumbnail = self._html_search_regex(r'<meta property="og:image" content="(.+?)"',
  1089. webpage, u'thumbnail', fatal=False)
  1090. video_description = self._html_search_regex(r'<meta property="og:description" content="(.*?)"',
  1091. webpage, u'description', fatal=False)
  1092. data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
  1093. data = self._download_webpage(data_url, video_id, 'Downloading data webpage')
  1094. video_url = self._html_search_regex(r'<file type="high".*?>(.*?)</file>',
  1095. data, u'video URL')
  1096. return [{
  1097. 'id': video_id,
  1098. 'url': video_url,
  1099. 'ext': 'mp4',
  1100. 'title': video_title,
  1101. 'thumbnail': thumbnail,
  1102. 'description': video_description,
  1103. }]
  1104. class XHamsterIE(InfoExtractor):
  1105. """Information Extractor for xHamster"""
  1106. _VALID_URL = r'(?:http://)?(?:www.)?xhamster\.com/movies/(?P<id>[0-9]+)/.*\.html'
  1107. def _real_extract(self,url):
  1108. mobj = re.match(self._VALID_URL, url)
  1109. video_id = mobj.group('id')
  1110. mrss_url = 'http://xhamster.com/movies/%s/.html' % video_id
  1111. webpage = self._download_webpage(mrss_url, video_id)
  1112. mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
  1113. if mobj is None:
  1114. raise ExtractorError(u'Unable to extract media URL')
  1115. if len(mobj.group('server')) == 0:
  1116. video_url = compat_urllib_parse.unquote(mobj.group('file'))
  1117. else:
  1118. video_url = mobj.group('server')+'/key='+mobj.group('file')
  1119. video_extension = video_url.split('.')[-1]
  1120. video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
  1121. webpage, u'title')
  1122. # Can't see the description anywhere in the UI
  1123. # video_description = self._html_search_regex(r'<span>Description: </span>(?P<description>[^<]+)',
  1124. # webpage, u'description', fatal=False)
  1125. # if video_description: video_description = unescapeHTML(video_description)
  1126. mobj = re.search(r'hint=\'(?P<upload_date_Y>[0-9]{4})-(?P<upload_date_m>[0-9]{2})-(?P<upload_date_d>[0-9]{2}) [0-9]{2}:[0-9]{2}:[0-9]{2} [A-Z]{3,4}\'', webpage)
  1127. if mobj:
  1128. video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
  1129. else:
  1130. video_upload_date = None
  1131. self._downloader.report_warning(u'Unable to extract upload date')
  1132. video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
  1133. webpage, u'uploader id', default=u'anonymous')
  1134. video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
  1135. webpage, u'thumbnail', fatal=False)
  1136. return [{
  1137. 'id': video_id,
  1138. 'url': video_url,
  1139. 'ext': video_extension,
  1140. 'title': video_title,
  1141. # 'description': video_description,
  1142. 'upload_date': video_upload_date,
  1143. 'uploader_id': video_uploader_id,
  1144. 'thumbnail': video_thumbnail
  1145. }]
  1146. class HypemIE(InfoExtractor):
  1147. """Information Extractor for hypem"""
  1148. _VALID_URL = r'(?:http://)?(?:www\.)?hypem\.com/track/([^/]+)/([^/]+)'
  1149. def _real_extract(self, url):
  1150. mobj = re.match(self._VALID_URL, url)
  1151. if mobj is None:
  1152. raise ExtractorError(u'Invalid URL: %s' % url)
  1153. track_id = mobj.group(1)
  1154. data = { 'ax': 1, 'ts': time.time() }
  1155. data_encoded = compat_urllib_parse.urlencode(data)
  1156. complete_url = url + "?" + data_encoded
  1157. request = compat_urllib_request.Request(complete_url)
  1158. response, urlh = self._download_webpage_handle(request, track_id, u'Downloading webpage with the url')
  1159. cookie = urlh.headers.get('Set-Cookie', '')
  1160. self.report_extraction(track_id)
  1161. html_tracks = self._html_search_regex(r'<script type="application/json" id="displayList-data">(.*?)</script>',
  1162. response, u'tracks', flags=re.MULTILINE|re.DOTALL).strip()
  1163. try:
  1164. track_list = json.loads(html_tracks)
  1165. track = track_list[u'tracks'][0]
  1166. except ValueError:
  1167. raise ExtractorError(u'Hypemachine contained invalid JSON.')
  1168. key = track[u"key"]
  1169. track_id = track[u"id"]
  1170. artist = track[u"artist"]
  1171. title = track[u"song"]
  1172. serve_url = "http://hypem.com/serve/source/%s/%s" % (compat_str(track_id), compat_str(key))
  1173. request = compat_urllib_request.Request(serve_url, "" , {'Content-Type': 'application/json'})
  1174. request.add_header('cookie', cookie)
  1175. song_data_json = self._download_webpage(request, track_id, u'Downloading metadata')
  1176. try:
  1177. song_data = json.loads(song_data_json)
  1178. except ValueError:
  1179. raise ExtractorError(u'Hypemachine contained invalid JSON.')
  1180. final_url = song_data[u"url"]
  1181. return [{
  1182. 'id': track_id,
  1183. 'url': final_url,
  1184. 'ext': "mp3",
  1185. 'title': title,
  1186. 'artist': artist,
  1187. }]
  1188. class Vbox7IE(InfoExtractor):
  1189. """Information Extractor for Vbox7"""
  1190. _VALID_URL = r'(?:http://)?(?:www\.)?vbox7\.com/play:([^/]+)'
  1191. def _real_extract(self,url):
  1192. mobj = re.match(self._VALID_URL, url)
  1193. if mobj is None:
  1194. raise ExtractorError(u'Invalid URL: %s' % url)
  1195. video_id = mobj.group(1)
  1196. redirect_page, urlh = self._download_webpage_handle(url, video_id)
  1197. new_location = self._search_regex(r'window\.location = \'(.*)\';', redirect_page, u'redirect location')
  1198. redirect_url = urlh.geturl() + new_location
  1199. webpage = self._download_webpage(redirect_url, video_id, u'Downloading redirect page')
  1200. title = self._html_search_regex(r'<title>(.*)</title>',
  1201. webpage, u'title').split('/')[0].strip()
  1202. ext = "flv"
  1203. info_url = "http://vbox7.com/play/magare.do"
  1204. data = compat_urllib_parse.urlencode({'as3':'1','vid':video_id})
  1205. info_request = compat_urllib_request.Request(info_url, data)
  1206. info_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  1207. info_response = self._download_webpage(info_request, video_id, u'Downloading info webpage')
  1208. if info_response is None:
  1209. raise ExtractorError(u'Unable to extract the media url')
  1210. (final_url, thumbnail_url) = map(lambda x: x.split('=')[1], info_response.split('&'))
  1211. return [{
  1212. 'id': video_id,
  1213. 'url': final_url,
  1214. 'ext': ext,
  1215. 'title': title,
  1216. 'thumbnail': thumbnail_url,
  1217. }]
  1218. def gen_extractors():
  1219. """ Return a list of an instance of every supported extractor.
  1220. The order does matter; the first extractor matched is the one handling the URL.
  1221. """
  1222. return [
  1223. YoutubePlaylistIE(),
  1224. YoutubeChannelIE(),
  1225. YoutubeUserIE(),
  1226. YoutubeSearchIE(),
  1227. YoutubeIE(),
  1228. MetacafeIE(),
  1229. DailymotionIE(),
  1230. GoogleSearchIE(),
  1231. PhotobucketIE(),
  1232. YahooIE(),
  1233. YahooSearchIE(),
  1234. DepositFilesIE(),
  1235. FacebookIE(),
  1236. BlipTVIE(),
  1237. BlipTVUserIE(),
  1238. VimeoIE(),
  1239. MyVideoIE(),
  1240. ComedyCentralIE(),
  1241. EscapistIE(),
  1242. CollegeHumorIE(),
  1243. XVideosIE(),
  1244. SoundcloudSetIE(),
  1245. SoundcloudIE(),
  1246. InfoQIE(),
  1247. MixcloudIE(),
  1248. StanfordOpenClassroomIE(),
  1249. MTVIE(),
  1250. YoukuIE(),
  1251. XNXXIE(),
  1252. YouJizzIE(),
  1253. PornotubeIE(),
  1254. YouPornIE(),
  1255. GooglePlusIE(),
  1256. ArteTvIE(),
  1257. NBAIE(),
  1258. WorldStarHipHopIE(),
  1259. JustinTVIE(),
  1260. FunnyOrDieIE(),
  1261. SteamIE(),
  1262. UstreamIE(),
  1263. RBMARadioIE(),
  1264. EightTracksIE(),
  1265. KeekIE(),
  1266. TEDIE(),
  1267. MySpassIE(),
  1268. SpiegelIE(),
  1269. LiveLeakIE(),
  1270. ARDIE(),
  1271. ZDFIE(),
  1272. TumblrIE(),
  1273. BandcampIE(),
  1274. RedTubeIE(),
  1275. InaIE(),
  1276. HowcastIE(),
  1277. VineIE(),
  1278. FlickrIE(),
  1279. TeamcocoIE(),
  1280. XHamsterIE(),
  1281. HypemIE(),
  1282. Vbox7IE(),
  1283. GametrailersIE(),
  1284. StatigramIE(),
  1285. GenericIE()
  1286. ]
  1287. def get_info_extractor(ie_name):
  1288. """Returns the info extractor class with the given ie_name"""
  1289. return globals()[ie_name+'IE']