InfoExtractors.py 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from __future__ import absolute_import
  4. import base64
  5. import datetime
  6. import itertools
  7. import netrc
  8. import os
  9. import re
  10. import socket
  11. import time
  12. import email.utils
  13. import xml.etree.ElementTree
  14. import random
  15. import math
  16. import operator
  17. import hashlib
  18. import binascii
  19. import urllib
  20. from .utils import *
  21. from .extractor.common import InfoExtractor, SearchInfoExtractor
  22. from .extractor.dailymotion import DailymotionIE
  23. from .extractor.metacafe import MetacafeIE
  24. from .extractor.statigram import StatigramIE
  25. from .extractor.photobucket import PhotobucketIE
  26. from .extractor.vimeo import VimeoIE
  27. from .extractor.yahoo import YahooIE
  28. from .extractor.youtube import YoutubeIE, YoutubePlaylistIE, YoutubeUserIE, YoutubeChannelIE
  29. class ArteTvIE(InfoExtractor):
  30. """arte.tv information extractor."""
  31. _VALID_URL = r'(?:http://)?videos\.arte\.tv/(?:fr|de)/videos/.*'
  32. _LIVE_URL = r'index-[0-9]+\.html$'
  33. IE_NAME = u'arte.tv'
  34. def fetch_webpage(self, url):
  35. request = compat_urllib_request.Request(url)
  36. try:
  37. self.report_download_webpage(url)
  38. webpage = compat_urllib_request.urlopen(request).read()
  39. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  40. raise ExtractorError(u'Unable to retrieve video webpage: %s' % compat_str(err))
  41. except ValueError as err:
  42. raise ExtractorError(u'Invalid URL: %s' % url)
  43. return webpage
  44. def grep_webpage(self, url, regex, regexFlags, matchTuples):
  45. page = self.fetch_webpage(url)
  46. mobj = re.search(regex, page, regexFlags)
  47. info = {}
  48. if mobj is None:
  49. raise ExtractorError(u'Invalid URL: %s' % url)
  50. for (i, key, err) in matchTuples:
  51. if mobj.group(i) is None:
  52. raise ExtractorError(err)
  53. else:
  54. info[key] = mobj.group(i)
  55. return info
  56. def extractLiveStream(self, url):
  57. video_lang = url.split('/')[-4]
  58. info = self.grep_webpage(
  59. url,
  60. r'src="(.*?/videothek_js.*?\.js)',
  61. 0,
  62. [
  63. (1, 'url', u'Invalid URL: %s' % url)
  64. ]
  65. )
  66. http_host = url.split('/')[2]
  67. next_url = 'http://%s%s' % (http_host, compat_urllib_parse.unquote(info.get('url')))
  68. info = self.grep_webpage(
  69. next_url,
  70. r'(s_artestras_scst_geoFRDE_' + video_lang + '.*?)\'.*?' +
  71. '(http://.*?\.swf).*?' +
  72. '(rtmp://.*?)\'',
  73. re.DOTALL,
  74. [
  75. (1, 'path', u'could not extract video path: %s' % url),
  76. (2, 'player', u'could not extract video player: %s' % url),
  77. (3, 'url', u'could not extract video url: %s' % url)
  78. ]
  79. )
  80. video_url = u'%s/%s' % (info.get('url'), info.get('path'))
  81. def extractPlus7Stream(self, url):
  82. video_lang = url.split('/')[-3]
  83. info = self.grep_webpage(
  84. url,
  85. r'param name="movie".*?videorefFileUrl=(http[^\'"&]*)',
  86. 0,
  87. [
  88. (1, 'url', u'Invalid URL: %s' % url)
  89. ]
  90. )
  91. next_url = compat_urllib_parse.unquote(info.get('url'))
  92. info = self.grep_webpage(
  93. next_url,
  94. r'<video lang="%s" ref="(http[^\'"&]*)' % video_lang,
  95. 0,
  96. [
  97. (1, 'url', u'Could not find <video> tag: %s' % url)
  98. ]
  99. )
  100. next_url = compat_urllib_parse.unquote(info.get('url'))
  101. info = self.grep_webpage(
  102. next_url,
  103. r'<video id="(.*?)".*?>.*?' +
  104. '<name>(.*?)</name>.*?' +
  105. '<dateVideo>(.*?)</dateVideo>.*?' +
  106. '<url quality="hd">(.*?)</url>',
  107. re.DOTALL,
  108. [
  109. (1, 'id', u'could not extract video id: %s' % url),
  110. (2, 'title', u'could not extract video title: %s' % url),
  111. (3, 'date', u'could not extract video date: %s' % url),
  112. (4, 'url', u'could not extract video url: %s' % url)
  113. ]
  114. )
  115. return {
  116. 'id': info.get('id'),
  117. 'url': compat_urllib_parse.unquote(info.get('url')),
  118. 'uploader': u'arte.tv',
  119. 'upload_date': unified_strdate(info.get('date')),
  120. 'title': info.get('title').decode('utf-8'),
  121. 'ext': u'mp4',
  122. 'format': u'NA',
  123. 'player_url': None,
  124. }
  125. def _real_extract(self, url):
  126. video_id = url.split('/')[-1]
  127. self.report_extraction(video_id)
  128. if re.search(self._LIVE_URL, video_id) is not None:
  129. self.extractLiveStream(url)
  130. return
  131. else:
  132. info = self.extractPlus7Stream(url)
  133. return [info]
  134. class GenericIE(InfoExtractor):
  135. """Generic last-resort information extractor."""
  136. _VALID_URL = r'.*'
  137. IE_NAME = u'generic'
  138. def report_download_webpage(self, video_id):
  139. """Report webpage download."""
  140. if not self._downloader.params.get('test', False):
  141. self._downloader.report_warning(u'Falling back on generic information extractor.')
  142. super(GenericIE, self).report_download_webpage(video_id)
  143. def report_following_redirect(self, new_url):
  144. """Report information extraction."""
  145. self._downloader.to_screen(u'[redirect] Following redirect to %s' % new_url)
  146. def _test_redirect(self, url):
  147. """Check if it is a redirect, like url shorteners, in case return the new url."""
  148. class HeadRequest(compat_urllib_request.Request):
  149. def get_method(self):
  150. return "HEAD"
  151. class HEADRedirectHandler(compat_urllib_request.HTTPRedirectHandler):
  152. """
  153. Subclass the HTTPRedirectHandler to make it use our
  154. HeadRequest also on the redirected URL
  155. """
  156. def redirect_request(self, req, fp, code, msg, headers, newurl):
  157. if code in (301, 302, 303, 307):
  158. newurl = newurl.replace(' ', '%20')
  159. newheaders = dict((k,v) for k,v in req.headers.items()
  160. if k.lower() not in ("content-length", "content-type"))
  161. return HeadRequest(newurl,
  162. headers=newheaders,
  163. origin_req_host=req.get_origin_req_host(),
  164. unverifiable=True)
  165. else:
  166. raise compat_urllib_error.HTTPError(req.get_full_url(), code, msg, headers, fp)
  167. class HTTPMethodFallback(compat_urllib_request.BaseHandler):
  168. """
  169. Fallback to GET if HEAD is not allowed (405 HTTP error)
  170. """
  171. def http_error_405(self, req, fp, code, msg, headers):
  172. fp.read()
  173. fp.close()
  174. newheaders = dict((k,v) for k,v in req.headers.items()
  175. if k.lower() not in ("content-length", "content-type"))
  176. return self.parent.open(compat_urllib_request.Request(req.get_full_url(),
  177. headers=newheaders,
  178. origin_req_host=req.get_origin_req_host(),
  179. unverifiable=True))
  180. # Build our opener
  181. opener = compat_urllib_request.OpenerDirector()
  182. for handler in [compat_urllib_request.HTTPHandler, compat_urllib_request.HTTPDefaultErrorHandler,
  183. HTTPMethodFallback, HEADRedirectHandler,
  184. compat_urllib_request.HTTPErrorProcessor, compat_urllib_request.HTTPSHandler]:
  185. opener.add_handler(handler())
  186. response = opener.open(HeadRequest(url))
  187. if response is None:
  188. raise ExtractorError(u'Invalid URL protocol')
  189. new_url = response.geturl()
  190. if url == new_url:
  191. return False
  192. self.report_following_redirect(new_url)
  193. return new_url
  194. def _real_extract(self, url):
  195. new_url = self._test_redirect(url)
  196. if new_url: return [self.url_result(new_url)]
  197. video_id = url.split('/')[-1]
  198. try:
  199. webpage = self._download_webpage(url, video_id)
  200. except ValueError as err:
  201. # since this is the last-resort InfoExtractor, if
  202. # this error is thrown, it'll be thrown here
  203. raise ExtractorError(u'Invalid URL: %s' % url)
  204. self.report_extraction(video_id)
  205. # Start with something easy: JW Player in SWFObject
  206. mobj = re.search(r'flashvars: [\'"](?:.*&)?file=(http[^\'"&]*)', webpage)
  207. if mobj is None:
  208. # Broaden the search a little bit
  209. mobj = re.search(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)', webpage)
  210. if mobj is None:
  211. # Broaden the search a little bit: JWPlayer JS loader
  212. mobj = re.search(r'[^A-Za-z0-9]?file:\s*["\'](http[^\'"&]*)', webpage)
  213. if mobj is None:
  214. # Try to find twitter cards info
  215. mobj = re.search(r'<meta (?:property|name)="twitter:player:stream" (?:content|value)="(.+?)"', webpage)
  216. if mobj is None:
  217. # We look for Open Graph info:
  218. # We have to match any number spaces between elements, some sites try to align them (eg.: statigr.am)
  219. m_video_type = re.search(r'<meta.*?property="og:video:type".*?content="video/(.*?)"', webpage)
  220. # We only look in og:video if the MIME type is a video, don't try if it's a Flash player:
  221. if m_video_type is not None:
  222. mobj = re.search(r'<meta.*?property="og:video".*?content="(.*?)"', webpage)
  223. if mobj is None:
  224. raise ExtractorError(u'Invalid URL: %s' % url)
  225. # It's possible that one of the regexes
  226. # matched, but returned an empty group:
  227. if mobj.group(1) is None:
  228. raise ExtractorError(u'Invalid URL: %s' % url)
  229. video_url = compat_urllib_parse.unquote(mobj.group(1))
  230. video_id = os.path.basename(video_url)
  231. # here's a fun little line of code for you:
  232. video_extension = os.path.splitext(video_id)[1][1:]
  233. video_id = os.path.splitext(video_id)[0]
  234. # it's tempting to parse this further, but you would
  235. # have to take into account all the variations like
  236. # Video Title - Site Name
  237. # Site Name | Video Title
  238. # Video Title - Tagline | Site Name
  239. # and so on and so forth; it's just not practical
  240. video_title = self._html_search_regex(r'<title>(.*)</title>',
  241. webpage, u'video title')
  242. # video uploader is domain name
  243. video_uploader = self._search_regex(r'(?:https?://)?([^/]*)/.*',
  244. url, u'video uploader')
  245. return [{
  246. 'id': video_id,
  247. 'url': video_url,
  248. 'uploader': video_uploader,
  249. 'upload_date': None,
  250. 'title': video_title,
  251. 'ext': video_extension,
  252. }]
  253. class YoutubeSearchIE(SearchInfoExtractor):
  254. """Information Extractor for YouTube search queries."""
  255. _API_URL = 'https://gdata.youtube.com/feeds/api/videos?q=%s&start-index=%i&max-results=50&v=2&alt=jsonc'
  256. _MAX_RESULTS = 1000
  257. IE_NAME = u'youtube:search'
  258. _SEARCH_KEY = 'ytsearch'
  259. def report_download_page(self, query, pagenum):
  260. """Report attempt to download search page with given number."""
  261. self._downloader.to_screen(u'[youtube] query "%s": Downloading page %s' % (query, pagenum))
  262. def _get_n_results(self, query, n):
  263. """Get a specified number of results for a query"""
  264. video_ids = []
  265. pagenum = 0
  266. limit = n
  267. while (50 * pagenum) < limit:
  268. self.report_download_page(query, pagenum+1)
  269. result_url = self._API_URL % (compat_urllib_parse.quote_plus(query), (50*pagenum)+1)
  270. request = compat_urllib_request.Request(result_url)
  271. try:
  272. data = compat_urllib_request.urlopen(request).read().decode('utf-8')
  273. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  274. raise ExtractorError(u'Unable to download API page: %s' % compat_str(err))
  275. api_response = json.loads(data)['data']
  276. if not 'items' in api_response:
  277. raise ExtractorError(u'[youtube] No video results')
  278. new_ids = list(video['id'] for video in api_response['items'])
  279. video_ids += new_ids
  280. limit = min(n, api_response['totalItems'])
  281. pagenum += 1
  282. if len(video_ids) > n:
  283. video_ids = video_ids[:n]
  284. videos = [self.url_result('http://www.youtube.com/watch?v=%s' % id, 'Youtube') for id in video_ids]
  285. return self.playlist_result(videos, query)
  286. class GoogleSearchIE(SearchInfoExtractor):
  287. """Information Extractor for Google Video search queries."""
  288. _MORE_PAGES_INDICATOR = r'id="pnnext" class="pn"'
  289. _MAX_RESULTS = 1000
  290. IE_NAME = u'video.google:search'
  291. _SEARCH_KEY = 'gvsearch'
  292. def _get_n_results(self, query, n):
  293. """Get a specified number of results for a query"""
  294. res = {
  295. '_type': 'playlist',
  296. 'id': query,
  297. 'entries': []
  298. }
  299. for pagenum in itertools.count(1):
  300. result_url = u'http://www.google.com/search?tbm=vid&q=%s&start=%s&hl=en' % (compat_urllib_parse.quote_plus(query), pagenum*10)
  301. webpage = self._download_webpage(result_url, u'gvsearch:' + query,
  302. note='Downloading result page ' + str(pagenum))
  303. for mobj in re.finditer(r'<h3 class="r"><a href="([^"]+)"', webpage):
  304. e = {
  305. '_type': 'url',
  306. 'url': mobj.group(1)
  307. }
  308. res['entries'].append(e)
  309. if (pagenum * 10 > n) or not re.search(self._MORE_PAGES_INDICATOR, webpage):
  310. return res
  311. class YahooSearchIE(SearchInfoExtractor):
  312. """Information Extractor for Yahoo! Video search queries."""
  313. _MAX_RESULTS = 1000
  314. IE_NAME = u'screen.yahoo:search'
  315. _SEARCH_KEY = 'yvsearch'
  316. def _get_n_results(self, query, n):
  317. """Get a specified number of results for a query"""
  318. res = {
  319. '_type': 'playlist',
  320. 'id': query,
  321. 'entries': []
  322. }
  323. for pagenum in itertools.count(0):
  324. result_url = u'http://video.search.yahoo.com/search/?p=%s&fr=screen&o=js&gs=0&b=%d' % (compat_urllib_parse.quote_plus(query), pagenum * 30)
  325. webpage = self._download_webpage(result_url, query,
  326. note='Downloading results page '+str(pagenum+1))
  327. info = json.loads(webpage)
  328. m = info[u'm']
  329. results = info[u'results']
  330. for (i, r) in enumerate(results):
  331. if (pagenum * 30) +i >= n:
  332. break
  333. mobj = re.search(r'(?P<url>screen\.yahoo\.com/.*?-\d*?\.html)"', r)
  334. e = self.url_result('http://' + mobj.group('url'), 'Yahoo')
  335. res['entries'].append(e)
  336. if (pagenum * 30 +i >= n) or (m[u'last'] >= (m[u'total'] -1 )):
  337. break
  338. return res
  339. class BlipTVUserIE(InfoExtractor):
  340. """Information Extractor for blip.tv users."""
  341. _VALID_URL = r'(?:(?:(?:https?://)?(?:\w+\.)?blip\.tv/)|bliptvuser:)([^/]+)/*$'
  342. _PAGE_SIZE = 12
  343. IE_NAME = u'blip.tv:user'
  344. def _real_extract(self, url):
  345. # Extract username
  346. mobj = re.match(self._VALID_URL, url)
  347. if mobj is None:
  348. raise ExtractorError(u'Invalid URL: %s' % url)
  349. username = mobj.group(1)
  350. page_base = 'http://m.blip.tv/pr/show_get_full_episode_list?users_id=%s&lite=0&esi=1'
  351. page = self._download_webpage(url, username, u'Downloading user page')
  352. mobj = re.search(r'data-users-id="([^"]+)"', page)
  353. page_base = page_base % mobj.group(1)
  354. # Download video ids using BlipTV Ajax calls. Result size per
  355. # query is limited (currently to 12 videos) so we need to query
  356. # page by page until there are no video ids - it means we got
  357. # all of them.
  358. video_ids = []
  359. pagenum = 1
  360. while True:
  361. url = page_base + "&page=" + str(pagenum)
  362. page = self._download_webpage(url, username,
  363. u'Downloading video ids from page %d' % pagenum)
  364. # Extract video identifiers
  365. ids_in_page = []
  366. for mobj in re.finditer(r'href="/([^"]+)"', page):
  367. if mobj.group(1) not in ids_in_page:
  368. ids_in_page.append(unescapeHTML(mobj.group(1)))
  369. video_ids.extend(ids_in_page)
  370. # A little optimization - if current page is not
  371. # "full", ie. does not contain PAGE_SIZE video ids then
  372. # we can assume that this page is the last one - there
  373. # are no more ids on further pages - no need to query
  374. # again.
  375. if len(ids_in_page) < self._PAGE_SIZE:
  376. break
  377. pagenum += 1
  378. urls = [u'http://blip.tv/%s' % video_id for video_id in video_ids]
  379. url_entries = [self.url_result(url, 'BlipTV') for url in urls]
  380. return [self.playlist_result(url_entries, playlist_title = username)]
  381. class DepositFilesIE(InfoExtractor):
  382. """Information extractor for depositfiles.com"""
  383. _VALID_URL = r'(?:http://)?(?:\w+\.)?depositfiles\.com/(?:../(?#locale))?files/(.+)'
  384. def _real_extract(self, url):
  385. file_id = url.split('/')[-1]
  386. # Rebuild url in english locale
  387. url = 'http://depositfiles.com/en/files/' + file_id
  388. # Retrieve file webpage with 'Free download' button pressed
  389. free_download_indication = { 'gateway_result' : '1' }
  390. request = compat_urllib_request.Request(url, compat_urllib_parse.urlencode(free_download_indication))
  391. try:
  392. self.report_download_webpage(file_id)
  393. webpage = compat_urllib_request.urlopen(request).read()
  394. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  395. raise ExtractorError(u'Unable to retrieve file webpage: %s' % compat_str(err))
  396. # Search for the real file URL
  397. mobj = re.search(r'<form action="(http://fileshare.+?)"', webpage)
  398. if (mobj is None) or (mobj.group(1) is None):
  399. # Try to figure out reason of the error.
  400. mobj = re.search(r'<strong>(Attention.*?)</strong>', webpage, re.DOTALL)
  401. if (mobj is not None) and (mobj.group(1) is not None):
  402. restriction_message = re.sub('\s+', ' ', mobj.group(1)).strip()
  403. raise ExtractorError(u'%s' % restriction_message)
  404. else:
  405. raise ExtractorError(u'Unable to extract download URL from: %s' % url)
  406. file_url = mobj.group(1)
  407. file_extension = os.path.splitext(file_url)[1][1:]
  408. # Search for file title
  409. file_title = self._search_regex(r'<b title="(.*?)">', webpage, u'title')
  410. return [{
  411. 'id': file_id.decode('utf-8'),
  412. 'url': file_url.decode('utf-8'),
  413. 'uploader': None,
  414. 'upload_date': None,
  415. 'title': file_title,
  416. 'ext': file_extension.decode('utf-8'),
  417. }]
  418. class FacebookIE(InfoExtractor):
  419. """Information Extractor for Facebook"""
  420. _VALID_URL = r'^(?:https?://)?(?:\w+\.)?facebook\.com/(?:video/video|photo)\.php\?(?:.*?)v=(?P<ID>\d+)(?:.*)'
  421. _LOGIN_URL = 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php&'
  422. _NETRC_MACHINE = 'facebook'
  423. IE_NAME = u'facebook'
  424. def report_login(self):
  425. """Report attempt to log in."""
  426. self.to_screen(u'Logging in')
  427. def _real_initialize(self):
  428. if self._downloader is None:
  429. return
  430. useremail = None
  431. password = None
  432. downloader_params = self._downloader.params
  433. # Attempt to use provided username and password or .netrc data
  434. if downloader_params.get('username', None) is not None:
  435. useremail = downloader_params['username']
  436. password = downloader_params['password']
  437. elif downloader_params.get('usenetrc', False):
  438. try:
  439. info = netrc.netrc().authenticators(self._NETRC_MACHINE)
  440. if info is not None:
  441. useremail = info[0]
  442. password = info[2]
  443. else:
  444. raise netrc.NetrcParseError('No authenticators for %s' % self._NETRC_MACHINE)
  445. except (IOError, netrc.NetrcParseError) as err:
  446. self._downloader.report_warning(u'parsing .netrc: %s' % compat_str(err))
  447. return
  448. if useremail is None:
  449. return
  450. # Log in
  451. login_form = {
  452. 'email': useremail,
  453. 'pass': password,
  454. 'login': 'Log+In'
  455. }
  456. request = compat_urllib_request.Request(self._LOGIN_URL, compat_urllib_parse.urlencode(login_form))
  457. try:
  458. self.report_login()
  459. login_results = compat_urllib_request.urlopen(request).read()
  460. if re.search(r'<form(.*)name="login"(.*)</form>', login_results) is not None:
  461. self._downloader.report_warning(u'unable to log in: bad username/password, or exceded login rate limit (~3/min). Check credentials or wait.')
  462. return
  463. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  464. self._downloader.report_warning(u'unable to log in: %s' % compat_str(err))
  465. return
  466. def _real_extract(self, url):
  467. mobj = re.match(self._VALID_URL, url)
  468. if mobj is None:
  469. raise ExtractorError(u'Invalid URL: %s' % url)
  470. video_id = mobj.group('ID')
  471. url = 'https://www.facebook.com/video/video.php?v=%s' % video_id
  472. webpage = self._download_webpage(url, video_id)
  473. BEFORE = '{swf.addParam(param[0], param[1]);});\n'
  474. AFTER = '.forEach(function(variable) {swf.addVariable(variable[0], variable[1]);});'
  475. m = re.search(re.escape(BEFORE) + '(.*?)' + re.escape(AFTER), webpage)
  476. if not m:
  477. raise ExtractorError(u'Cannot parse data')
  478. data = dict(json.loads(m.group(1)))
  479. params_raw = compat_urllib_parse.unquote(data['params'])
  480. params = json.loads(params_raw)
  481. video_data = params['video_data'][0]
  482. video_url = video_data.get('hd_src')
  483. if not video_url:
  484. video_url = video_data['sd_src']
  485. if not video_url:
  486. raise ExtractorError(u'Cannot find video URL')
  487. video_duration = int(video_data['video_duration'])
  488. thumbnail = video_data['thumbnail_src']
  489. video_title = self._html_search_regex('<h2 class="uiHeaderTitle">([^<]+)</h2>',
  490. webpage, u'title')
  491. info = {
  492. 'id': video_id,
  493. 'title': video_title,
  494. 'url': video_url,
  495. 'ext': 'mp4',
  496. 'duration': video_duration,
  497. 'thumbnail': thumbnail,
  498. }
  499. return [info]
  500. class BlipTVIE(InfoExtractor):
  501. """Information extractor for blip.tv"""
  502. _VALID_URL = r'^(?:https?://)?(?:\w+\.)?blip\.tv/((.+/)|(play/)|(api\.swf#))(.+)$'
  503. _URL_EXT = r'^.*\.([a-z0-9]+)$'
  504. IE_NAME = u'blip.tv'
  505. def report_direct_download(self, title):
  506. """Report information extraction."""
  507. self.to_screen(u'%s: Direct download detected' % title)
  508. def _real_extract(self, url):
  509. mobj = re.match(self._VALID_URL, url)
  510. if mobj is None:
  511. raise ExtractorError(u'Invalid URL: %s' % url)
  512. # See https://github.com/rg3/youtube-dl/issues/857
  513. api_mobj = re.match(r'http://a\.blip\.tv/api\.swf#(?P<video_id>[\d\w]+)', url)
  514. if api_mobj is not None:
  515. url = 'http://blip.tv/play/g_%s' % api_mobj.group('video_id')
  516. urlp = compat_urllib_parse_urlparse(url)
  517. if urlp.path.startswith('/play/'):
  518. request = compat_urllib_request.Request(url)
  519. response = compat_urllib_request.urlopen(request)
  520. redirecturl = response.geturl()
  521. rurlp = compat_urllib_parse_urlparse(redirecturl)
  522. file_id = compat_parse_qs(rurlp.fragment)['file'][0].rpartition('/')[2]
  523. url = 'http://blip.tv/a/a-' + file_id
  524. return self._real_extract(url)
  525. if '?' in url:
  526. cchar = '&'
  527. else:
  528. cchar = '?'
  529. json_url = url + cchar + 'skin=json&version=2&no_wrap=1'
  530. request = compat_urllib_request.Request(json_url)
  531. request.add_header('User-Agent', 'iTunes/10.6.1')
  532. self.report_extraction(mobj.group(1))
  533. info = None
  534. try:
  535. urlh = compat_urllib_request.urlopen(request)
  536. if urlh.headers.get('Content-Type', '').startswith('video/'): # Direct download
  537. basename = url.split('/')[-1]
  538. title,ext = os.path.splitext(basename)
  539. title = title.decode('UTF-8')
  540. ext = ext.replace('.', '')
  541. self.report_direct_download(title)
  542. info = {
  543. 'id': title,
  544. 'url': url,
  545. 'uploader': None,
  546. 'upload_date': None,
  547. 'title': title,
  548. 'ext': ext,
  549. 'urlhandle': urlh
  550. }
  551. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  552. raise ExtractorError(u'ERROR: unable to download video info webpage: %s' % compat_str(err))
  553. if info is None: # Regular URL
  554. try:
  555. json_code_bytes = urlh.read()
  556. json_code = json_code_bytes.decode('utf-8')
  557. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  558. raise ExtractorError(u'Unable to read video info webpage: %s' % compat_str(err))
  559. try:
  560. json_data = json.loads(json_code)
  561. if 'Post' in json_data:
  562. data = json_data['Post']
  563. else:
  564. data = json_data
  565. upload_date = datetime.datetime.strptime(data['datestamp'], '%m-%d-%y %H:%M%p').strftime('%Y%m%d')
  566. video_url = data['media']['url']
  567. umobj = re.match(self._URL_EXT, video_url)
  568. if umobj is None:
  569. raise ValueError('Can not determine filename extension')
  570. ext = umobj.group(1)
  571. info = {
  572. 'id': data['item_id'],
  573. 'url': video_url,
  574. 'uploader': data['display_name'],
  575. 'upload_date': upload_date,
  576. 'title': data['title'],
  577. 'ext': ext,
  578. 'format': data['media']['mimeType'],
  579. 'thumbnail': data['thumbnailUrl'],
  580. 'description': data['description'],
  581. 'player_url': data['embedUrl'],
  582. 'user_agent': 'iTunes/10.6.1',
  583. }
  584. except (ValueError,KeyError) as err:
  585. raise ExtractorError(u'Unable to parse video information: %s' % repr(err))
  586. return [info]
  587. class MyVideoIE(InfoExtractor):
  588. """Information Extractor for myvideo.de."""
  589. _VALID_URL = r'(?:http://)?(?:www\.)?myvideo\.de/watch/([0-9]+)/([^?/]+).*'
  590. IE_NAME = u'myvideo'
  591. # Original Code from: https://github.com/dersphere/plugin.video.myvideo_de.git
  592. # Released into the Public Domain by Tristan Fischer on 2013-05-19
  593. # https://github.com/rg3/youtube-dl/pull/842
  594. def __rc4crypt(self,data, key):
  595. x = 0
  596. box = list(range(256))
  597. for i in list(range(256)):
  598. x = (x + box[i] + compat_ord(key[i % len(key)])) % 256
  599. box[i], box[x] = box[x], box[i]
  600. x = 0
  601. y = 0
  602. out = ''
  603. for char in data:
  604. x = (x + 1) % 256
  605. y = (y + box[x]) % 256
  606. box[x], box[y] = box[y], box[x]
  607. out += chr(compat_ord(char) ^ box[(box[x] + box[y]) % 256])
  608. return out
  609. def __md5(self,s):
  610. return hashlib.md5(s).hexdigest().encode()
  611. def _real_extract(self,url):
  612. mobj = re.match(self._VALID_URL, url)
  613. if mobj is None:
  614. raise ExtractorError(u'invalid URL: %s' % url)
  615. video_id = mobj.group(1)
  616. GK = (
  617. b'WXpnME1EZGhNRGhpTTJNM01XVmhOREU0WldNNVpHTTJOakpt'
  618. b'TW1FMU5tVTBNR05pWkRaa05XRXhNVFJoWVRVd1ptSXhaVEV3'
  619. b'TnpsbA0KTVRkbU1tSTRNdz09'
  620. )
  621. # Get video webpage
  622. webpage_url = 'http://www.myvideo.de/watch/%s' % video_id
  623. webpage = self._download_webpage(webpage_url, video_id)
  624. mobj = re.search('source src=\'(.+?)[.]([^.]+)\'', webpage)
  625. if mobj is not None:
  626. self.report_extraction(video_id)
  627. video_url = mobj.group(1) + '.flv'
  628. video_title = self._html_search_regex('<title>([^<]+)</title>',
  629. webpage, u'title')
  630. video_ext = self._search_regex('[.](.+?)$', video_url, u'extension')
  631. return [{
  632. 'id': video_id,
  633. 'url': video_url,
  634. 'uploader': None,
  635. 'upload_date': None,
  636. 'title': video_title,
  637. 'ext': u'flv',
  638. }]
  639. # try encxml
  640. mobj = re.search('var flashvars={(.+?)}', webpage)
  641. if mobj is None:
  642. raise ExtractorError(u'Unable to extract video')
  643. params = {}
  644. encxml = ''
  645. sec = mobj.group(1)
  646. for (a, b) in re.findall('(.+?):\'(.+?)\',?', sec):
  647. if not a == '_encxml':
  648. params[a] = b
  649. else:
  650. encxml = compat_urllib_parse.unquote(b)
  651. if not params.get('domain'):
  652. params['domain'] = 'www.myvideo.de'
  653. xmldata_url = '%s?%s' % (encxml, compat_urllib_parse.urlencode(params))
  654. if 'flash_playertype=MTV' in xmldata_url:
  655. self._downloader.report_warning(u'avoiding MTV player')
  656. xmldata_url = (
  657. 'http://www.myvideo.de/dynamic/get_player_video_xml.php'
  658. '?flash_playertype=D&ID=%s&_countlimit=4&autorun=yes'
  659. ) % video_id
  660. # get enc data
  661. enc_data = self._download_webpage(xmldata_url, video_id).split('=')[1]
  662. enc_data_b = binascii.unhexlify(enc_data)
  663. sk = self.__md5(
  664. base64.b64decode(base64.b64decode(GK)) +
  665. self.__md5(
  666. str(video_id).encode('utf-8')
  667. )
  668. )
  669. dec_data = self.__rc4crypt(enc_data_b, sk)
  670. # extracting infos
  671. self.report_extraction(video_id)
  672. video_url = None
  673. mobj = re.search('connectionurl=\'(.*?)\'', dec_data)
  674. if mobj:
  675. video_url = compat_urllib_parse.unquote(mobj.group(1))
  676. if 'myvideo2flash' in video_url:
  677. self._downloader.report_warning(u'forcing RTMPT ...')
  678. video_url = video_url.replace('rtmpe://', 'rtmpt://')
  679. if not video_url:
  680. # extract non rtmp videos
  681. mobj = re.search('path=\'(http.*?)\' source=\'(.*?)\'', dec_data)
  682. if mobj is None:
  683. raise ExtractorError(u'unable to extract url')
  684. video_url = compat_urllib_parse.unquote(mobj.group(1)) + compat_urllib_parse.unquote(mobj.group(2))
  685. video_file = self._search_regex('source=\'(.*?)\'', dec_data, u'video file')
  686. video_file = compat_urllib_parse.unquote(video_file)
  687. if not video_file.endswith('f4m'):
  688. ppath, prefix = video_file.split('.')
  689. video_playpath = '%s:%s' % (prefix, ppath)
  690. video_hls_playlist = ''
  691. else:
  692. video_playpath = ''
  693. video_hls_playlist = (
  694. video_filepath + video_file
  695. ).replace('.f4m', '.m3u8')
  696. video_swfobj = self._search_regex('swfobject.embedSWF\(\'(.+?)\'', webpage, u'swfobj')
  697. video_swfobj = compat_urllib_parse.unquote(video_swfobj)
  698. video_title = self._html_search_regex("<h1(?: class='globalHd')?>(.*?)</h1>",
  699. webpage, u'title')
  700. return [{
  701. 'id': video_id,
  702. 'url': video_url,
  703. 'tc_url': video_url,
  704. 'uploader': None,
  705. 'upload_date': None,
  706. 'title': video_title,
  707. 'ext': u'flv',
  708. 'play_path': video_playpath,
  709. 'video_file': video_file,
  710. 'video_hls_playlist': video_hls_playlist,
  711. 'player_url': video_swfobj,
  712. }]
  713. class ComedyCentralIE(InfoExtractor):
  714. """Information extractor for The Daily Show and Colbert Report """
  715. # urls can be abbreviations like :thedailyshow or :colbert
  716. # urls for episodes like:
  717. # or urls for clips like: http://www.thedailyshow.com/watch/mon-december-10-2012/any-given-gun-day
  718. # or: http://www.colbertnation.com/the-colbert-report-videos/421667/november-29-2012/moon-shattering-news
  719. # or: http://www.colbertnation.com/the-colbert-report-collections/422008/festival-of-lights/79524
  720. _VALID_URL = r"""^(:(?P<shortname>tds|thedailyshow|cr|colbert|colbertnation|colbertreport)
  721. |(https?://)?(www\.)?
  722. (?P<showname>thedailyshow|colbertnation)\.com/
  723. (full-episodes/(?P<episode>.*)|
  724. (?P<clip>
  725. (the-colbert-report-(videos|collections)/(?P<clipID>[0-9]+)/[^/]*/(?P<cntitle>.*?))
  726. |(watch/(?P<date>[^/]*)/(?P<tdstitle>.*)))))
  727. $"""
  728. _available_formats = ['3500', '2200', '1700', '1200', '750', '400']
  729. _video_extensions = {
  730. '3500': 'mp4',
  731. '2200': 'mp4',
  732. '1700': 'mp4',
  733. '1200': 'mp4',
  734. '750': 'mp4',
  735. '400': 'mp4',
  736. }
  737. _video_dimensions = {
  738. '3500': '1280x720',
  739. '2200': '960x540',
  740. '1700': '768x432',
  741. '1200': '640x360',
  742. '750': '512x288',
  743. '400': '384x216',
  744. }
  745. @classmethod
  746. def suitable(cls, url):
  747. """Receives a URL and returns True if suitable for this IE."""
  748. return re.match(cls._VALID_URL, url, re.VERBOSE) is not None
  749. def _print_formats(self, formats):
  750. print('Available formats:')
  751. for x in formats:
  752. print('%s\t:\t%s\t[%s]' %(x, self._video_extensions.get(x, 'mp4'), self._video_dimensions.get(x, '???')))
  753. def _real_extract(self, url):
  754. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  755. if mobj is None:
  756. raise ExtractorError(u'Invalid URL: %s' % url)
  757. if mobj.group('shortname'):
  758. if mobj.group('shortname') in ('tds', 'thedailyshow'):
  759. url = u'http://www.thedailyshow.com/full-episodes/'
  760. else:
  761. url = u'http://www.colbertnation.com/full-episodes/'
  762. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  763. assert mobj is not None
  764. if mobj.group('clip'):
  765. if mobj.group('showname') == 'thedailyshow':
  766. epTitle = mobj.group('tdstitle')
  767. else:
  768. epTitle = mobj.group('cntitle')
  769. dlNewest = False
  770. else:
  771. dlNewest = not mobj.group('episode')
  772. if dlNewest:
  773. epTitle = mobj.group('showname')
  774. else:
  775. epTitle = mobj.group('episode')
  776. self.report_extraction(epTitle)
  777. webpage,htmlHandle = self._download_webpage_handle(url, epTitle)
  778. if dlNewest:
  779. url = htmlHandle.geturl()
  780. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  781. if mobj is None:
  782. raise ExtractorError(u'Invalid redirected URL: ' + url)
  783. if mobj.group('episode') == '':
  784. raise ExtractorError(u'Redirected URL is still not specific: ' + url)
  785. epTitle = mobj.group('episode')
  786. mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage)
  787. if len(mMovieParams) == 0:
  788. # The Colbert Report embeds the information in a without
  789. # a URL prefix; so extract the alternate reference
  790. # and then add the URL prefix manually.
  791. altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video).*?:.*?)"', webpage)
  792. if len(altMovieParams) == 0:
  793. raise ExtractorError(u'unable to find Flash URL in webpage ' + url)
  794. else:
  795. mMovieParams = [("http://media.mtvnservices.com/" + altMovieParams[0], altMovieParams[0])]
  796. uri = mMovieParams[0][1]
  797. indexUrl = 'http://shadow.comedycentral.com/feeds/video_player/mrss/?' + compat_urllib_parse.urlencode({'uri': uri})
  798. indexXml = self._download_webpage(indexUrl, epTitle,
  799. u'Downloading show index',
  800. u'unable to download episode index')
  801. results = []
  802. idoc = xml.etree.ElementTree.fromstring(indexXml)
  803. itemEls = idoc.findall('.//item')
  804. for partNum,itemEl in enumerate(itemEls):
  805. mediaId = itemEl.findall('./guid')[0].text
  806. shortMediaId = mediaId.split(':')[-1]
  807. showId = mediaId.split(':')[-2].replace('.com', '')
  808. officialTitle = itemEl.findall('./title')[0].text
  809. officialDate = unified_strdate(itemEl.findall('./pubDate')[0].text)
  810. configUrl = ('http://www.comedycentral.com/global/feeds/entertainment/media/mediaGenEntertainment.jhtml?' +
  811. compat_urllib_parse.urlencode({'uri': mediaId}))
  812. configXml = self._download_webpage(configUrl, epTitle,
  813. u'Downloading configuration for %s' % shortMediaId)
  814. cdoc = xml.etree.ElementTree.fromstring(configXml)
  815. turls = []
  816. for rendition in cdoc.findall('.//rendition'):
  817. finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text)
  818. turls.append(finfo)
  819. if len(turls) == 0:
  820. self._downloader.report_error(u'unable to download ' + mediaId + ': No videos found')
  821. continue
  822. if self._downloader.params.get('listformats', None):
  823. self._print_formats([i[0] for i in turls])
  824. return
  825. # For now, just pick the highest bitrate
  826. format,rtmp_video_url = turls[-1]
  827. # Get the format arg from the arg stream
  828. req_format = self._downloader.params.get('format', None)
  829. # Select format if we can find one
  830. for f,v in turls:
  831. if f == req_format:
  832. format, rtmp_video_url = f, v
  833. break
  834. m = re.match(r'^rtmpe?://.*?/(?P<finalid>gsp.comedystor/.*)$', rtmp_video_url)
  835. if not m:
  836. raise ExtractorError(u'Cannot transform RTMP url')
  837. base = 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=1+_pxI0=Ripod-h264+_pxL0=undefined+_pxM0=+_pxK=18639+_pxE=mp4/44620/mtvnorigin/'
  838. video_url = base + m.group('finalid')
  839. effTitle = showId + u'-' + epTitle + u' part ' + compat_str(partNum+1)
  840. info = {
  841. 'id': shortMediaId,
  842. 'url': video_url,
  843. 'uploader': showId,
  844. 'upload_date': officialDate,
  845. 'title': effTitle,
  846. 'ext': 'mp4',
  847. 'format': format,
  848. 'thumbnail': None,
  849. 'description': officialTitle,
  850. }
  851. results.append(info)
  852. return results
  853. class EscapistIE(InfoExtractor):
  854. """Information extractor for The Escapist """
  855. _VALID_URL = r'^(https?://)?(www\.)?escapistmagazine\.com/videos/view/(?P<showname>[^/]+)/(?P<episode>[^/?]+)[/?]?.*$'
  856. IE_NAME = u'escapist'
  857. def _real_extract(self, url):
  858. mobj = re.match(self._VALID_URL, url)
  859. if mobj is None:
  860. raise ExtractorError(u'Invalid URL: %s' % url)
  861. showName = mobj.group('showname')
  862. videoId = mobj.group('episode')
  863. self.report_extraction(videoId)
  864. webpage = self._download_webpage(url, videoId)
  865. videoDesc = self._html_search_regex('<meta name="description" content="([^"]*)"',
  866. webpage, u'description', fatal=False)
  867. imgUrl = self._html_search_regex('<meta property="og:image" content="([^"]*)"',
  868. webpage, u'thumbnail', fatal=False)
  869. playerUrl = self._html_search_regex('<meta property="og:video" content="([^"]*)"',
  870. webpage, u'player url')
  871. title = self._html_search_regex('<meta name="title" content="([^"]*)"',
  872. webpage, u'player url').split(' : ')[-1]
  873. configUrl = self._search_regex('config=(.*)$', playerUrl, u'config url')
  874. configUrl = compat_urllib_parse.unquote(configUrl)
  875. configJSON = self._download_webpage(configUrl, videoId,
  876. u'Downloading configuration',
  877. u'unable to download configuration')
  878. # Technically, it's JavaScript, not JSON
  879. configJSON = configJSON.replace("'", '"')
  880. try:
  881. config = json.loads(configJSON)
  882. except (ValueError,) as err:
  883. raise ExtractorError(u'Invalid JSON in configuration file: ' + compat_str(err))
  884. playlist = config['playlist']
  885. videoUrl = playlist[1]['url']
  886. info = {
  887. 'id': videoId,
  888. 'url': videoUrl,
  889. 'uploader': showName,
  890. 'upload_date': None,
  891. 'title': title,
  892. 'ext': 'mp4',
  893. 'thumbnail': imgUrl,
  894. 'description': videoDesc,
  895. 'player_url': playerUrl,
  896. }
  897. return [info]
  898. class CollegeHumorIE(InfoExtractor):
  899. """Information extractor for collegehumor.com"""
  900. _WORKING = False
  901. _VALID_URL = r'^(?:https?://)?(?:www\.)?collegehumor\.com/video/(?P<videoid>[0-9]+)/(?P<shorttitle>.*)$'
  902. IE_NAME = u'collegehumor'
  903. def report_manifest(self, video_id):
  904. """Report information extraction."""
  905. self.to_screen(u'%s: Downloading XML manifest' % video_id)
  906. def _real_extract(self, url):
  907. mobj = re.match(self._VALID_URL, url)
  908. if mobj is None:
  909. raise ExtractorError(u'Invalid URL: %s' % url)
  910. video_id = mobj.group('videoid')
  911. info = {
  912. 'id': video_id,
  913. 'uploader': None,
  914. 'upload_date': None,
  915. }
  916. self.report_extraction(video_id)
  917. xmlUrl = 'http://www.collegehumor.com/moogaloop/video/' + video_id
  918. try:
  919. metaXml = compat_urllib_request.urlopen(xmlUrl).read()
  920. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  921. raise ExtractorError(u'Unable to download video info XML: %s' % compat_str(err))
  922. mdoc = xml.etree.ElementTree.fromstring(metaXml)
  923. try:
  924. videoNode = mdoc.findall('./video')[0]
  925. info['description'] = videoNode.findall('./description')[0].text
  926. info['title'] = videoNode.findall('./caption')[0].text
  927. info['thumbnail'] = videoNode.findall('./thumbnail')[0].text
  928. manifest_url = videoNode.findall('./file')[0].text
  929. except IndexError:
  930. raise ExtractorError(u'Invalid metadata XML file')
  931. manifest_url += '?hdcore=2.10.3'
  932. self.report_manifest(video_id)
  933. try:
  934. manifestXml = compat_urllib_request.urlopen(manifest_url).read()
  935. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  936. raise ExtractorError(u'Unable to download video info XML: %s' % compat_str(err))
  937. adoc = xml.etree.ElementTree.fromstring(manifestXml)
  938. try:
  939. media_node = adoc.findall('./{http://ns.adobe.com/f4m/1.0}media')[0]
  940. node_id = media_node.attrib['url']
  941. video_id = adoc.findall('./{http://ns.adobe.com/f4m/1.0}id')[0].text
  942. except IndexError as err:
  943. raise ExtractorError(u'Invalid manifest file')
  944. url_pr = compat_urllib_parse_urlparse(manifest_url)
  945. url = url_pr.scheme + '://' + url_pr.netloc + '/z' + video_id[:-2] + '/' + node_id + 'Seg1-Frag1'
  946. info['url'] = url
  947. info['ext'] = 'f4f'
  948. return [info]
  949. class XVideosIE(InfoExtractor):
  950. """Information extractor for xvideos.com"""
  951. _VALID_URL = r'^(?:https?://)?(?:www\.)?xvideos\.com/video([0-9]+)(?:.*)'
  952. IE_NAME = u'xvideos'
  953. def _real_extract(self, url):
  954. mobj = re.match(self._VALID_URL, url)
  955. if mobj is None:
  956. raise ExtractorError(u'Invalid URL: %s' % url)
  957. video_id = mobj.group(1)
  958. webpage = self._download_webpage(url, video_id)
  959. self.report_extraction(video_id)
  960. # Extract video URL
  961. video_url = compat_urllib_parse.unquote(self._search_regex(r'flv_url=(.+?)&',
  962. webpage, u'video URL'))
  963. # Extract title
  964. video_title = self._html_search_regex(r'<title>(.*?)\s+-\s+XVID',
  965. webpage, u'title')
  966. # Extract video thumbnail
  967. video_thumbnail = self._search_regex(r'http://(?:img.*?\.)xvideos.com/videos/thumbs/[a-fA-F0-9]+/[a-fA-F0-9]+/[a-fA-F0-9]+/[a-fA-F0-9]+/([a-fA-F0-9.]+jpg)',
  968. webpage, u'thumbnail', fatal=False)
  969. info = {
  970. 'id': video_id,
  971. 'url': video_url,
  972. 'uploader': None,
  973. 'upload_date': None,
  974. 'title': video_title,
  975. 'ext': 'flv',
  976. 'thumbnail': video_thumbnail,
  977. 'description': None,
  978. }
  979. return [info]
  980. class SoundcloudIE(InfoExtractor):
  981. """Information extractor for soundcloud.com
  982. To access the media, the uid of the song and a stream token
  983. must be extracted from the page source and the script must make
  984. a request to media.soundcloud.com/crossdomain.xml. Then
  985. the media can be grabbed by requesting from an url composed
  986. of the stream token and uid
  987. """
  988. _VALID_URL = r'^(?:https?://)?(?:www\.)?soundcloud\.com/([\w\d-]+)/([\w\d-]+)'
  989. IE_NAME = u'soundcloud'
  990. def report_resolve(self, video_id):
  991. """Report information extraction."""
  992. self.to_screen(u'%s: Resolving id' % video_id)
  993. def _real_extract(self, url):
  994. mobj = re.match(self._VALID_URL, url)
  995. if mobj is None:
  996. raise ExtractorError(u'Invalid URL: %s' % url)
  997. # extract uploader (which is in the url)
  998. uploader = mobj.group(1)
  999. # extract simple title (uploader + slug of song title)
  1000. slug_title = mobj.group(2)
  1001. simple_title = uploader + u'-' + slug_title
  1002. full_title = '%s/%s' % (uploader, slug_title)
  1003. self.report_resolve(full_title)
  1004. url = 'http://soundcloud.com/%s/%s' % (uploader, slug_title)
  1005. resolv_url = 'http://api.soundcloud.com/resolve.json?url=' + url + '&client_id=b45b1aa10f1ac2941910a7f0d10f8e28'
  1006. info_json = self._download_webpage(resolv_url, full_title, u'Downloading info JSON')
  1007. info = json.loads(info_json)
  1008. video_id = info['id']
  1009. self.report_extraction(full_title)
  1010. streams_url = 'https://api.sndcdn.com/i1/tracks/' + str(video_id) + '/streams?client_id=b45b1aa10f1ac2941910a7f0d10f8e28'
  1011. stream_json = self._download_webpage(streams_url, full_title,
  1012. u'Downloading stream definitions',
  1013. u'unable to download stream definitions')
  1014. streams = json.loads(stream_json)
  1015. mediaURL = streams['http_mp3_128_url']
  1016. upload_date = unified_strdate(info['created_at'])
  1017. return [{
  1018. 'id': info['id'],
  1019. 'url': mediaURL,
  1020. 'uploader': info['user']['username'],
  1021. 'upload_date': upload_date,
  1022. 'title': info['title'],
  1023. 'ext': u'mp3',
  1024. 'description': info['description'],
  1025. }]
  1026. class SoundcloudSetIE(InfoExtractor):
  1027. """Information extractor for soundcloud.com sets
  1028. To access the media, the uid of the song and a stream token
  1029. must be extracted from the page source and the script must make
  1030. a request to media.soundcloud.com/crossdomain.xml. Then
  1031. the media can be grabbed by requesting from an url composed
  1032. of the stream token and uid
  1033. """
  1034. _VALID_URL = r'^(?:https?://)?(?:www\.)?soundcloud\.com/([\w\d-]+)/sets/([\w\d-]+)'
  1035. IE_NAME = u'soundcloud:set'
  1036. def report_resolve(self, video_id):
  1037. """Report information extraction."""
  1038. self.to_screen(u'%s: Resolving id' % video_id)
  1039. def _real_extract(self, url):
  1040. mobj = re.match(self._VALID_URL, url)
  1041. if mobj is None:
  1042. raise ExtractorError(u'Invalid URL: %s' % url)
  1043. # extract uploader (which is in the url)
  1044. uploader = mobj.group(1)
  1045. # extract simple title (uploader + slug of song title)
  1046. slug_title = mobj.group(2)
  1047. simple_title = uploader + u'-' + slug_title
  1048. full_title = '%s/sets/%s' % (uploader, slug_title)
  1049. self.report_resolve(full_title)
  1050. url = 'http://soundcloud.com/%s/sets/%s' % (uploader, slug_title)
  1051. resolv_url = 'http://api.soundcloud.com/resolve.json?url=' + url + '&client_id=b45b1aa10f1ac2941910a7f0d10f8e28'
  1052. info_json = self._download_webpage(resolv_url, full_title)
  1053. videos = []
  1054. info = json.loads(info_json)
  1055. if 'errors' in info:
  1056. for err in info['errors']:
  1057. self._downloader.report_error(u'unable to download video webpage: %s' % compat_str(err['error_message']))
  1058. return
  1059. self.report_extraction(full_title)
  1060. for track in info['tracks']:
  1061. video_id = track['id']
  1062. streams_url = 'https://api.sndcdn.com/i1/tracks/' + str(video_id) + '/streams?client_id=b45b1aa10f1ac2941910a7f0d10f8e28'
  1063. stream_json = self._download_webpage(streams_url, video_id, u'Downloading track info JSON')
  1064. self.report_extraction(video_id)
  1065. streams = json.loads(stream_json)
  1066. mediaURL = streams['http_mp3_128_url']
  1067. videos.append({
  1068. 'id': video_id,
  1069. 'url': mediaURL,
  1070. 'uploader': track['user']['username'],
  1071. 'upload_date': unified_strdate(track['created_at']),
  1072. 'title': track['title'],
  1073. 'ext': u'mp3',
  1074. 'description': track['description'],
  1075. })
  1076. return videos
  1077. class InfoQIE(InfoExtractor):
  1078. """Information extractor for infoq.com"""
  1079. _VALID_URL = r'^(?:https?://)?(?:www\.)?infoq\.com/[^/]+/[^/]+$'
  1080. def _real_extract(self, url):
  1081. mobj = re.match(self._VALID_URL, url)
  1082. if mobj is None:
  1083. raise ExtractorError(u'Invalid URL: %s' % url)
  1084. webpage = self._download_webpage(url, video_id=url)
  1085. self.report_extraction(url)
  1086. # Extract video URL
  1087. mobj = re.search(r"jsclassref ?= ?'([^']*)'", webpage)
  1088. if mobj is None:
  1089. raise ExtractorError(u'Unable to extract video url')
  1090. real_id = compat_urllib_parse.unquote(base64.b64decode(mobj.group(1).encode('ascii')).decode('utf-8'))
  1091. video_url = 'rtmpe://video.infoq.com/cfx/st/' + real_id
  1092. # Extract title
  1093. video_title = self._search_regex(r'contentTitle = "(.*?)";',
  1094. webpage, u'title')
  1095. # Extract description
  1096. video_description = self._html_search_regex(r'<meta name="description" content="(.*)"(?:\s*/)?>',
  1097. webpage, u'description', fatal=False)
  1098. video_filename = video_url.split('/')[-1]
  1099. video_id, extension = video_filename.split('.')
  1100. info = {
  1101. 'id': video_id,
  1102. 'url': video_url,
  1103. 'uploader': None,
  1104. 'upload_date': None,
  1105. 'title': video_title,
  1106. 'ext': extension, # Extension is always(?) mp4, but seems to be flv
  1107. 'thumbnail': None,
  1108. 'description': video_description,
  1109. }
  1110. return [info]
  1111. class MixcloudIE(InfoExtractor):
  1112. """Information extractor for www.mixcloud.com"""
  1113. _WORKING = False # New API, but it seems good http://www.mixcloud.com/developers/documentation/
  1114. _VALID_URL = r'^(?:https?://)?(?:www\.)?mixcloud\.com/([\w\d-]+)/([\w\d-]+)'
  1115. IE_NAME = u'mixcloud'
  1116. def report_download_json(self, file_id):
  1117. """Report JSON download."""
  1118. self.to_screen(u'Downloading json')
  1119. def get_urls(self, jsonData, fmt, bitrate='best'):
  1120. """Get urls from 'audio_formats' section in json"""
  1121. file_url = None
  1122. try:
  1123. bitrate_list = jsonData[fmt]
  1124. if bitrate is None or bitrate == 'best' or bitrate not in bitrate_list:
  1125. bitrate = max(bitrate_list) # select highest
  1126. url_list = jsonData[fmt][bitrate]
  1127. except TypeError: # we have no bitrate info.
  1128. url_list = jsonData[fmt]
  1129. return url_list
  1130. def check_urls(self, url_list):
  1131. """Returns 1st active url from list"""
  1132. for url in url_list:
  1133. try:
  1134. compat_urllib_request.urlopen(url)
  1135. return url
  1136. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  1137. url = None
  1138. return None
  1139. def _print_formats(self, formats):
  1140. print('Available formats:')
  1141. for fmt in formats.keys():
  1142. for b in formats[fmt]:
  1143. try:
  1144. ext = formats[fmt][b][0]
  1145. print('%s\t%s\t[%s]' % (fmt, b, ext.split('.')[-1]))
  1146. except TypeError: # we have no bitrate info
  1147. ext = formats[fmt][0]
  1148. print('%s\t%s\t[%s]' % (fmt, '??', ext.split('.')[-1]))
  1149. break
  1150. def _real_extract(self, url):
  1151. mobj = re.match(self._VALID_URL, url)
  1152. if mobj is None:
  1153. raise ExtractorError(u'Invalid URL: %s' % url)
  1154. # extract uploader & filename from url
  1155. uploader = mobj.group(1).decode('utf-8')
  1156. file_id = uploader + "-" + mobj.group(2).decode('utf-8')
  1157. # construct API request
  1158. file_url = 'http://www.mixcloud.com/api/1/cloudcast/' + '/'.join(url.split('/')[-3:-1]) + '.json'
  1159. # retrieve .json file with links to files
  1160. request = compat_urllib_request.Request(file_url)
  1161. try:
  1162. self.report_download_json(file_url)
  1163. jsonData = compat_urllib_request.urlopen(request).read()
  1164. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  1165. raise ExtractorError(u'Unable to retrieve file: %s' % compat_str(err))
  1166. # parse JSON
  1167. json_data = json.loads(jsonData)
  1168. player_url = json_data['player_swf_url']
  1169. formats = dict(json_data['audio_formats'])
  1170. req_format = self._downloader.params.get('format', None)
  1171. bitrate = None
  1172. if self._downloader.params.get('listformats', None):
  1173. self._print_formats(formats)
  1174. return
  1175. if req_format is None or req_format == 'best':
  1176. for format_param in formats.keys():
  1177. url_list = self.get_urls(formats, format_param)
  1178. # check urls
  1179. file_url = self.check_urls(url_list)
  1180. if file_url is not None:
  1181. break # got it!
  1182. else:
  1183. if req_format not in formats:
  1184. raise ExtractorError(u'Format is not available')
  1185. url_list = self.get_urls(formats, req_format)
  1186. file_url = self.check_urls(url_list)
  1187. format_param = req_format
  1188. return [{
  1189. 'id': file_id.decode('utf-8'),
  1190. 'url': file_url.decode('utf-8'),
  1191. 'uploader': uploader.decode('utf-8'),
  1192. 'upload_date': None,
  1193. 'title': json_data['name'],
  1194. 'ext': file_url.split('.')[-1].decode('utf-8'),
  1195. 'format': (format_param is None and u'NA' or format_param.decode('utf-8')),
  1196. 'thumbnail': json_data['thumbnail_url'],
  1197. 'description': json_data['description'],
  1198. 'player_url': player_url.decode('utf-8'),
  1199. }]
  1200. class StanfordOpenClassroomIE(InfoExtractor):
  1201. """Information extractor for Stanford's Open ClassRoom"""
  1202. _VALID_URL = r'^(?:https?://)?openclassroom.stanford.edu(?P<path>/?|(/MainFolder/(?:HomePage|CoursePage|VideoPage)\.php([?]course=(?P<course>[^&]+)(&video=(?P<video>[^&]+))?(&.*)?)?))$'
  1203. IE_NAME = u'stanfordoc'
  1204. def _real_extract(self, url):
  1205. mobj = re.match(self._VALID_URL, url)
  1206. if mobj is None:
  1207. raise ExtractorError(u'Invalid URL: %s' % url)
  1208. if mobj.group('course') and mobj.group('video'): # A specific video
  1209. course = mobj.group('course')
  1210. video = mobj.group('video')
  1211. info = {
  1212. 'id': course + '_' + video,
  1213. 'uploader': None,
  1214. 'upload_date': None,
  1215. }
  1216. self.report_extraction(info['id'])
  1217. baseUrl = 'http://openclassroom.stanford.edu/MainFolder/courses/' + course + '/videos/'
  1218. xmlUrl = baseUrl + video + '.xml'
  1219. try:
  1220. metaXml = compat_urllib_request.urlopen(xmlUrl).read()
  1221. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  1222. raise ExtractorError(u'Unable to download video info XML: %s' % compat_str(err))
  1223. mdoc = xml.etree.ElementTree.fromstring(metaXml)
  1224. try:
  1225. info['title'] = mdoc.findall('./title')[0].text
  1226. info['url'] = baseUrl + mdoc.findall('./videoFile')[0].text
  1227. except IndexError:
  1228. raise ExtractorError(u'Invalid metadata XML file')
  1229. info['ext'] = info['url'].rpartition('.')[2]
  1230. return [info]
  1231. elif mobj.group('course'): # A course page
  1232. course = mobj.group('course')
  1233. info = {
  1234. 'id': course,
  1235. 'type': 'playlist',
  1236. 'uploader': None,
  1237. 'upload_date': None,
  1238. }
  1239. coursepage = self._download_webpage(url, info['id'],
  1240. note='Downloading course info page',
  1241. errnote='Unable to download course info page')
  1242. info['title'] = self._html_search_regex('<h1>([^<]+)</h1>', coursepage, 'title', default=info['id'])
  1243. info['description'] = self._html_search_regex('<description>([^<]+)</description>',
  1244. coursepage, u'description', fatal=False)
  1245. links = orderedSet(re.findall('<a href="(VideoPage.php\?[^"]+)">', coursepage))
  1246. info['list'] = [
  1247. {
  1248. 'type': 'reference',
  1249. 'url': 'http://openclassroom.stanford.edu/MainFolder/' + unescapeHTML(vpage),
  1250. }
  1251. for vpage in links]
  1252. results = []
  1253. for entry in info['list']:
  1254. assert entry['type'] == 'reference'
  1255. results += self.extract(entry['url'])
  1256. return results
  1257. else: # Root page
  1258. info = {
  1259. 'id': 'Stanford OpenClassroom',
  1260. 'type': 'playlist',
  1261. 'uploader': None,
  1262. 'upload_date': None,
  1263. }
  1264. self.report_download_webpage(info['id'])
  1265. rootURL = 'http://openclassroom.stanford.edu/MainFolder/HomePage.php'
  1266. try:
  1267. rootpage = compat_urllib_request.urlopen(rootURL).read()
  1268. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  1269. raise ExtractorError(u'Unable to download course info page: ' + compat_str(err))
  1270. info['title'] = info['id']
  1271. links = orderedSet(re.findall('<a href="(CoursePage.php\?[^"]+)">', rootpage))
  1272. info['list'] = [
  1273. {
  1274. 'type': 'reference',
  1275. 'url': 'http://openclassroom.stanford.edu/MainFolder/' + unescapeHTML(cpage),
  1276. }
  1277. for cpage in links]
  1278. results = []
  1279. for entry in info['list']:
  1280. assert entry['type'] == 'reference'
  1281. results += self.extract(entry['url'])
  1282. return results
  1283. class MTVIE(InfoExtractor):
  1284. """Information extractor for MTV.com"""
  1285. _VALID_URL = r'^(?P<proto>https?://)?(?:www\.)?mtv\.com/videos/[^/]+/(?P<videoid>[0-9]+)/[^/]+$'
  1286. IE_NAME = u'mtv'
  1287. def _real_extract(self, url):
  1288. mobj = re.match(self._VALID_URL, url)
  1289. if mobj is None:
  1290. raise ExtractorError(u'Invalid URL: %s' % url)
  1291. if not mobj.group('proto'):
  1292. url = 'http://' + url
  1293. video_id = mobj.group('videoid')
  1294. webpage = self._download_webpage(url, video_id)
  1295. song_name = self._html_search_regex(r'<meta name="mtv_vt" content="([^"]+)"/>',
  1296. webpage, u'song name', fatal=False)
  1297. video_title = self._html_search_regex(r'<meta name="mtv_an" content="([^"]+)"/>',
  1298. webpage, u'title')
  1299. mtvn_uri = self._html_search_regex(r'<meta name="mtvn_uri" content="([^"]+)"/>',
  1300. webpage, u'mtvn_uri', fatal=False)
  1301. content_id = self._search_regex(r'MTVN.Player.defaultPlaylistId = ([0-9]+);',
  1302. webpage, u'content id', fatal=False)
  1303. videogen_url = 'http://www.mtv.com/player/includes/mediaGen.jhtml?uri=' + mtvn_uri + '&id=' + content_id + '&vid=' + video_id + '&ref=www.mtvn.com&viewUri=' + mtvn_uri
  1304. self.report_extraction(video_id)
  1305. request = compat_urllib_request.Request(videogen_url)
  1306. try:
  1307. metadataXml = compat_urllib_request.urlopen(request).read()
  1308. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  1309. raise ExtractorError(u'Unable to download video metadata: %s' % compat_str(err))
  1310. mdoc = xml.etree.ElementTree.fromstring(metadataXml)
  1311. renditions = mdoc.findall('.//rendition')
  1312. # For now, always pick the highest quality.
  1313. rendition = renditions[-1]
  1314. try:
  1315. _,_,ext = rendition.attrib['type'].partition('/')
  1316. format = ext + '-' + rendition.attrib['width'] + 'x' + rendition.attrib['height'] + '_' + rendition.attrib['bitrate']
  1317. video_url = rendition.find('./src').text
  1318. except KeyError:
  1319. raise ExtractorError('Invalid rendition field.')
  1320. info = {
  1321. 'id': video_id,
  1322. 'url': video_url,
  1323. 'uploader': performer,
  1324. 'upload_date': None,
  1325. 'title': video_title,
  1326. 'ext': ext,
  1327. 'format': format,
  1328. }
  1329. return [info]
  1330. class YoukuIE(InfoExtractor):
  1331. _VALID_URL = r'(?:http://)?v\.youku\.com/v_show/id_(?P<ID>[A-Za-z0-9]+)\.html'
  1332. def _gen_sid(self):
  1333. nowTime = int(time.time() * 1000)
  1334. random1 = random.randint(1000,1998)
  1335. random2 = random.randint(1000,9999)
  1336. return "%d%d%d" %(nowTime,random1,random2)
  1337. def _get_file_ID_mix_string(self, seed):
  1338. mixed = []
  1339. source = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\:._-1234567890")
  1340. seed = float(seed)
  1341. for i in range(len(source)):
  1342. seed = (seed * 211 + 30031 ) % 65536
  1343. index = math.floor(seed / 65536 * len(source) )
  1344. mixed.append(source[int(index)])
  1345. source.remove(source[int(index)])
  1346. #return ''.join(mixed)
  1347. return mixed
  1348. def _get_file_id(self, fileId, seed):
  1349. mixed = self._get_file_ID_mix_string(seed)
  1350. ids = fileId.split('*')
  1351. realId = []
  1352. for ch in ids:
  1353. if ch:
  1354. realId.append(mixed[int(ch)])
  1355. return ''.join(realId)
  1356. def _real_extract(self, url):
  1357. mobj = re.match(self._VALID_URL, url)
  1358. if mobj is None:
  1359. raise ExtractorError(u'Invalid URL: %s' % url)
  1360. video_id = mobj.group('ID')
  1361. info_url = 'http://v.youku.com/player/getPlayList/VideoIDS/' + video_id
  1362. jsondata = self._download_webpage(info_url, video_id)
  1363. self.report_extraction(video_id)
  1364. try:
  1365. config = json.loads(jsondata)
  1366. video_title = config['data'][0]['title']
  1367. seed = config['data'][0]['seed']
  1368. format = self._downloader.params.get('format', None)
  1369. supported_format = list(config['data'][0]['streamfileids'].keys())
  1370. if format is None or format == 'best':
  1371. if 'hd2' in supported_format:
  1372. format = 'hd2'
  1373. else:
  1374. format = 'flv'
  1375. ext = u'flv'
  1376. elif format == 'worst':
  1377. format = 'mp4'
  1378. ext = u'mp4'
  1379. else:
  1380. format = 'flv'
  1381. ext = u'flv'
  1382. fileid = config['data'][0]['streamfileids'][format]
  1383. keys = [s['k'] for s in config['data'][0]['segs'][format]]
  1384. except (UnicodeDecodeError, ValueError, KeyError):
  1385. raise ExtractorError(u'Unable to extract info section')
  1386. files_info=[]
  1387. sid = self._gen_sid()
  1388. fileid = self._get_file_id(fileid, seed)
  1389. #column 8,9 of fileid represent the segment number
  1390. #fileid[7:9] should be changed
  1391. for index, key in enumerate(keys):
  1392. temp_fileid = '%s%02X%s' % (fileid[0:8], index, fileid[10:])
  1393. download_url = 'http://f.youku.com/player/getFlvPath/sid/%s_%02X/st/flv/fileid/%s?k=%s' % (sid, index, temp_fileid, key)
  1394. info = {
  1395. 'id': '%s_part%02d' % (video_id, index),
  1396. 'url': download_url,
  1397. 'uploader': None,
  1398. 'upload_date': None,
  1399. 'title': video_title,
  1400. 'ext': ext,
  1401. }
  1402. files_info.append(info)
  1403. return files_info
  1404. class XNXXIE(InfoExtractor):
  1405. """Information extractor for xnxx.com"""
  1406. _VALID_URL = r'^(?:https?://)?video\.xnxx\.com/video([0-9]+)/(.*)'
  1407. IE_NAME = u'xnxx'
  1408. VIDEO_URL_RE = r'flv_url=(.*?)&amp;'
  1409. VIDEO_TITLE_RE = r'<title>(.*?)\s+-\s+XNXX.COM'
  1410. VIDEO_THUMB_RE = r'url_bigthumb=(.*?)&amp;'
  1411. def _real_extract(self, url):
  1412. mobj = re.match(self._VALID_URL, url)
  1413. if mobj is None:
  1414. raise ExtractorError(u'Invalid URL: %s' % url)
  1415. video_id = mobj.group(1)
  1416. # Get webpage content
  1417. webpage = self._download_webpage(url, video_id)
  1418. video_url = self._search_regex(self.VIDEO_URL_RE,
  1419. webpage, u'video URL')
  1420. video_url = compat_urllib_parse.unquote(video_url)
  1421. video_title = self._html_search_regex(self.VIDEO_TITLE_RE,
  1422. webpage, u'title')
  1423. video_thumbnail = self._search_regex(self.VIDEO_THUMB_RE,
  1424. webpage, u'thumbnail', fatal=False)
  1425. return [{
  1426. 'id': video_id,
  1427. 'url': video_url,
  1428. 'uploader': None,
  1429. 'upload_date': None,
  1430. 'title': video_title,
  1431. 'ext': 'flv',
  1432. 'thumbnail': video_thumbnail,
  1433. 'description': None,
  1434. }]
  1435. class GooglePlusIE(InfoExtractor):
  1436. """Information extractor for plus.google.com."""
  1437. _VALID_URL = r'(?:https://)?plus\.google\.com/(?:[^/]+/)*?posts/(\w+)'
  1438. IE_NAME = u'plus.google'
  1439. def _real_extract(self, url):
  1440. # Extract id from URL
  1441. mobj = re.match(self._VALID_URL, url)
  1442. if mobj is None:
  1443. raise ExtractorError(u'Invalid URL: %s' % url)
  1444. post_url = mobj.group(0)
  1445. video_id = mobj.group(1)
  1446. video_extension = 'flv'
  1447. # Step 1, Retrieve post webpage to extract further information
  1448. webpage = self._download_webpage(post_url, video_id, u'Downloading entry webpage')
  1449. self.report_extraction(video_id)
  1450. # Extract update date
  1451. upload_date = self._html_search_regex('title="Timestamp">(.*?)</a>',
  1452. webpage, u'upload date', fatal=False)
  1453. if upload_date:
  1454. # Convert timestring to a format suitable for filename
  1455. upload_date = datetime.datetime.strptime(upload_date, "%Y-%m-%d")
  1456. upload_date = upload_date.strftime('%Y%m%d')
  1457. # Extract uploader
  1458. uploader = self._html_search_regex(r'rel\="author".*?>(.*?)</a>',
  1459. webpage, u'uploader', fatal=False)
  1460. # Extract title
  1461. # Get the first line for title
  1462. video_title = self._html_search_regex(r'<meta name\=\"Description\" content\=\"(.*?)[\n<"]',
  1463. webpage, 'title', default=u'NA')
  1464. # Step 2, Stimulate clicking the image box to launch video
  1465. video_page = self._search_regex('"(https\://plus\.google\.com/photos/.*?)",,"image/jpeg","video"\]',
  1466. webpage, u'video page URL')
  1467. webpage = self._download_webpage(video_page, video_id, u'Downloading video page')
  1468. # Extract video links on video page
  1469. """Extract video links of all sizes"""
  1470. pattern = '\d+,\d+,(\d+),"(http\://redirector\.googlevideo\.com.*?)"'
  1471. mobj = re.findall(pattern, webpage)
  1472. if len(mobj) == 0:
  1473. raise ExtractorError(u'Unable to extract video links')
  1474. # Sort in resolution
  1475. links = sorted(mobj)
  1476. # Choose the lowest of the sort, i.e. highest resolution
  1477. video_url = links[-1]
  1478. # Only get the url. The resolution part in the tuple has no use anymore
  1479. video_url = video_url[-1]
  1480. # Treat escaped \u0026 style hex
  1481. try:
  1482. video_url = video_url.decode("unicode_escape")
  1483. except AttributeError: # Python 3
  1484. video_url = bytes(video_url, 'ascii').decode('unicode-escape')
  1485. return [{
  1486. 'id': video_id,
  1487. 'url': video_url,
  1488. 'uploader': uploader,
  1489. 'upload_date': upload_date,
  1490. 'title': video_title,
  1491. 'ext': video_extension,
  1492. }]
  1493. class NBAIE(InfoExtractor):
  1494. _VALID_URL = r'^(?:https?://)?(?:watch\.|www\.)?nba\.com/(?:nba/)?video(/[^?]*?)(?:/index\.html)?(?:\?.*)?$'
  1495. IE_NAME = u'nba'
  1496. def _real_extract(self, url):
  1497. mobj = re.match(self._VALID_URL, url)
  1498. if mobj is None:
  1499. raise ExtractorError(u'Invalid URL: %s' % url)
  1500. video_id = mobj.group(1)
  1501. webpage = self._download_webpage(url, video_id)
  1502. video_url = u'http://ht-mobile.cdn.turner.com/nba/big' + video_id + '_nba_1280x720.mp4'
  1503. shortened_video_id = video_id.rpartition('/')[2]
  1504. title = self._html_search_regex(r'<meta property="og:title" content="(.*?)"',
  1505. webpage, 'title', default=shortened_video_id).replace('NBA.com: ', '')
  1506. # It isn't there in the HTML it returns to us
  1507. # uploader_date = self._html_search_regex(r'<b>Date:</b> (.*?)</div>', webpage, 'upload_date', fatal=False)
  1508. description = self._html_search_regex(r'<meta name="description" (?:content|value)="(.*?)" />', webpage, 'description', fatal=False)
  1509. info = {
  1510. 'id': shortened_video_id,
  1511. 'url': video_url,
  1512. 'ext': 'mp4',
  1513. 'title': title,
  1514. # 'uploader_date': uploader_date,
  1515. 'description': description,
  1516. }
  1517. return [info]
  1518. class JustinTVIE(InfoExtractor):
  1519. """Information extractor for justin.tv and twitch.tv"""
  1520. # TODO: One broadcast may be split into multiple videos. The key
  1521. # 'broadcast_id' is the same for all parts, and 'broadcast_part'
  1522. # starts at 1 and increases. Can we treat all parts as one video?
  1523. _VALID_URL = r"""(?x)^(?:http://)?(?:www\.)?(?:twitch|justin)\.tv/
  1524. (?:
  1525. (?P<channelid>[^/]+)|
  1526. (?:(?:[^/]+)/b/(?P<videoid>[^/]+))|
  1527. (?:(?:[^/]+)/c/(?P<chapterid>[^/]+))
  1528. )
  1529. /?(?:\#.*)?$
  1530. """
  1531. _JUSTIN_PAGE_LIMIT = 100
  1532. IE_NAME = u'justin.tv'
  1533. def report_download_page(self, channel, offset):
  1534. """Report attempt to download a single page of videos."""
  1535. self.to_screen(u'%s: Downloading video information from %d to %d' %
  1536. (channel, offset, offset + self._JUSTIN_PAGE_LIMIT))
  1537. # Return count of items, list of *valid* items
  1538. def _parse_page(self, url, video_id):
  1539. webpage = self._download_webpage(url, video_id,
  1540. u'Downloading video info JSON',
  1541. u'unable to download video info JSON')
  1542. response = json.loads(webpage)
  1543. if type(response) != list:
  1544. error_text = response.get('error', 'unknown error')
  1545. raise ExtractorError(u'Justin.tv API: %s' % error_text)
  1546. info = []
  1547. for clip in response:
  1548. video_url = clip['video_file_url']
  1549. if video_url:
  1550. video_extension = os.path.splitext(video_url)[1][1:]
  1551. video_date = re.sub('-', '', clip['start_time'][:10])
  1552. video_uploader_id = clip.get('user_id', clip.get('channel_id'))
  1553. video_id = clip['id']
  1554. video_title = clip.get('title', video_id)
  1555. info.append({
  1556. 'id': video_id,
  1557. 'url': video_url,
  1558. 'title': video_title,
  1559. 'uploader': clip.get('channel_name', video_uploader_id),
  1560. 'uploader_id': video_uploader_id,
  1561. 'upload_date': video_date,
  1562. 'ext': video_extension,
  1563. })
  1564. return (len(response), info)
  1565. def _real_extract(self, url):
  1566. mobj = re.match(self._VALID_URL, url)
  1567. if mobj is None:
  1568. raise ExtractorError(u'invalid URL: %s' % url)
  1569. api_base = 'http://api.justin.tv'
  1570. paged = False
  1571. if mobj.group('channelid'):
  1572. paged = True
  1573. video_id = mobj.group('channelid')
  1574. api = api_base + '/channel/archives/%s.json' % video_id
  1575. elif mobj.group('chapterid'):
  1576. chapter_id = mobj.group('chapterid')
  1577. webpage = self._download_webpage(url, chapter_id)
  1578. m = re.search(r'PP\.archive_id = "([0-9]+)";', webpage)
  1579. if not m:
  1580. raise ExtractorError(u'Cannot find archive of a chapter')
  1581. archive_id = m.group(1)
  1582. api = api_base + '/broadcast/by_chapter/%s.xml' % chapter_id
  1583. chapter_info_xml = self._download_webpage(api, chapter_id,
  1584. note=u'Downloading chapter information',
  1585. errnote=u'Chapter information download failed')
  1586. doc = xml.etree.ElementTree.fromstring(chapter_info_xml)
  1587. for a in doc.findall('.//archive'):
  1588. if archive_id == a.find('./id').text:
  1589. break
  1590. else:
  1591. raise ExtractorError(u'Could not find chapter in chapter information')
  1592. video_url = a.find('./video_file_url').text
  1593. video_ext = video_url.rpartition('.')[2] or u'flv'
  1594. chapter_api_url = u'https://api.twitch.tv/kraken/videos/c' + chapter_id
  1595. chapter_info_json = self._download_webpage(chapter_api_url, u'c' + chapter_id,
  1596. note='Downloading chapter metadata',
  1597. errnote='Download of chapter metadata failed')
  1598. chapter_info = json.loads(chapter_info_json)
  1599. bracket_start = int(doc.find('.//bracket_start').text)
  1600. bracket_end = int(doc.find('.//bracket_end').text)
  1601. # TODO determine start (and probably fix up file)
  1602. # youtube-dl -v http://www.twitch.tv/firmbelief/c/1757457
  1603. #video_url += u'?start=' + TODO:start_timestamp
  1604. # bracket_start is 13290, but we want 51670615
  1605. self._downloader.report_warning(u'Chapter detected, but we can just download the whole file. '
  1606. u'Chapter starts at %s and ends at %s' % (formatSeconds(bracket_start), formatSeconds(bracket_end)))
  1607. info = {
  1608. 'id': u'c' + chapter_id,
  1609. 'url': video_url,
  1610. 'ext': video_ext,
  1611. 'title': chapter_info['title'],
  1612. 'thumbnail': chapter_info['preview'],
  1613. 'description': chapter_info['description'],
  1614. 'uploader': chapter_info['channel']['display_name'],
  1615. 'uploader_id': chapter_info['channel']['name'],
  1616. }
  1617. return [info]
  1618. else:
  1619. video_id = mobj.group('videoid')
  1620. api = api_base + '/broadcast/by_archive/%s.json' % video_id
  1621. self.report_extraction(video_id)
  1622. info = []
  1623. offset = 0
  1624. limit = self._JUSTIN_PAGE_LIMIT
  1625. while True:
  1626. if paged:
  1627. self.report_download_page(video_id, offset)
  1628. page_url = api + ('?offset=%d&limit=%d' % (offset, limit))
  1629. page_count, page_info = self._parse_page(page_url, video_id)
  1630. info.extend(page_info)
  1631. if not paged or page_count != limit:
  1632. break
  1633. offset += limit
  1634. return info
  1635. class FunnyOrDieIE(InfoExtractor):
  1636. _VALID_URL = r'^(?:https?://)?(?:www\.)?funnyordie\.com/videos/(?P<id>[0-9a-f]+)/.*$'
  1637. def _real_extract(self, url):
  1638. mobj = re.match(self._VALID_URL, url)
  1639. if mobj is None:
  1640. raise ExtractorError(u'invalid URL: %s' % url)
  1641. video_id = mobj.group('id')
  1642. webpage = self._download_webpage(url, video_id)
  1643. video_url = self._html_search_regex(r'<video[^>]*>\s*<source[^>]*>\s*<source src="(?P<url>[^"]+)"',
  1644. webpage, u'video URL', flags=re.DOTALL)
  1645. title = self._html_search_regex((r"<h1 class='player_page_h1'.*?>(?P<title>.*?)</h1>",
  1646. r'<title>(?P<title>[^<]+?)</title>'), webpage, 'title', flags=re.DOTALL)
  1647. video_description = self._html_search_regex(r'<meta property="og:description" content="(?P<desc>.*?)"',
  1648. webpage, u'description', fatal=False, flags=re.DOTALL)
  1649. info = {
  1650. 'id': video_id,
  1651. 'url': video_url,
  1652. 'ext': 'mp4',
  1653. 'title': title,
  1654. 'description': video_description,
  1655. }
  1656. return [info]
  1657. class SteamIE(InfoExtractor):
  1658. _VALID_URL = r"""http://store\.steampowered\.com/
  1659. (agecheck/)?
  1660. (?P<urltype>video|app)/ #If the page is only for videos or for a game
  1661. (?P<gameID>\d+)/?
  1662. (?P<videoID>\d*)(?P<extra>\??) #For urltype == video we sometimes get the videoID
  1663. """
  1664. _VIDEO_PAGE_TEMPLATE = 'http://store.steampowered.com/video/%s/'
  1665. _AGECHECK_TEMPLATE = 'http://store.steampowered.com/agecheck/video/%s/?snr=1_agecheck_agecheck__age-gate&ageDay=1&ageMonth=January&ageYear=1970'
  1666. @classmethod
  1667. def suitable(cls, url):
  1668. """Receives a URL and returns True if suitable for this IE."""
  1669. return re.match(cls._VALID_URL, url, re.VERBOSE) is not None
  1670. def _real_extract(self, url):
  1671. m = re.match(self._VALID_URL, url, re.VERBOSE)
  1672. gameID = m.group('gameID')
  1673. videourl = self._VIDEO_PAGE_TEMPLATE % gameID
  1674. webpage = self._download_webpage(videourl, gameID)
  1675. if re.search('<h2>Please enter your birth date to continue:</h2>', webpage) is not None:
  1676. videourl = self._AGECHECK_TEMPLATE % gameID
  1677. self.report_age_confirmation()
  1678. webpage = self._download_webpage(videourl, gameID)
  1679. self.report_extraction(gameID)
  1680. game_title = self._html_search_regex(r'<h2 class="pageheader">(.*?)</h2>',
  1681. webpage, 'game title')
  1682. urlRE = r"'movie_(?P<videoID>\d+)': \{\s*FILENAME: \"(?P<videoURL>[\w:/\.\?=]+)\"(,\s*MOVIE_NAME: \"(?P<videoName>[\w:/\.\?=\+-]+)\")?\s*\},"
  1683. mweb = re.finditer(urlRE, webpage)
  1684. namesRE = r'<span class="title">(?P<videoName>.+?)</span>'
  1685. titles = re.finditer(namesRE, webpage)
  1686. thumbsRE = r'<img class="movie_thumb" src="(?P<thumbnail>.+?)">'
  1687. thumbs = re.finditer(thumbsRE, webpage)
  1688. videos = []
  1689. for vid,vtitle,thumb in zip(mweb,titles,thumbs):
  1690. video_id = vid.group('videoID')
  1691. title = vtitle.group('videoName')
  1692. video_url = vid.group('videoURL')
  1693. video_thumb = thumb.group('thumbnail')
  1694. if not video_url:
  1695. raise ExtractorError(u'Cannot find video url for %s' % video_id)
  1696. info = {
  1697. 'id':video_id,
  1698. 'url':video_url,
  1699. 'ext': 'flv',
  1700. 'title': unescapeHTML(title),
  1701. 'thumbnail': video_thumb
  1702. }
  1703. videos.append(info)
  1704. return [self.playlist_result(videos, gameID, game_title)]
  1705. class UstreamIE(InfoExtractor):
  1706. _VALID_URL = r'https?://www\.ustream\.tv/recorded/(?P<videoID>\d+)'
  1707. IE_NAME = u'ustream'
  1708. def _real_extract(self, url):
  1709. m = re.match(self._VALID_URL, url)
  1710. video_id = m.group('videoID')
  1711. video_url = u'http://tcdn.ustream.tv/video/%s' % video_id
  1712. webpage = self._download_webpage(url, video_id)
  1713. self.report_extraction(video_id)
  1714. video_title = self._html_search_regex(r'data-title="(?P<title>.+)"',
  1715. webpage, u'title')
  1716. uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>',
  1717. webpage, u'uploader', fatal=False, flags=re.DOTALL)
  1718. thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"',
  1719. webpage, u'thumbnail', fatal=False)
  1720. info = {
  1721. 'id': video_id,
  1722. 'url': video_url,
  1723. 'ext': 'flv',
  1724. 'title': video_title,
  1725. 'uploader': uploader,
  1726. 'thumbnail': thumbnail,
  1727. }
  1728. return info
  1729. class WorldStarHipHopIE(InfoExtractor):
  1730. _VALID_URL = r'https?://(?:www|m)\.worldstar(?:candy|hiphop)\.com/videos/video\.php\?v=(?P<id>.*)'
  1731. IE_NAME = u'WorldStarHipHop'
  1732. def _real_extract(self, url):
  1733. m = re.match(self._VALID_URL, url)
  1734. video_id = m.group('id')
  1735. webpage_src = self._download_webpage(url, video_id)
  1736. video_url = self._search_regex(r'so\.addVariable\("file","(.*?)"\)',
  1737. webpage_src, u'video URL')
  1738. if 'mp4' in video_url:
  1739. ext = 'mp4'
  1740. else:
  1741. ext = 'flv'
  1742. video_title = self._html_search_regex(r"<title>(.*)</title>",
  1743. webpage_src, u'title')
  1744. # Getting thumbnail and if not thumbnail sets correct title for WSHH candy video.
  1745. thumbnail = self._html_search_regex(r'rel="image_src" href="(.*)" />',
  1746. webpage_src, u'thumbnail', fatal=False)
  1747. if not thumbnail:
  1748. _title = r"""candytitles.*>(.*)</span>"""
  1749. mobj = re.search(_title, webpage_src)
  1750. if mobj is not None:
  1751. video_title = mobj.group(1)
  1752. results = [{
  1753. 'id': video_id,
  1754. 'url' : video_url,
  1755. 'title' : video_title,
  1756. 'thumbnail' : thumbnail,
  1757. 'ext' : ext,
  1758. }]
  1759. return results
  1760. class RBMARadioIE(InfoExtractor):
  1761. _VALID_URL = r'https?://(?:www\.)?rbmaradio\.com/shows/(?P<videoID>[^/]+)$'
  1762. def _real_extract(self, url):
  1763. m = re.match(self._VALID_URL, url)
  1764. video_id = m.group('videoID')
  1765. webpage = self._download_webpage(url, video_id)
  1766. json_data = self._search_regex(r'window\.gon.*?gon\.show=(.+?);$',
  1767. webpage, u'json data', flags=re.MULTILINE)
  1768. try:
  1769. data = json.loads(json_data)
  1770. except ValueError as e:
  1771. raise ExtractorError(u'Invalid JSON: ' + str(e))
  1772. video_url = data['akamai_url'] + '&cbr=256'
  1773. url_parts = compat_urllib_parse_urlparse(video_url)
  1774. video_ext = url_parts.path.rpartition('.')[2]
  1775. info = {
  1776. 'id': video_id,
  1777. 'url': video_url,
  1778. 'ext': video_ext,
  1779. 'title': data['title'],
  1780. 'description': data.get('teaser_text'),
  1781. 'location': data.get('country_of_origin'),
  1782. 'uploader': data.get('host', {}).get('name'),
  1783. 'uploader_id': data.get('host', {}).get('slug'),
  1784. 'thumbnail': data.get('image', {}).get('large_url_2x'),
  1785. 'duration': data.get('duration'),
  1786. }
  1787. return [info]
  1788. class YouPornIE(InfoExtractor):
  1789. """Information extractor for youporn.com."""
  1790. _VALID_URL = r'^(?:https?://)?(?:\w+\.)?youporn\.com/watch/(?P<videoid>[0-9]+)/(?P<title>[^/]+)'
  1791. def _print_formats(self, formats):
  1792. """Print all available formats"""
  1793. print(u'Available formats:')
  1794. print(u'ext\t\tformat')
  1795. print(u'---------------------------------')
  1796. for format in formats:
  1797. print(u'%s\t\t%s' % (format['ext'], format['format']))
  1798. def _specific(self, req_format, formats):
  1799. for x in formats:
  1800. if(x["format"]==req_format):
  1801. return x
  1802. return None
  1803. def _real_extract(self, url):
  1804. mobj = re.match(self._VALID_URL, url)
  1805. if mobj is None:
  1806. raise ExtractorError(u'Invalid URL: %s' % url)
  1807. video_id = mobj.group('videoid')
  1808. req = compat_urllib_request.Request(url)
  1809. req.add_header('Cookie', 'age_verified=1')
  1810. webpage = self._download_webpage(req, video_id)
  1811. # Get JSON parameters
  1812. json_params = self._search_regex(r'var currentVideo = new Video\((.*)\);', webpage, u'JSON parameters')
  1813. try:
  1814. params = json.loads(json_params)
  1815. except:
  1816. raise ExtractorError(u'Invalid JSON')
  1817. self.report_extraction(video_id)
  1818. try:
  1819. video_title = params['title']
  1820. upload_date = unified_strdate(params['release_date_f'])
  1821. video_description = params['description']
  1822. video_uploader = params['submitted_by']
  1823. thumbnail = params['thumbnails'][0]['image']
  1824. except KeyError:
  1825. raise ExtractorError('Missing JSON parameter: ' + sys.exc_info()[1])
  1826. # Get all of the formats available
  1827. DOWNLOAD_LIST_RE = r'(?s)<ul class="downloadList">(?P<download_list>.*?)</ul>'
  1828. download_list_html = self._search_regex(DOWNLOAD_LIST_RE,
  1829. webpage, u'download list').strip()
  1830. # Get all of the links from the page
  1831. LINK_RE = r'(?s)<a href="(?P<url>[^"]+)">'
  1832. links = re.findall(LINK_RE, download_list_html)
  1833. if(len(links) == 0):
  1834. raise ExtractorError(u'ERROR: no known formats available for video')
  1835. self.to_screen(u'Links found: %d' % len(links))
  1836. formats = []
  1837. for link in links:
  1838. # A link looks like this:
  1839. # 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
  1840. # A path looks like this:
  1841. # /201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4
  1842. video_url = unescapeHTML( link )
  1843. path = compat_urllib_parse_urlparse( video_url ).path
  1844. extension = os.path.splitext( path )[1][1:]
  1845. format = path.split('/')[4].split('_')[:2]
  1846. size = format[0]
  1847. bitrate = format[1]
  1848. format = "-".join( format )
  1849. # title = u'%s-%s-%s' % (video_title, size, bitrate)
  1850. formats.append({
  1851. 'id': video_id,
  1852. 'url': video_url,
  1853. 'uploader': video_uploader,
  1854. 'upload_date': upload_date,
  1855. 'title': video_title,
  1856. 'ext': extension,
  1857. 'format': format,
  1858. 'thumbnail': thumbnail,
  1859. 'description': video_description
  1860. })
  1861. if self._downloader.params.get('listformats', None):
  1862. self._print_formats(formats)
  1863. return
  1864. req_format = self._downloader.params.get('format', None)
  1865. self.to_screen(u'Format: %s' % req_format)
  1866. if req_format is None or req_format == 'best':
  1867. return [formats[0]]
  1868. elif req_format == 'worst':
  1869. return [formats[-1]]
  1870. elif req_format in ('-1', 'all'):
  1871. return formats
  1872. else:
  1873. format = self._specific( req_format, formats )
  1874. if result is None:
  1875. raise ExtractorError(u'Requested format not available')
  1876. return [format]
  1877. class PornotubeIE(InfoExtractor):
  1878. """Information extractor for pornotube.com."""
  1879. _VALID_URL = r'^(?:https?://)?(?:\w+\.)?pornotube\.com(/c/(?P<channel>[0-9]+))?(/m/(?P<videoid>[0-9]+))(/(?P<title>.+))$'
  1880. def _real_extract(self, url):
  1881. mobj = re.match(self._VALID_URL, url)
  1882. if mobj is None:
  1883. raise ExtractorError(u'Invalid URL: %s' % url)
  1884. video_id = mobj.group('videoid')
  1885. video_title = mobj.group('title')
  1886. # Get webpage content
  1887. webpage = self._download_webpage(url, video_id)
  1888. # Get the video URL
  1889. VIDEO_URL_RE = r'url: "(?P<url>http://video[0-9].pornotube.com/.+\.flv)",'
  1890. video_url = self._search_regex(VIDEO_URL_RE, webpage, u'video url')
  1891. video_url = compat_urllib_parse.unquote(video_url)
  1892. #Get the uploaded date
  1893. VIDEO_UPLOADED_RE = r'<div class="video_added_by">Added (?P<date>[0-9\/]+) by'
  1894. upload_date = self._html_search_regex(VIDEO_UPLOADED_RE, webpage, u'upload date', fatal=False)
  1895. if upload_date: upload_date = unified_strdate(upload_date)
  1896. info = {'id': video_id,
  1897. 'url': video_url,
  1898. 'uploader': None,
  1899. 'upload_date': upload_date,
  1900. 'title': video_title,
  1901. 'ext': 'flv',
  1902. 'format': 'flv'}
  1903. return [info]
  1904. class YouJizzIE(InfoExtractor):
  1905. """Information extractor for youjizz.com."""
  1906. _VALID_URL = r'^(?:https?://)?(?:\w+\.)?youjizz\.com/videos/(?P<videoid>[^.]+).html$'
  1907. def _real_extract(self, url):
  1908. mobj = re.match(self._VALID_URL, url)
  1909. if mobj is None:
  1910. raise ExtractorError(u'Invalid URL: %s' % url)
  1911. video_id = mobj.group('videoid')
  1912. # Get webpage content
  1913. webpage = self._download_webpage(url, video_id)
  1914. # Get the video title
  1915. video_title = self._html_search_regex(r'<title>(?P<title>.*)</title>',
  1916. webpage, u'title').strip()
  1917. # Get the embed page
  1918. result = re.search(r'https?://www.youjizz.com/videos/embed/(?P<videoid>[0-9]+)', webpage)
  1919. if result is None:
  1920. raise ExtractorError(u'ERROR: unable to extract embed page')
  1921. embed_page_url = result.group(0).strip()
  1922. video_id = result.group('videoid')
  1923. webpage = self._download_webpage(embed_page_url, video_id)
  1924. # Get the video URL
  1925. video_url = self._search_regex(r'so.addVariable\("file",encodeURIComponent\("(?P<source>[^"]+)"\)\);',
  1926. webpage, u'video URL')
  1927. info = {'id': video_id,
  1928. 'url': video_url,
  1929. 'title': video_title,
  1930. 'ext': 'flv',
  1931. 'format': 'flv',
  1932. 'player_url': embed_page_url}
  1933. return [info]
  1934. class EightTracksIE(InfoExtractor):
  1935. IE_NAME = '8tracks'
  1936. _VALID_URL = r'https?://8tracks.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
  1937. def _real_extract(self, url):
  1938. mobj = re.match(self._VALID_URL, url)
  1939. if mobj is None:
  1940. raise ExtractorError(u'Invalid URL: %s' % url)
  1941. playlist_id = mobj.group('id')
  1942. webpage = self._download_webpage(url, playlist_id)
  1943. json_like = self._search_regex(r"PAGE.mix = (.*?);\n", webpage, u'trax information', flags=re.DOTALL)
  1944. data = json.loads(json_like)
  1945. session = str(random.randint(0, 1000000000))
  1946. mix_id = data['id']
  1947. track_count = data['tracks_count']
  1948. first_url = 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session, mix_id)
  1949. next_url = first_url
  1950. res = []
  1951. for i in itertools.count():
  1952. api_json = self._download_webpage(next_url, playlist_id,
  1953. note=u'Downloading song information %s/%s' % (str(i+1), track_count),
  1954. errnote=u'Failed to download song information')
  1955. api_data = json.loads(api_json)
  1956. track_data = api_data[u'set']['track']
  1957. info = {
  1958. 'id': track_data['id'],
  1959. 'url': track_data['track_file_stream_url'],
  1960. 'title': track_data['performer'] + u' - ' + track_data['name'],
  1961. 'raw_title': track_data['name'],
  1962. 'uploader_id': data['user']['login'],
  1963. 'ext': 'm4a',
  1964. }
  1965. res.append(info)
  1966. if api_data['set']['at_last_track']:
  1967. break
  1968. next_url = 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % (session, mix_id, track_data['id'])
  1969. return res
  1970. class KeekIE(InfoExtractor):
  1971. _VALID_URL = r'http://(?:www\.)?keek\.com/(?:!|\w+/keeks/)(?P<videoID>\w+)'
  1972. IE_NAME = u'keek'
  1973. def _real_extract(self, url):
  1974. m = re.match(self._VALID_URL, url)
  1975. video_id = m.group('videoID')
  1976. video_url = u'http://cdn.keek.com/keek/video/%s' % video_id
  1977. thumbnail = u'http://cdn.keek.com/keek/thumbnail/%s/w100/h75' % video_id
  1978. webpage = self._download_webpage(url, video_id)
  1979. video_title = self._html_search_regex(r'<meta property="og:title" content="(?P<title>.*?)"',
  1980. webpage, u'title')
  1981. uploader = self._html_search_regex(r'<div class="user-name-and-bio">[\S\s]+?<h2>(?P<uploader>.+?)</h2>',
  1982. webpage, u'uploader', fatal=False)
  1983. info = {
  1984. 'id': video_id,
  1985. 'url': video_url,
  1986. 'ext': 'mp4',
  1987. 'title': video_title,
  1988. 'thumbnail': thumbnail,
  1989. 'uploader': uploader
  1990. }
  1991. return [info]
  1992. class TEDIE(InfoExtractor):
  1993. _VALID_URL=r'''http://www\.ted\.com/
  1994. (
  1995. ((?P<type_playlist>playlists)/(?P<playlist_id>\d+)) # We have a playlist
  1996. |
  1997. ((?P<type_talk>talks)) # We have a simple talk
  1998. )
  1999. (/lang/(.*?))? # The url may contain the language
  2000. /(?P<name>\w+) # Here goes the name and then ".html"
  2001. '''
  2002. @classmethod
  2003. def suitable(cls, url):
  2004. """Receives a URL and returns True if suitable for this IE."""
  2005. return re.match(cls._VALID_URL, url, re.VERBOSE) is not None
  2006. def _real_extract(self, url):
  2007. m=re.match(self._VALID_URL, url, re.VERBOSE)
  2008. if m.group('type_talk'):
  2009. return [self._talk_info(url)]
  2010. else :
  2011. playlist_id=m.group('playlist_id')
  2012. name=m.group('name')
  2013. self.to_screen(u'Getting info of playlist %s: "%s"' % (playlist_id,name))
  2014. return [self._playlist_videos_info(url,name,playlist_id)]
  2015. def _playlist_videos_info(self,url,name,playlist_id=0):
  2016. '''Returns the videos of the playlist'''
  2017. video_RE=r'''
  2018. <li\ id="talk_(\d+)"([.\s]*?)data-id="(?P<video_id>\d+)"
  2019. ([.\s]*?)data-playlist_item_id="(\d+)"
  2020. ([.\s]*?)data-mediaslug="(?P<mediaSlug>.+?)"
  2021. '''
  2022. video_name_RE=r'<p\ class="talk-title"><a href="(?P<talk_url>/talks/(.+).html)">(?P<fullname>.+?)</a></p>'
  2023. webpage=self._download_webpage(url, playlist_id, 'Downloading playlist webpage')
  2024. m_videos=re.finditer(video_RE,webpage,re.VERBOSE)
  2025. m_names=re.finditer(video_name_RE,webpage)
  2026. playlist_title = self._html_search_regex(r'div class="headline">\s*?<h1>\s*?<span>(.*?)</span>',
  2027. webpage, 'playlist title')
  2028. playlist_entries = []
  2029. for m_video, m_name in zip(m_videos,m_names):
  2030. video_id=m_video.group('video_id')
  2031. talk_url='http://www.ted.com%s' % m_name.group('talk_url')
  2032. playlist_entries.append(self.url_result(talk_url, 'TED'))
  2033. return self.playlist_result(playlist_entries, playlist_id = playlist_id, playlist_title = playlist_title)
  2034. def _talk_info(self, url, video_id=0):
  2035. """Return the video for the talk in the url"""
  2036. m = re.match(self._VALID_URL, url,re.VERBOSE)
  2037. video_name = m.group('name')
  2038. webpage = self._download_webpage(url, video_id, 'Downloading \"%s\" page' % video_name)
  2039. self.report_extraction(video_name)
  2040. # If the url includes the language we get the title translated
  2041. title = self._html_search_regex(r'<span id="altHeadline" >(?P<title>.*)</span>',
  2042. webpage, 'title')
  2043. json_data = self._search_regex(r'<script.*?>var talkDetails = ({.*?})</script>',
  2044. webpage, 'json data')
  2045. info = json.loads(json_data)
  2046. desc = self._html_search_regex(r'<div class="talk-intro">.*?<p.*?>(.*?)</p>',
  2047. webpage, 'description', flags = re.DOTALL)
  2048. thumbnail = self._search_regex(r'</span>[\s.]*</div>[\s.]*<img src="(.*?)"',
  2049. webpage, 'thumbnail')
  2050. info = {
  2051. 'id': info['id'],
  2052. 'url': info['htmlStreams'][-1]['file'],
  2053. 'ext': 'mp4',
  2054. 'title': title,
  2055. 'thumbnail': thumbnail,
  2056. 'description': desc,
  2057. }
  2058. return info
  2059. class MySpassIE(InfoExtractor):
  2060. _VALID_URL = r'http://www.myspass.de/.*'
  2061. def _real_extract(self, url):
  2062. META_DATA_URL_TEMPLATE = 'http://www.myspass.de/myspass/includes/apps/video/getvideometadataxml.php?id=%s'
  2063. # video id is the last path element of the URL
  2064. # usually there is a trailing slash, so also try the second but last
  2065. url_path = compat_urllib_parse_urlparse(url).path
  2066. url_parent_path, video_id = os.path.split(url_path)
  2067. if not video_id:
  2068. _, video_id = os.path.split(url_parent_path)
  2069. # get metadata
  2070. metadata_url = META_DATA_URL_TEMPLATE % video_id
  2071. metadata_text = self._download_webpage(metadata_url, video_id)
  2072. metadata = xml.etree.ElementTree.fromstring(metadata_text.encode('utf-8'))
  2073. # extract values from metadata
  2074. url_flv_el = metadata.find('url_flv')
  2075. if url_flv_el is None:
  2076. raise ExtractorError(u'Unable to extract download url')
  2077. video_url = url_flv_el.text
  2078. extension = os.path.splitext(video_url)[1][1:]
  2079. title_el = metadata.find('title')
  2080. if title_el is None:
  2081. raise ExtractorError(u'Unable to extract title')
  2082. title = title_el.text
  2083. format_id_el = metadata.find('format_id')
  2084. if format_id_el is None:
  2085. format = ext
  2086. else:
  2087. format = format_id_el.text
  2088. description_el = metadata.find('description')
  2089. if description_el is not None:
  2090. description = description_el.text
  2091. else:
  2092. description = None
  2093. imagePreview_el = metadata.find('imagePreview')
  2094. if imagePreview_el is not None:
  2095. thumbnail = imagePreview_el.text
  2096. else:
  2097. thumbnail = None
  2098. info = {
  2099. 'id': video_id,
  2100. 'url': video_url,
  2101. 'title': title,
  2102. 'ext': extension,
  2103. 'format': format,
  2104. 'thumbnail': thumbnail,
  2105. 'description': description
  2106. }
  2107. return [info]
  2108. class SpiegelIE(InfoExtractor):
  2109. _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<videoID>[0-9]+)(?:\.html)?(?:#.*)?$'
  2110. def _real_extract(self, url):
  2111. m = re.match(self._VALID_URL, url)
  2112. video_id = m.group('videoID')
  2113. webpage = self._download_webpage(url, video_id)
  2114. video_title = self._html_search_regex(r'<div class="module-title">(.*?)</div>',
  2115. webpage, u'title')
  2116. xml_url = u'http://video2.spiegel.de/flash/' + video_id + u'.xml'
  2117. xml_code = self._download_webpage(xml_url, video_id,
  2118. note=u'Downloading XML', errnote=u'Failed to download XML')
  2119. idoc = xml.etree.ElementTree.fromstring(xml_code)
  2120. last_type = idoc[-1]
  2121. filename = last_type.findall('./filename')[0].text
  2122. duration = float(last_type.findall('./duration')[0].text)
  2123. video_url = 'http://video2.spiegel.de/flash/' + filename
  2124. video_ext = filename.rpartition('.')[2]
  2125. info = {
  2126. 'id': video_id,
  2127. 'url': video_url,
  2128. 'ext': video_ext,
  2129. 'title': video_title,
  2130. 'duration': duration,
  2131. }
  2132. return [info]
  2133. class LiveLeakIE(InfoExtractor):
  2134. _VALID_URL = r'^(?:http?://)?(?:\w+\.)?liveleak\.com/view\?(?:.*?)i=(?P<video_id>[\w_]+)(?:.*)'
  2135. IE_NAME = u'liveleak'
  2136. def _real_extract(self, url):
  2137. mobj = re.match(self._VALID_URL, url)
  2138. if mobj is None:
  2139. raise ExtractorError(u'Invalid URL: %s' % url)
  2140. video_id = mobj.group('video_id')
  2141. webpage = self._download_webpage(url, video_id)
  2142. video_url = self._search_regex(r'file: "(.*?)",',
  2143. webpage, u'video URL')
  2144. video_title = self._html_search_regex(r'<meta property="og:title" content="(?P<title>.*?)"',
  2145. webpage, u'title').replace('LiveLeak.com -', '').strip()
  2146. video_description = self._html_search_regex(r'<meta property="og:description" content="(?P<desc>.*?)"',
  2147. webpage, u'description', fatal=False)
  2148. video_uploader = self._html_search_regex(r'By:.*?(\w+)</a>',
  2149. webpage, u'uploader', fatal=False)
  2150. info = {
  2151. 'id': video_id,
  2152. 'url': video_url,
  2153. 'ext': 'mp4',
  2154. 'title': video_title,
  2155. 'description': video_description,
  2156. 'uploader': video_uploader
  2157. }
  2158. return [info]
  2159. class ARDIE(InfoExtractor):
  2160. _VALID_URL = r'^(?:https?://)?(?:(?:www\.)?ardmediathek\.de|mediathek\.daserste\.de)/(?:.*/)(?P<video_id>[^/\?]+)(?:\?.*)?'
  2161. _TITLE = r'<h1(?: class="boxTopHeadline")?>(?P<title>.*)</h1>'
  2162. _MEDIA_STREAM = r'mediaCollection\.addMediaStream\((?P<media_type>\d+), (?P<quality>\d+), "(?P<rtmp_url>[^"]*)", "(?P<video_url>[^"]*)", "[^"]*"\)'
  2163. def _real_extract(self, url):
  2164. # determine video id from url
  2165. m = re.match(self._VALID_URL, url)
  2166. numid = re.search(r'documentId=([0-9]+)', url)
  2167. if numid:
  2168. video_id = numid.group(1)
  2169. else:
  2170. video_id = m.group('video_id')
  2171. # determine title and media streams from webpage
  2172. html = self._download_webpage(url, video_id)
  2173. title = re.search(self._TITLE, html).group('title')
  2174. streams = [m.groupdict() for m in re.finditer(self._MEDIA_STREAM, html)]
  2175. if not streams:
  2176. assert '"fsk"' in html
  2177. raise ExtractorError(u'This video is only available after 8:00 pm')
  2178. # choose default media type and highest quality for now
  2179. stream = max([s for s in streams if int(s["media_type"]) == 0],
  2180. key=lambda s: int(s["quality"]))
  2181. # there's two possibilities: RTMP stream or HTTP download
  2182. info = {'id': video_id, 'title': title, 'ext': 'mp4'}
  2183. if stream['rtmp_url']:
  2184. self.to_screen(u'RTMP download detected')
  2185. assert stream['video_url'].startswith('mp4:')
  2186. info["url"] = stream["rtmp_url"]
  2187. info["play_path"] = stream['video_url']
  2188. else:
  2189. assert stream["video_url"].endswith('.mp4')
  2190. info["url"] = stream["video_url"]
  2191. return [info]
  2192. class ZDFIE(InfoExtractor):
  2193. _VALID_URL = r'^http://www\.zdf\.de\/ZDFmediathek\/(.*beitrag\/video\/)(?P<video_id>[^/\?]+)(?:\?.*)?'
  2194. _TITLE = r'<h1(?: class="beitragHeadline")?>(?P<title>.*)</h1>'
  2195. _MEDIA_STREAM = r'<a href="(?P<video_url>.+(?P<media_type>.streaming).+/zdf/(?P<quality>[^\/]+)/[^"]*)".+class="play".+>'
  2196. _MMS_STREAM = r'href="(?P<video_url>mms://[^"]*)"'
  2197. _RTSP_STREAM = r'(?P<video_url>rtsp://[^"]*.mp4)'
  2198. def _real_extract(self, url):
  2199. mobj = re.match(self._VALID_URL, url)
  2200. if mobj is None:
  2201. raise ExtractorError(u'Invalid URL: %s' % url)
  2202. video_id = mobj.group('video_id')
  2203. html = self._download_webpage(url, video_id)
  2204. streams = [m.groupdict() for m in re.finditer(self._MEDIA_STREAM, html)]
  2205. if streams is None:
  2206. raise ExtractorError(u'No media url found.')
  2207. # s['media_type'] == 'wstreaming' -> use 'Windows Media Player' and mms url
  2208. # s['media_type'] == 'hstreaming' -> use 'Quicktime' and rtsp url
  2209. # choose first/default media type and highest quality for now
  2210. for s in streams: #find 300 - dsl1000mbit
  2211. if s['quality'] == '300' and s['media_type'] == 'wstreaming':
  2212. stream_=s
  2213. break
  2214. for s in streams: #find veryhigh - dsl2000mbit
  2215. if s['quality'] == 'veryhigh' and s['media_type'] == 'wstreaming': # 'hstreaming' - rtsp is not working
  2216. stream_=s
  2217. break
  2218. if stream_ is None:
  2219. raise ExtractorError(u'No stream found.')
  2220. media_link = self._download_webpage(stream_['video_url'], video_id,'Get stream URL')
  2221. self.report_extraction(video_id)
  2222. mobj = re.search(self._TITLE, html)
  2223. if mobj is None:
  2224. raise ExtractorError(u'Cannot extract title')
  2225. title = unescapeHTML(mobj.group('title'))
  2226. mobj = re.search(self._MMS_STREAM, media_link)
  2227. if mobj is None:
  2228. mobj = re.search(self._RTSP_STREAM, media_link)
  2229. if mobj is None:
  2230. raise ExtractorError(u'Cannot extract mms:// or rtsp:// URL')
  2231. mms_url = mobj.group('video_url')
  2232. mobj = re.search('(.*)[.](?P<ext>[^.]+)', mms_url)
  2233. if mobj is None:
  2234. raise ExtractorError(u'Cannot extract extention')
  2235. ext = mobj.group('ext')
  2236. return [{'id': video_id,
  2237. 'url': mms_url,
  2238. 'title': title,
  2239. 'ext': ext
  2240. }]
  2241. class TumblrIE(InfoExtractor):
  2242. _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/((post)|(video))/(?P<id>\d*)/(.*?)'
  2243. def _real_extract(self, url):
  2244. m_url = re.match(self._VALID_URL, url)
  2245. video_id = m_url.group('id')
  2246. blog = m_url.group('blog_name')
  2247. url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
  2248. webpage = self._download_webpage(url, video_id)
  2249. re_video = r'src=\\x22(?P<video_url>http://%s\.tumblr\.com/video_file/%s/(.*?))\\x22 type=\\x22video/(?P<ext>.*?)\\x22' % (blog, video_id)
  2250. video = re.search(re_video, webpage)
  2251. if video is None:
  2252. raise ExtractorError(u'Unable to extract video')
  2253. video_url = video.group('video_url')
  2254. ext = video.group('ext')
  2255. video_thumbnail = self._search_regex(r'posters(.*?)\[\\x22(?P<thumb>.*?)\\x22',
  2256. webpage, u'thumbnail', fatal=False) # We pick the first poster
  2257. if video_thumbnail: video_thumbnail = video_thumbnail.replace('\\', '')
  2258. # The only place where you can get a title, it's not complete,
  2259. # but searching in other places doesn't work for all videos
  2260. video_title = self._html_search_regex(r'<title>(?P<title>.*?)</title>',
  2261. webpage, u'title', flags=re.DOTALL)
  2262. return [{'id': video_id,
  2263. 'url': video_url,
  2264. 'title': video_title,
  2265. 'thumbnail': video_thumbnail,
  2266. 'ext': ext
  2267. }]
  2268. class BandcampIE(InfoExtractor):
  2269. _VALID_URL = r'http://.*?\.bandcamp\.com/track/(?P<title>.*)'
  2270. def _real_extract(self, url):
  2271. mobj = re.match(self._VALID_URL, url)
  2272. title = mobj.group('title')
  2273. webpage = self._download_webpage(url, title)
  2274. # We get the link to the free download page
  2275. m_download = re.search(r'freeDownloadPage: "(.*?)"', webpage)
  2276. if m_download is None:
  2277. raise ExtractorError(u'No free songs found')
  2278. download_link = m_download.group(1)
  2279. id = re.search(r'var TralbumData = {(.*?)id: (?P<id>\d*?)$',
  2280. webpage, re.MULTILINE|re.DOTALL).group('id')
  2281. download_webpage = self._download_webpage(download_link, id,
  2282. 'Downloading free downloads page')
  2283. # We get the dictionary of the track from some javascrip code
  2284. info = re.search(r'items: (.*?),$',
  2285. download_webpage, re.MULTILINE).group(1)
  2286. info = json.loads(info)[0]
  2287. # We pick mp3-320 for now, until format selection can be easily implemented.
  2288. mp3_info = info[u'downloads'][u'mp3-320']
  2289. # If we try to use this url it says the link has expired
  2290. initial_url = mp3_info[u'url']
  2291. re_url = r'(?P<server>http://(.*?)\.bandcamp\.com)/download/track\?enc=mp3-320&fsig=(?P<fsig>.*?)&id=(?P<id>.*?)&ts=(?P<ts>.*)$'
  2292. m_url = re.match(re_url, initial_url)
  2293. #We build the url we will use to get the final track url
  2294. # This url is build in Bandcamp in the script download_bunde_*.js
  2295. 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'))
  2296. final_url_webpage = self._download_webpage(request_url, id, 'Requesting download url')
  2297. # If we could correctly generate the .rand field the url would be
  2298. #in the "download_url" key
  2299. final_url = re.search(r'"retry_url":"(.*?)"', final_url_webpage).group(1)
  2300. track_info = {'id':id,
  2301. 'title' : info[u'title'],
  2302. 'ext' : 'mp3',
  2303. 'url' : final_url,
  2304. 'thumbnail' : info[u'thumb_url'],
  2305. 'uploader' : info[u'artist']
  2306. }
  2307. return [track_info]
  2308. class RedTubeIE(InfoExtractor):
  2309. """Information Extractor for redtube"""
  2310. _VALID_URL = r'(?:http://)?(?:www\.)?redtube\.com/(?P<id>[0-9]+)'
  2311. def _real_extract(self,url):
  2312. mobj = re.match(self._VALID_URL, url)
  2313. if mobj is None:
  2314. raise ExtractorError(u'Invalid URL: %s' % url)
  2315. video_id = mobj.group('id')
  2316. video_extension = 'mp4'
  2317. webpage = self._download_webpage(url, video_id)
  2318. self.report_extraction(video_id)
  2319. video_url = self._html_search_regex(r'<source src="(.+?)" type="video/mp4">',
  2320. webpage, u'video URL')
  2321. video_title = self._html_search_regex('<h1 class="videoTitle slidePanelMovable">(.+?)</h1>',
  2322. webpage, u'title')
  2323. return [{
  2324. 'id': video_id,
  2325. 'url': video_url,
  2326. 'ext': video_extension,
  2327. 'title': video_title,
  2328. }]
  2329. class InaIE(InfoExtractor):
  2330. """Information Extractor for Ina.fr"""
  2331. _VALID_URL = r'(?:http://)?(?:www\.)?ina\.fr/video/(?P<id>I[0-9]+)/.*'
  2332. def _real_extract(self,url):
  2333. mobj = re.match(self._VALID_URL, url)
  2334. video_id = mobj.group('id')
  2335. mrss_url='http://player.ina.fr/notices/%s.mrss' % video_id
  2336. video_extension = 'mp4'
  2337. webpage = self._download_webpage(mrss_url, video_id)
  2338. self.report_extraction(video_id)
  2339. video_url = self._html_search_regex(r'<media:player url="(?P<mp4url>http://mp4.ina.fr/[^"]+\.mp4)',
  2340. webpage, u'video URL')
  2341. video_title = self._search_regex(r'<title><!\[CDATA\[(?P<titre>.*?)]]></title>',
  2342. webpage, u'title')
  2343. return [{
  2344. 'id': video_id,
  2345. 'url': video_url,
  2346. 'ext': video_extension,
  2347. 'title': video_title,
  2348. }]
  2349. class HowcastIE(InfoExtractor):
  2350. """Information Extractor for Howcast.com"""
  2351. _VALID_URL = r'(?:https?://)?(?:www\.)?howcast\.com/videos/(?P<id>\d+)'
  2352. def _real_extract(self, url):
  2353. mobj = re.match(self._VALID_URL, url)
  2354. video_id = mobj.group('id')
  2355. webpage_url = 'http://www.howcast.com/videos/' + video_id
  2356. webpage = self._download_webpage(webpage_url, video_id)
  2357. self.report_extraction(video_id)
  2358. video_url = self._search_regex(r'\'?file\'?: "(http://mobile-media\.howcast\.com/[0-9]+\.mp4)',
  2359. webpage, u'video URL')
  2360. video_title = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') property=\'og:title\'',
  2361. webpage, u'title')
  2362. video_description = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') name=\'description\'',
  2363. webpage, u'description', fatal=False)
  2364. thumbnail = self._html_search_regex(r'<meta content=\'(.+?)\' property=\'og:image\'',
  2365. webpage, u'thumbnail', fatal=False)
  2366. return [{
  2367. 'id': video_id,
  2368. 'url': video_url,
  2369. 'ext': 'mp4',
  2370. 'title': video_title,
  2371. 'description': video_description,
  2372. 'thumbnail': thumbnail,
  2373. }]
  2374. class VineIE(InfoExtractor):
  2375. """Information Extractor for Vine.co"""
  2376. _VALID_URL = r'(?:https?://)?(?:www\.)?vine\.co/v/(?P<id>\w+)'
  2377. def _real_extract(self, url):
  2378. mobj = re.match(self._VALID_URL, url)
  2379. video_id = mobj.group('id')
  2380. webpage_url = 'https://vine.co/v/' + video_id
  2381. webpage = self._download_webpage(webpage_url, video_id)
  2382. self.report_extraction(video_id)
  2383. video_url = self._html_search_regex(r'<meta property="twitter:player:stream" content="(.+?)"',
  2384. webpage, u'video URL')
  2385. video_title = self._html_search_regex(r'<meta property="og:title" content="(.+?)"',
  2386. webpage, u'title')
  2387. thumbnail = self._html_search_regex(r'<meta property="og:image" content="(.+?)(\?.*?)?"',
  2388. webpage, u'thumbnail', fatal=False)
  2389. uploader = self._html_search_regex(r'<div class="user">.*?<h2>(.+?)</h2>',
  2390. webpage, u'uploader', fatal=False, flags=re.DOTALL)
  2391. return [{
  2392. 'id': video_id,
  2393. 'url': video_url,
  2394. 'ext': 'mp4',
  2395. 'title': video_title,
  2396. 'thumbnail': thumbnail,
  2397. 'uploader': uploader,
  2398. }]
  2399. class FlickrIE(InfoExtractor):
  2400. """Information Extractor for Flickr videos"""
  2401. _VALID_URL = r'(?:https?://)?(?:www\.)?flickr\.com/photos/(?P<uploader_id>[\w\-_@]+)/(?P<id>\d+).*'
  2402. def _real_extract(self, url):
  2403. mobj = re.match(self._VALID_URL, url)
  2404. video_id = mobj.group('id')
  2405. video_uploader_id = mobj.group('uploader_id')
  2406. webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id
  2407. webpage = self._download_webpage(webpage_url, video_id)
  2408. secret = self._search_regex(r"photo_secret: '(\w+)'", webpage, u'secret')
  2409. first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self'
  2410. first_xml = self._download_webpage(first_url, video_id, 'Downloading first data webpage')
  2411. node_id = self._html_search_regex(r'<Item id="id">(\d+-\d+)</Item>',
  2412. first_xml, u'node_id')
  2413. 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'
  2414. second_xml = self._download_webpage(second_url, video_id, 'Downloading second data webpage')
  2415. self.report_extraction(video_id)
  2416. mobj = re.search(r'<STREAM APP="(.+?)" FULLPATH="(.+?)"', second_xml)
  2417. if mobj is None:
  2418. raise ExtractorError(u'Unable to extract video url')
  2419. video_url = mobj.group(1) + unescapeHTML(mobj.group(2))
  2420. video_title = self._html_search_regex(r'<meta property="og:title" content=(?:"([^"]+)"|\'([^\']+)\')',
  2421. webpage, u'video title')
  2422. video_description = self._html_search_regex(r'<meta property="og:description" content=(?:"([^"]+)"|\'([^\']+)\')',
  2423. webpage, u'description', fatal=False)
  2424. thumbnail = self._html_search_regex(r'<meta property="og:image" content=(?:"([^"]+)"|\'([^\']+)\')',
  2425. webpage, u'thumbnail', fatal=False)
  2426. return [{
  2427. 'id': video_id,
  2428. 'url': video_url,
  2429. 'ext': 'mp4',
  2430. 'title': video_title,
  2431. 'description': video_description,
  2432. 'thumbnail': thumbnail,
  2433. 'uploader_id': video_uploader_id,
  2434. }]
  2435. class TeamcocoIE(InfoExtractor):
  2436. _VALID_URL = r'http://teamcoco\.com/video/(?P<url_title>.*)'
  2437. def _real_extract(self, url):
  2438. mobj = re.match(self._VALID_URL, url)
  2439. if mobj is None:
  2440. raise ExtractorError(u'Invalid URL: %s' % url)
  2441. url_title = mobj.group('url_title')
  2442. webpage = self._download_webpage(url, url_title)
  2443. video_id = self._html_search_regex(r'<article class="video" data-id="(\d+?)"',
  2444. webpage, u'video id')
  2445. self.report_extraction(video_id)
  2446. video_title = self._html_search_regex(r'<meta property="og:title" content="(.+?)"',
  2447. webpage, u'title')
  2448. thumbnail = self._html_search_regex(r'<meta property="og:image" content="(.+?)"',
  2449. webpage, u'thumbnail', fatal=False)
  2450. video_description = self._html_search_regex(r'<meta property="og:description" content="(.*?)"',
  2451. webpage, u'description', fatal=False)
  2452. data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
  2453. data = self._download_webpage(data_url, video_id, 'Downloading data webpage')
  2454. video_url = self._html_search_regex(r'<file type="high".*?>(.*?)</file>',
  2455. data, u'video URL')
  2456. return [{
  2457. 'id': video_id,
  2458. 'url': video_url,
  2459. 'ext': 'mp4',
  2460. 'title': video_title,
  2461. 'thumbnail': thumbnail,
  2462. 'description': video_description,
  2463. }]
  2464. class XHamsterIE(InfoExtractor):
  2465. """Information Extractor for xHamster"""
  2466. _VALID_URL = r'(?:http://)?(?:www.)?xhamster\.com/movies/(?P<id>[0-9]+)/.*\.html'
  2467. def _real_extract(self,url):
  2468. mobj = re.match(self._VALID_URL, url)
  2469. video_id = mobj.group('id')
  2470. mrss_url = 'http://xhamster.com/movies/%s/.html' % video_id
  2471. webpage = self._download_webpage(mrss_url, video_id)
  2472. mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
  2473. if mobj is None:
  2474. raise ExtractorError(u'Unable to extract media URL')
  2475. if len(mobj.group('server')) == 0:
  2476. video_url = compat_urllib_parse.unquote(mobj.group('file'))
  2477. else:
  2478. video_url = mobj.group('server')+'/key='+mobj.group('file')
  2479. video_extension = video_url.split('.')[-1]
  2480. video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
  2481. webpage, u'title')
  2482. # Can't see the description anywhere in the UI
  2483. # video_description = self._html_search_regex(r'<span>Description: </span>(?P<description>[^<]+)',
  2484. # webpage, u'description', fatal=False)
  2485. # if video_description: video_description = unescapeHTML(video_description)
  2486. 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)
  2487. if mobj:
  2488. video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
  2489. else:
  2490. video_upload_date = None
  2491. self._downloader.report_warning(u'Unable to extract upload date')
  2492. video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
  2493. webpage, u'uploader id', default=u'anonymous')
  2494. video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
  2495. webpage, u'thumbnail', fatal=False)
  2496. return [{
  2497. 'id': video_id,
  2498. 'url': video_url,
  2499. 'ext': video_extension,
  2500. 'title': video_title,
  2501. # 'description': video_description,
  2502. 'upload_date': video_upload_date,
  2503. 'uploader_id': video_uploader_id,
  2504. 'thumbnail': video_thumbnail
  2505. }]
  2506. class HypemIE(InfoExtractor):
  2507. """Information Extractor for hypem"""
  2508. _VALID_URL = r'(?:http://)?(?:www\.)?hypem\.com/track/([^/]+)/([^/]+)'
  2509. def _real_extract(self, url):
  2510. mobj = re.match(self._VALID_URL, url)
  2511. if mobj is None:
  2512. raise ExtractorError(u'Invalid URL: %s' % url)
  2513. track_id = mobj.group(1)
  2514. data = { 'ax': 1, 'ts': time.time() }
  2515. data_encoded = compat_urllib_parse.urlencode(data)
  2516. complete_url = url + "?" + data_encoded
  2517. request = compat_urllib_request.Request(complete_url)
  2518. response, urlh = self._download_webpage_handle(request, track_id, u'Downloading webpage with the url')
  2519. cookie = urlh.headers.get('Set-Cookie', '')
  2520. self.report_extraction(track_id)
  2521. html_tracks = self._html_search_regex(r'<script type="application/json" id="displayList-data">(.*?)</script>',
  2522. response, u'tracks', flags=re.MULTILINE|re.DOTALL).strip()
  2523. try:
  2524. track_list = json.loads(html_tracks)
  2525. track = track_list[u'tracks'][0]
  2526. except ValueError:
  2527. raise ExtractorError(u'Hypemachine contained invalid JSON.')
  2528. key = track[u"key"]
  2529. track_id = track[u"id"]
  2530. artist = track[u"artist"]
  2531. title = track[u"song"]
  2532. serve_url = "http://hypem.com/serve/source/%s/%s" % (compat_str(track_id), compat_str(key))
  2533. request = compat_urllib_request.Request(serve_url, "" , {'Content-Type': 'application/json'})
  2534. request.add_header('cookie', cookie)
  2535. song_data_json = self._download_webpage(request, track_id, u'Downloading metadata')
  2536. try:
  2537. song_data = json.loads(song_data_json)
  2538. except ValueError:
  2539. raise ExtractorError(u'Hypemachine contained invalid JSON.')
  2540. final_url = song_data[u"url"]
  2541. return [{
  2542. 'id': track_id,
  2543. 'url': final_url,
  2544. 'ext': "mp3",
  2545. 'title': title,
  2546. 'artist': artist,
  2547. }]
  2548. class Vbox7IE(InfoExtractor):
  2549. """Information Extractor for Vbox7"""
  2550. _VALID_URL = r'(?:http://)?(?:www\.)?vbox7\.com/play:([^/]+)'
  2551. def _real_extract(self,url):
  2552. mobj = re.match(self._VALID_URL, url)
  2553. if mobj is None:
  2554. raise ExtractorError(u'Invalid URL: %s' % url)
  2555. video_id = mobj.group(1)
  2556. redirect_page, urlh = self._download_webpage_handle(url, video_id)
  2557. new_location = self._search_regex(r'window\.location = \'(.*)\';', redirect_page, u'redirect location')
  2558. redirect_url = urlh.geturl() + new_location
  2559. webpage = self._download_webpage(redirect_url, video_id, u'Downloading redirect page')
  2560. title = self._html_search_regex(r'<title>(.*)</title>',
  2561. webpage, u'title').split('/')[0].strip()
  2562. ext = "flv"
  2563. info_url = "http://vbox7.com/play/magare.do"
  2564. data = compat_urllib_parse.urlencode({'as3':'1','vid':video_id})
  2565. info_request = compat_urllib_request.Request(info_url, data)
  2566. info_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  2567. info_response = self._download_webpage(info_request, video_id, u'Downloading info webpage')
  2568. if info_response is None:
  2569. raise ExtractorError(u'Unable to extract the media url')
  2570. (final_url, thumbnail_url) = map(lambda x: x.split('=')[1], info_response.split('&'))
  2571. return [{
  2572. 'id': video_id,
  2573. 'url': final_url,
  2574. 'ext': ext,
  2575. 'title': title,
  2576. 'thumbnail': thumbnail_url,
  2577. }]
  2578. class GametrailersIE(InfoExtractor):
  2579. _VALID_URL = r'http://www.gametrailers.com/(?P<type>videos|reviews|full-episodes)/(?P<id>.*?)/(?P<title>.*)'
  2580. def _real_extract(self, url):
  2581. mobj = re.match(self._VALID_URL, url)
  2582. if mobj is None:
  2583. raise ExtractorError(u'Invalid URL: %s' % url)
  2584. video_id = mobj.group('id')
  2585. video_type = mobj.group('type')
  2586. webpage = self._download_webpage(url, video_id)
  2587. if video_type == 'full-episodes':
  2588. mgid_re = r'data-video="(?P<mgid>mgid:.*?)"'
  2589. else:
  2590. mgid_re = r'data-contentId=\'(?P<mgid>mgid:.*?)\''
  2591. mgid = self._search_regex(mgid_re, webpage, u'mgid')
  2592. data = compat_urllib_parse.urlencode({'uri': mgid, 'acceptMethods': 'fms'})
  2593. info_page = self._download_webpage('http://www.gametrailers.com/feeds/mrss?' + data,
  2594. video_id, u'Downloading video info')
  2595. links_webpage = self._download_webpage('http://www.gametrailers.com/feeds/mediagen/?' + data,
  2596. video_id, u'Downloading video urls info')
  2597. self.report_extraction(video_id)
  2598. info_re = r'''<title><!\[CDATA\[(?P<title>.*?)\]\]></title>.*
  2599. <description><!\[CDATA\[(?P<description>.*?)\]\]></description>.*
  2600. <image>.*
  2601. <url>(?P<thumb>.*?)</url>.*
  2602. </image>'''
  2603. m_info = re.search(info_re, info_page, re.VERBOSE|re.DOTALL)
  2604. if m_info is None:
  2605. raise ExtractorError(u'Unable to extract video info')
  2606. video_title = m_info.group('title')
  2607. video_description = m_info.group('description')
  2608. video_thumb = m_info.group('thumb')
  2609. m_urls = list(re.finditer(r'<src>(?P<url>.*)</src>', links_webpage))
  2610. if m_urls is None or len(m_urls) == 0:
  2611. raise ExtractError(u'Unable to extrat video url')
  2612. # They are sorted from worst to best quality
  2613. video_url = m_urls[-1].group('url')
  2614. return {'url': video_url,
  2615. 'id': video_id,
  2616. 'title': video_title,
  2617. # Videos are actually flv not mp4
  2618. 'ext': 'flv',
  2619. 'thumbnail': video_thumb,
  2620. 'description': video_description,
  2621. }
  2622. def gen_extractors():
  2623. """ Return a list of an instance of every supported extractor.
  2624. The order does matter; the first extractor matched is the one handling the URL.
  2625. """
  2626. return [
  2627. YoutubePlaylistIE(),
  2628. YoutubeChannelIE(),
  2629. YoutubeUserIE(),
  2630. YoutubeSearchIE(),
  2631. YoutubeIE(),
  2632. MetacafeIE(),
  2633. DailymotionIE(),
  2634. GoogleSearchIE(),
  2635. PhotobucketIE(),
  2636. YahooIE(),
  2637. YahooSearchIE(),
  2638. DepositFilesIE(),
  2639. FacebookIE(),
  2640. BlipTVIE(),
  2641. BlipTVUserIE(),
  2642. VimeoIE(),
  2643. MyVideoIE(),
  2644. ComedyCentralIE(),
  2645. EscapistIE(),
  2646. CollegeHumorIE(),
  2647. XVideosIE(),
  2648. SoundcloudSetIE(),
  2649. SoundcloudIE(),
  2650. InfoQIE(),
  2651. MixcloudIE(),
  2652. StanfordOpenClassroomIE(),
  2653. MTVIE(),
  2654. YoukuIE(),
  2655. XNXXIE(),
  2656. YouJizzIE(),
  2657. PornotubeIE(),
  2658. YouPornIE(),
  2659. GooglePlusIE(),
  2660. ArteTvIE(),
  2661. NBAIE(),
  2662. WorldStarHipHopIE(),
  2663. JustinTVIE(),
  2664. FunnyOrDieIE(),
  2665. SteamIE(),
  2666. UstreamIE(),
  2667. RBMARadioIE(),
  2668. EightTracksIE(),
  2669. KeekIE(),
  2670. TEDIE(),
  2671. MySpassIE(),
  2672. SpiegelIE(),
  2673. LiveLeakIE(),
  2674. ARDIE(),
  2675. ZDFIE(),
  2676. TumblrIE(),
  2677. BandcampIE(),
  2678. RedTubeIE(),
  2679. InaIE(),
  2680. HowcastIE(),
  2681. VineIE(),
  2682. FlickrIE(),
  2683. TeamcocoIE(),
  2684. XHamsterIE(),
  2685. HypemIE(),
  2686. Vbox7IE(),
  2687. GametrailersIE(),
  2688. StatigramIE(),
  2689. GenericIE()
  2690. ]
  2691. def get_info_extractor(ie_name):
  2692. """Returns the info extractor class with the given ie_name"""
  2693. return globals()[ie_name+'IE']