InfoExtractors.py 49 KB

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