InfoExtractors.py 28 KB

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