InfoExtractors.py 36 KB

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