InfoExtractors.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. import base64
  2. import datetime
  3. import itertools
  4. import netrc
  5. import os
  6. import re
  7. import socket
  8. import time
  9. import email.utils
  10. import xml.etree.ElementTree
  11. import random
  12. import math
  13. import operator
  14. import hashlib
  15. import binascii
  16. import urllib
  17. from .utils import *
  18. from .extractor.common import InfoExtractor, SearchInfoExtractor
  19. from .extractor.ard import ARDIE
  20. from .extractor.arte import ArteTvIE
  21. from .extractor.bliptv import BlipTVIE, BlipTVUserIE
  22. from .extractor.comedycentral import ComedyCentralIE
  23. from .extractor.collegehumor import CollegeHumorIE
  24. from .extractor.dailymotion import DailymotionIE
  25. from .extractor.depositfiles import DepositFilesIE
  26. from .extractor.eighttracks import EightTracksIE
  27. from .extractor.escapist import EscapistIE
  28. from .extractor.facebook import FacebookIE
  29. from .extractor.funnyordie import FunnyOrDieIE
  30. from .extractor.gametrailers import GametrailersIE
  31. from .extractor.generic import GenericIE
  32. from .extractor.googleplus import GooglePlusIE
  33. from .extractor.googlesearch import GoogleSearchIE
  34. from .extractor.infoq import InfoQIE
  35. from .extractor.justintv import JustinTVIE
  36. from .extractor.keek import KeekIE
  37. from .extractor.metacafe import MetacafeIE
  38. from .extractor.mixcloud import MixcloudIE
  39. from .extractor.mtv import MTVIE
  40. from .extractor.myspass import MySpassIE
  41. from .extractor.myvideo import MyVideoIE
  42. from .extractor.nba import NBAIE
  43. from .extractor.statigram import StatigramIE
  44. from .extractor.photobucket import PhotobucketIE
  45. from .extractor.pornotube import PornotubeIE
  46. from .extractor.rbmaradio import RBMARadioIE
  47. from .extractor.soundcloud import SoundcloudIE, SoundcloudSetIE
  48. from .extractor.stanfordoc import StanfordOpenClassroomIE
  49. from .extractor.steam import SteamIE
  50. from .extractor.ted import TEDIE
  51. from .extractor.ustream import UstreamIE
  52. from .extractor.vimeo import VimeoIE
  53. from .extractor.worldstarhiphop import WorldStarHipHopIE
  54. from .extractor.xnxx import XNXXIE
  55. from .extractor.xvideos import XVideosIE
  56. from .extractor.yahoo import YahooIE, YahooSearchIE
  57. from .extractor.youjizz import YouJizzIE
  58. from .extractor.youku import YoukuIE
  59. from .extractor.youporn import YouPornIE
  60. from .extractor.youtube import YoutubeIE, YoutubePlaylistIE, YoutubeSearchIE, YoutubeUserIE, YoutubeChannelIE
  61. from .extractor.zdf import ZDFIE
  62. class SpiegelIE(InfoExtractor):
  63. _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<videoID>[0-9]+)(?:\.html)?(?:#.*)?$'
  64. def _real_extract(self, url):
  65. m = re.match(self._VALID_URL, url)
  66. video_id = m.group('videoID')
  67. webpage = self._download_webpage(url, video_id)
  68. video_title = self._html_search_regex(r'<div class="module-title">(.*?)</div>',
  69. webpage, u'title')
  70. xml_url = u'http://video2.spiegel.de/flash/' + video_id + u'.xml'
  71. xml_code = self._download_webpage(xml_url, video_id,
  72. note=u'Downloading XML', errnote=u'Failed to download XML')
  73. idoc = xml.etree.ElementTree.fromstring(xml_code)
  74. last_type = idoc[-1]
  75. filename = last_type.findall('./filename')[0].text
  76. duration = float(last_type.findall('./duration')[0].text)
  77. video_url = 'http://video2.spiegel.de/flash/' + filename
  78. video_ext = filename.rpartition('.')[2]
  79. info = {
  80. 'id': video_id,
  81. 'url': video_url,
  82. 'ext': video_ext,
  83. 'title': video_title,
  84. 'duration': duration,
  85. }
  86. return [info]
  87. class LiveLeakIE(InfoExtractor):
  88. _VALID_URL = r'^(?:http?://)?(?:\w+\.)?liveleak\.com/view\?(?:.*?)i=(?P<video_id>[\w_]+)(?:.*)'
  89. IE_NAME = u'liveleak'
  90. def _real_extract(self, url):
  91. mobj = re.match(self._VALID_URL, url)
  92. if mobj is None:
  93. raise ExtractorError(u'Invalid URL: %s' % url)
  94. video_id = mobj.group('video_id')
  95. webpage = self._download_webpage(url, video_id)
  96. video_url = self._search_regex(r'file: "(.*?)",',
  97. webpage, u'video URL')
  98. video_title = self._html_search_regex(r'<meta property="og:title" content="(?P<title>.*?)"',
  99. webpage, u'title').replace('LiveLeak.com -', '').strip()
  100. video_description = self._html_search_regex(r'<meta property="og:description" content="(?P<desc>.*?)"',
  101. webpage, u'description', fatal=False)
  102. video_uploader = self._html_search_regex(r'By:.*?(\w+)</a>',
  103. webpage, u'uploader', fatal=False)
  104. info = {
  105. 'id': video_id,
  106. 'url': video_url,
  107. 'ext': 'mp4',
  108. 'title': video_title,
  109. 'description': video_description,
  110. 'uploader': video_uploader
  111. }
  112. return [info]
  113. class TumblrIE(InfoExtractor):
  114. _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/((post)|(video))/(?P<id>\d*)/(.*?)'
  115. def _real_extract(self, url):
  116. m_url = re.match(self._VALID_URL, url)
  117. video_id = m_url.group('id')
  118. blog = m_url.group('blog_name')
  119. url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
  120. webpage = self._download_webpage(url, video_id)
  121. re_video = r'src=\\x22(?P<video_url>http://%s\.tumblr\.com/video_file/%s/(.*?))\\x22 type=\\x22video/(?P<ext>.*?)\\x22' % (blog, video_id)
  122. video = re.search(re_video, webpage)
  123. if video is None:
  124. raise ExtractorError(u'Unable to extract video')
  125. video_url = video.group('video_url')
  126. ext = video.group('ext')
  127. video_thumbnail = self._search_regex(r'posters(.*?)\[\\x22(?P<thumb>.*?)\\x22',
  128. webpage, u'thumbnail', fatal=False) # We pick the first poster
  129. if video_thumbnail: video_thumbnail = video_thumbnail.replace('\\', '')
  130. # The only place where you can get a title, it's not complete,
  131. # but searching in other places doesn't work for all videos
  132. video_title = self._html_search_regex(r'<title>(?P<title>.*?)</title>',
  133. webpage, u'title', flags=re.DOTALL)
  134. return [{'id': video_id,
  135. 'url': video_url,
  136. 'title': video_title,
  137. 'thumbnail': video_thumbnail,
  138. 'ext': ext
  139. }]
  140. class BandcampIE(InfoExtractor):
  141. _VALID_URL = r'http://.*?\.bandcamp\.com/track/(?P<title>.*)'
  142. def _real_extract(self, url):
  143. mobj = re.match(self._VALID_URL, url)
  144. title = mobj.group('title')
  145. webpage = self._download_webpage(url, title)
  146. # We get the link to the free download page
  147. m_download = re.search(r'freeDownloadPage: "(.*?)"', webpage)
  148. if m_download is None:
  149. raise ExtractorError(u'No free songs found')
  150. download_link = m_download.group(1)
  151. id = re.search(r'var TralbumData = {(.*?)id: (?P<id>\d*?)$',
  152. webpage, re.MULTILINE|re.DOTALL).group('id')
  153. download_webpage = self._download_webpage(download_link, id,
  154. 'Downloading free downloads page')
  155. # We get the dictionary of the track from some javascrip code
  156. info = re.search(r'items: (.*?),$',
  157. download_webpage, re.MULTILINE).group(1)
  158. info = json.loads(info)[0]
  159. # We pick mp3-320 for now, until format selection can be easily implemented.
  160. mp3_info = info[u'downloads'][u'mp3-320']
  161. # If we try to use this url it says the link has expired
  162. initial_url = mp3_info[u'url']
  163. re_url = r'(?P<server>http://(.*?)\.bandcamp\.com)/download/track\?enc=mp3-320&fsig=(?P<fsig>.*?)&id=(?P<id>.*?)&ts=(?P<ts>.*)$'
  164. m_url = re.match(re_url, initial_url)
  165. #We build the url we will use to get the final track url
  166. # This url is build in Bandcamp in the script download_bunde_*.js
  167. 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'))
  168. final_url_webpage = self._download_webpage(request_url, id, 'Requesting download url')
  169. # If we could correctly generate the .rand field the url would be
  170. #in the "download_url" key
  171. final_url = re.search(r'"retry_url":"(.*?)"', final_url_webpage).group(1)
  172. track_info = {'id':id,
  173. 'title' : info[u'title'],
  174. 'ext' : 'mp3',
  175. 'url' : final_url,
  176. 'thumbnail' : info[u'thumb_url'],
  177. 'uploader' : info[u'artist']
  178. }
  179. return [track_info]
  180. class RedTubeIE(InfoExtractor):
  181. """Information Extractor for redtube"""
  182. _VALID_URL = r'(?:http://)?(?:www\.)?redtube\.com/(?P<id>[0-9]+)'
  183. def _real_extract(self,url):
  184. mobj = re.match(self._VALID_URL, url)
  185. if mobj is None:
  186. raise ExtractorError(u'Invalid URL: %s' % url)
  187. video_id = mobj.group('id')
  188. video_extension = 'mp4'
  189. webpage = self._download_webpage(url, video_id)
  190. self.report_extraction(video_id)
  191. video_url = self._html_search_regex(r'<source src="(.+?)" type="video/mp4">',
  192. webpage, u'video URL')
  193. video_title = self._html_search_regex('<h1 class="videoTitle slidePanelMovable">(.+?)</h1>',
  194. webpage, u'title')
  195. return [{
  196. 'id': video_id,
  197. 'url': video_url,
  198. 'ext': video_extension,
  199. 'title': video_title,
  200. }]
  201. class InaIE(InfoExtractor):
  202. """Information Extractor for Ina.fr"""
  203. _VALID_URL = r'(?:http://)?(?:www\.)?ina\.fr/video/(?P<id>I[0-9]+)/.*'
  204. def _real_extract(self,url):
  205. mobj = re.match(self._VALID_URL, url)
  206. video_id = mobj.group('id')
  207. mrss_url='http://player.ina.fr/notices/%s.mrss' % video_id
  208. video_extension = 'mp4'
  209. webpage = self._download_webpage(mrss_url, video_id)
  210. self.report_extraction(video_id)
  211. video_url = self._html_search_regex(r'<media:player url="(?P<mp4url>http://mp4.ina.fr/[^"]+\.mp4)',
  212. webpage, u'video URL')
  213. video_title = self._search_regex(r'<title><!\[CDATA\[(?P<titre>.*?)]]></title>',
  214. webpage, u'title')
  215. return [{
  216. 'id': video_id,
  217. 'url': video_url,
  218. 'ext': video_extension,
  219. 'title': video_title,
  220. }]
  221. class HowcastIE(InfoExtractor):
  222. """Information Extractor for Howcast.com"""
  223. _VALID_URL = r'(?:https?://)?(?:www\.)?howcast\.com/videos/(?P<id>\d+)'
  224. def _real_extract(self, url):
  225. mobj = re.match(self._VALID_URL, url)
  226. video_id = mobj.group('id')
  227. webpage_url = 'http://www.howcast.com/videos/' + video_id
  228. webpage = self._download_webpage(webpage_url, video_id)
  229. self.report_extraction(video_id)
  230. video_url = self._search_regex(r'\'?file\'?: "(http://mobile-media\.howcast\.com/[0-9]+\.mp4)',
  231. webpage, u'video URL')
  232. video_title = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') property=\'og:title\'',
  233. webpage, u'title')
  234. video_description = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') name=\'description\'',
  235. webpage, u'description', fatal=False)
  236. thumbnail = self._html_search_regex(r'<meta content=\'(.+?)\' property=\'og:image\'',
  237. webpage, u'thumbnail', fatal=False)
  238. return [{
  239. 'id': video_id,
  240. 'url': video_url,
  241. 'ext': 'mp4',
  242. 'title': video_title,
  243. 'description': video_description,
  244. 'thumbnail': thumbnail,
  245. }]
  246. class VineIE(InfoExtractor):
  247. """Information Extractor for Vine.co"""
  248. _VALID_URL = r'(?:https?://)?(?:www\.)?vine\.co/v/(?P<id>\w+)'
  249. def _real_extract(self, url):
  250. mobj = re.match(self._VALID_URL, url)
  251. video_id = mobj.group('id')
  252. webpage_url = 'https://vine.co/v/' + video_id
  253. webpage = self._download_webpage(webpage_url, video_id)
  254. self.report_extraction(video_id)
  255. video_url = self._html_search_regex(r'<meta property="twitter:player:stream" content="(.+?)"',
  256. webpage, u'video URL')
  257. video_title = self._html_search_regex(r'<meta property="og:title" content="(.+?)"',
  258. webpage, u'title')
  259. thumbnail = self._html_search_regex(r'<meta property="og:image" content="(.+?)(\?.*?)?"',
  260. webpage, u'thumbnail', fatal=False)
  261. uploader = self._html_search_regex(r'<div class="user">.*?<h2>(.+?)</h2>',
  262. webpage, u'uploader', fatal=False, flags=re.DOTALL)
  263. return [{
  264. 'id': video_id,
  265. 'url': video_url,
  266. 'ext': 'mp4',
  267. 'title': video_title,
  268. 'thumbnail': thumbnail,
  269. 'uploader': uploader,
  270. }]
  271. class FlickrIE(InfoExtractor):
  272. """Information Extractor for Flickr videos"""
  273. _VALID_URL = r'(?:https?://)?(?:www\.)?flickr\.com/photos/(?P<uploader_id>[\w\-_@]+)/(?P<id>\d+).*'
  274. def _real_extract(self, url):
  275. mobj = re.match(self._VALID_URL, url)
  276. video_id = mobj.group('id')
  277. video_uploader_id = mobj.group('uploader_id')
  278. webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id
  279. webpage = self._download_webpage(webpage_url, video_id)
  280. secret = self._search_regex(r"photo_secret: '(\w+)'", webpage, u'secret')
  281. first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self'
  282. first_xml = self._download_webpage(first_url, video_id, 'Downloading first data webpage')
  283. node_id = self._html_search_regex(r'<Item id="id">(\d+-\d+)</Item>',
  284. first_xml, u'node_id')
  285. 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'
  286. second_xml = self._download_webpage(second_url, video_id, 'Downloading second data webpage')
  287. self.report_extraction(video_id)
  288. mobj = re.search(r'<STREAM APP="(.+?)" FULLPATH="(.+?)"', second_xml)
  289. if mobj is None:
  290. raise ExtractorError(u'Unable to extract video url')
  291. video_url = mobj.group(1) + unescapeHTML(mobj.group(2))
  292. video_title = self._html_search_regex(r'<meta property="og:title" content=(?:"([^"]+)"|\'([^\']+)\')',
  293. webpage, u'video title')
  294. video_description = self._html_search_regex(r'<meta property="og:description" content=(?:"([^"]+)"|\'([^\']+)\')',
  295. webpage, u'description', fatal=False)
  296. thumbnail = self._html_search_regex(r'<meta property="og:image" content=(?:"([^"]+)"|\'([^\']+)\')',
  297. webpage, u'thumbnail', fatal=False)
  298. return [{
  299. 'id': video_id,
  300. 'url': video_url,
  301. 'ext': 'mp4',
  302. 'title': video_title,
  303. 'description': video_description,
  304. 'thumbnail': thumbnail,
  305. 'uploader_id': video_uploader_id,
  306. }]
  307. class TeamcocoIE(InfoExtractor):
  308. _VALID_URL = r'http://teamcoco\.com/video/(?P<url_title>.*)'
  309. def _real_extract(self, url):
  310. mobj = re.match(self._VALID_URL, url)
  311. if mobj is None:
  312. raise ExtractorError(u'Invalid URL: %s' % url)
  313. url_title = mobj.group('url_title')
  314. webpage = self._download_webpage(url, url_title)
  315. video_id = self._html_search_regex(r'<article class="video" data-id="(\d+?)"',
  316. webpage, u'video id')
  317. self.report_extraction(video_id)
  318. video_title = self._html_search_regex(r'<meta property="og:title" content="(.+?)"',
  319. webpage, u'title')
  320. thumbnail = self._html_search_regex(r'<meta property="og:image" content="(.+?)"',
  321. webpage, u'thumbnail', fatal=False)
  322. video_description = self._html_search_regex(r'<meta property="og:description" content="(.*?)"',
  323. webpage, u'description', fatal=False)
  324. data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
  325. data = self._download_webpage(data_url, video_id, 'Downloading data webpage')
  326. video_url = self._html_search_regex(r'<file type="high".*?>(.*?)</file>',
  327. data, u'video URL')
  328. return [{
  329. 'id': video_id,
  330. 'url': video_url,
  331. 'ext': 'mp4',
  332. 'title': video_title,
  333. 'thumbnail': thumbnail,
  334. 'description': video_description,
  335. }]
  336. class XHamsterIE(InfoExtractor):
  337. """Information Extractor for xHamster"""
  338. _VALID_URL = r'(?:http://)?(?:www.)?xhamster\.com/movies/(?P<id>[0-9]+)/.*\.html'
  339. def _real_extract(self,url):
  340. mobj = re.match(self._VALID_URL, url)
  341. video_id = mobj.group('id')
  342. mrss_url = 'http://xhamster.com/movies/%s/.html' % video_id
  343. webpage = self._download_webpage(mrss_url, video_id)
  344. mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
  345. if mobj is None:
  346. raise ExtractorError(u'Unable to extract media URL')
  347. if len(mobj.group('server')) == 0:
  348. video_url = compat_urllib_parse.unquote(mobj.group('file'))
  349. else:
  350. video_url = mobj.group('server')+'/key='+mobj.group('file')
  351. video_extension = video_url.split('.')[-1]
  352. video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
  353. webpage, u'title')
  354. # Can't see the description anywhere in the UI
  355. # video_description = self._html_search_regex(r'<span>Description: </span>(?P<description>[^<]+)',
  356. # webpage, u'description', fatal=False)
  357. # if video_description: video_description = unescapeHTML(video_description)
  358. 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)
  359. if mobj:
  360. video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
  361. else:
  362. video_upload_date = None
  363. self._downloader.report_warning(u'Unable to extract upload date')
  364. video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
  365. webpage, u'uploader id', default=u'anonymous')
  366. video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
  367. webpage, u'thumbnail', fatal=False)
  368. return [{
  369. 'id': video_id,
  370. 'url': video_url,
  371. 'ext': video_extension,
  372. 'title': video_title,
  373. # 'description': video_description,
  374. 'upload_date': video_upload_date,
  375. 'uploader_id': video_uploader_id,
  376. 'thumbnail': video_thumbnail
  377. }]
  378. class HypemIE(InfoExtractor):
  379. """Information Extractor for hypem"""
  380. _VALID_URL = r'(?:http://)?(?:www\.)?hypem\.com/track/([^/]+)/([^/]+)'
  381. def _real_extract(self, url):
  382. mobj = re.match(self._VALID_URL, url)
  383. if mobj is None:
  384. raise ExtractorError(u'Invalid URL: %s' % url)
  385. track_id = mobj.group(1)
  386. data = { 'ax': 1, 'ts': time.time() }
  387. data_encoded = compat_urllib_parse.urlencode(data)
  388. complete_url = url + "?" + data_encoded
  389. request = compat_urllib_request.Request(complete_url)
  390. response, urlh = self._download_webpage_handle(request, track_id, u'Downloading webpage with the url')
  391. cookie = urlh.headers.get('Set-Cookie', '')
  392. self.report_extraction(track_id)
  393. html_tracks = self._html_search_regex(r'<script type="application/json" id="displayList-data">(.*?)</script>',
  394. response, u'tracks', flags=re.MULTILINE|re.DOTALL).strip()
  395. try:
  396. track_list = json.loads(html_tracks)
  397. track = track_list[u'tracks'][0]
  398. except ValueError:
  399. raise ExtractorError(u'Hypemachine contained invalid JSON.')
  400. key = track[u"key"]
  401. track_id = track[u"id"]
  402. artist = track[u"artist"]
  403. title = track[u"song"]
  404. serve_url = "http://hypem.com/serve/source/%s/%s" % (compat_str(track_id), compat_str(key))
  405. request = compat_urllib_request.Request(serve_url, "" , {'Content-Type': 'application/json'})
  406. request.add_header('cookie', cookie)
  407. song_data_json = self._download_webpage(request, track_id, u'Downloading metadata')
  408. try:
  409. song_data = json.loads(song_data_json)
  410. except ValueError:
  411. raise ExtractorError(u'Hypemachine contained invalid JSON.')
  412. final_url = song_data[u"url"]
  413. return [{
  414. 'id': track_id,
  415. 'url': final_url,
  416. 'ext': "mp3",
  417. 'title': title,
  418. 'artist': artist,
  419. }]
  420. class Vbox7IE(InfoExtractor):
  421. """Information Extractor for Vbox7"""
  422. _VALID_URL = r'(?:http://)?(?:www\.)?vbox7\.com/play:([^/]+)'
  423. def _real_extract(self,url):
  424. mobj = re.match(self._VALID_URL, url)
  425. if mobj is None:
  426. raise ExtractorError(u'Invalid URL: %s' % url)
  427. video_id = mobj.group(1)
  428. redirect_page, urlh = self._download_webpage_handle(url, video_id)
  429. new_location = self._search_regex(r'window\.location = \'(.*)\';', redirect_page, u'redirect location')
  430. redirect_url = urlh.geturl() + new_location
  431. webpage = self._download_webpage(redirect_url, video_id, u'Downloading redirect page')
  432. title = self._html_search_regex(r'<title>(.*)</title>',
  433. webpage, u'title').split('/')[0].strip()
  434. ext = "flv"
  435. info_url = "http://vbox7.com/play/magare.do"
  436. data = compat_urllib_parse.urlencode({'as3':'1','vid':video_id})
  437. info_request = compat_urllib_request.Request(info_url, data)
  438. info_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  439. info_response = self._download_webpage(info_request, video_id, u'Downloading info webpage')
  440. if info_response is None:
  441. raise ExtractorError(u'Unable to extract the media url')
  442. (final_url, thumbnail_url) = map(lambda x: x.split('=')[1], info_response.split('&'))
  443. return [{
  444. 'id': video_id,
  445. 'url': final_url,
  446. 'ext': ext,
  447. 'title': title,
  448. 'thumbnail': thumbnail_url,
  449. }]
  450. def gen_extractors():
  451. """ Return a list of an instance of every supported extractor.
  452. The order does matter; the first extractor matched is the one handling the URL.
  453. """
  454. return [
  455. YoutubePlaylistIE(),
  456. YoutubeChannelIE(),
  457. YoutubeUserIE(),
  458. YoutubeSearchIE(),
  459. YoutubeIE(),
  460. MetacafeIE(),
  461. DailymotionIE(),
  462. GoogleSearchIE(),
  463. PhotobucketIE(),
  464. YahooIE(),
  465. YahooSearchIE(),
  466. DepositFilesIE(),
  467. FacebookIE(),
  468. BlipTVIE(),
  469. BlipTVUserIE(),
  470. VimeoIE(),
  471. MyVideoIE(),
  472. ComedyCentralIE(),
  473. EscapistIE(),
  474. CollegeHumorIE(),
  475. XVideosIE(),
  476. SoundcloudSetIE(),
  477. SoundcloudIE(),
  478. InfoQIE(),
  479. MixcloudIE(),
  480. StanfordOpenClassroomIE(),
  481. MTVIE(),
  482. YoukuIE(),
  483. XNXXIE(),
  484. YouJizzIE(),
  485. PornotubeIE(),
  486. YouPornIE(),
  487. GooglePlusIE(),
  488. ArteTvIE(),
  489. NBAIE(),
  490. WorldStarHipHopIE(),
  491. JustinTVIE(),
  492. FunnyOrDieIE(),
  493. SteamIE(),
  494. UstreamIE(),
  495. RBMARadioIE(),
  496. EightTracksIE(),
  497. KeekIE(),
  498. TEDIE(),
  499. MySpassIE(),
  500. SpiegelIE(),
  501. LiveLeakIE(),
  502. ARDIE(),
  503. ZDFIE(),
  504. TumblrIE(),
  505. BandcampIE(),
  506. RedTubeIE(),
  507. InaIE(),
  508. HowcastIE(),
  509. VineIE(),
  510. FlickrIE(),
  511. TeamcocoIE(),
  512. XHamsterIE(),
  513. HypemIE(),
  514. Vbox7IE(),
  515. GametrailersIE(),
  516. StatigramIE(),
  517. GenericIE()
  518. ]
  519. def get_info_extractor(ie_name):
  520. """Returns the info extractor class with the given ie_name"""
  521. return globals()[ie_name+'IE']