2
0

InfoExtractors.py 107 KB

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