InfoExtractors.py 30 KB

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