InfoExtractors.py 108 KB

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