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.

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