InfoExtractors.py 31 KB

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