InfoExtractors.py 26 KB

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