InfoExtractors.py 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500
  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.gametrailers import GametrailersIE
  29. from .extractor.generic import GenericIE
  30. from .extractor.googleplus import GooglePlusIE
  31. from .extractor.googlesearch import GoogleSearchIE
  32. from .extractor.infoq import InfoQIE
  33. from .extractor.metacafe import MetacafeIE
  34. from .extractor.mtv import MTVIE
  35. from .extractor.myvideo import MyVideoIE
  36. from .extractor.nba import NBAIE
  37. from .extractor.statigram import StatigramIE
  38. from .extractor.photobucket import PhotobucketIE
  39. from .extractor.soundcloud import SoundcloudIE, SoundcloudSetIE
  40. from .extractor.stanfordoc import StanfordOpenClassroomIE
  41. from .extractor.ted import TEDIE
  42. from .extractor.vimeo import VimeoIE
  43. from .extractor.xvideos import XVideosIE
  44. from .extractor.yahoo import YahooIE, YahooSearchIE
  45. from .extractor.youtube import YoutubeIE, YoutubePlaylistIE, YoutubeSearchIE, YoutubeUserIE, YoutubeChannelIE
  46. from .extractor.zdf import ZDFIE
  47. class MixcloudIE(InfoExtractor):
  48. """Information extractor for www.mixcloud.com"""
  49. _WORKING = False # New API, but it seems good http://www.mixcloud.com/developers/documentation/
  50. _VALID_URL = r'^(?:https?://)?(?:www\.)?mixcloud\.com/([\w\d-]+)/([\w\d-]+)'
  51. IE_NAME = u'mixcloud'
  52. def report_download_json(self, file_id):
  53. """Report JSON download."""
  54. self.to_screen(u'Downloading json')
  55. def get_urls(self, jsonData, fmt, bitrate='best'):
  56. """Get urls from 'audio_formats' section in json"""
  57. file_url = None
  58. try:
  59. bitrate_list = jsonData[fmt]
  60. if bitrate is None or bitrate == 'best' or bitrate not in bitrate_list:
  61. bitrate = max(bitrate_list) # select highest
  62. url_list = jsonData[fmt][bitrate]
  63. except TypeError: # we have no bitrate info.
  64. url_list = jsonData[fmt]
  65. return url_list
  66. def check_urls(self, url_list):
  67. """Returns 1st active url from list"""
  68. for url in url_list:
  69. try:
  70. compat_urllib_request.urlopen(url)
  71. return url
  72. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  73. url = None
  74. return None
  75. def _print_formats(self, formats):
  76. print('Available formats:')
  77. for fmt in formats.keys():
  78. for b in formats[fmt]:
  79. try:
  80. ext = formats[fmt][b][0]
  81. print('%s\t%s\t[%s]' % (fmt, b, ext.split('.')[-1]))
  82. except TypeError: # we have no bitrate info
  83. ext = formats[fmt][0]
  84. print('%s\t%s\t[%s]' % (fmt, '??', ext.split('.')[-1]))
  85. break
  86. def _real_extract(self, url):
  87. mobj = re.match(self._VALID_URL, url)
  88. if mobj is None:
  89. raise ExtractorError(u'Invalid URL: %s' % url)
  90. # extract uploader & filename from url
  91. uploader = mobj.group(1).decode('utf-8')
  92. file_id = uploader + "-" + mobj.group(2).decode('utf-8')
  93. # construct API request
  94. file_url = 'http://www.mixcloud.com/api/1/cloudcast/' + '/'.join(url.split('/')[-3:-1]) + '.json'
  95. # retrieve .json file with links to files
  96. request = compat_urllib_request.Request(file_url)
  97. try:
  98. self.report_download_json(file_url)
  99. jsonData = compat_urllib_request.urlopen(request).read()
  100. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  101. raise ExtractorError(u'Unable to retrieve file: %s' % compat_str(err))
  102. # parse JSON
  103. json_data = json.loads(jsonData)
  104. player_url = json_data['player_swf_url']
  105. formats = dict(json_data['audio_formats'])
  106. req_format = self._downloader.params.get('format', None)
  107. bitrate = None
  108. if self._downloader.params.get('listformats', None):
  109. self._print_formats(formats)
  110. return
  111. if req_format is None or req_format == 'best':
  112. for format_param in formats.keys():
  113. url_list = self.get_urls(formats, format_param)
  114. # check urls
  115. file_url = self.check_urls(url_list)
  116. if file_url is not None:
  117. break # got it!
  118. else:
  119. if req_format not in formats:
  120. raise ExtractorError(u'Format is not available')
  121. url_list = self.get_urls(formats, req_format)
  122. file_url = self.check_urls(url_list)
  123. format_param = req_format
  124. return [{
  125. 'id': file_id.decode('utf-8'),
  126. 'url': file_url.decode('utf-8'),
  127. 'uploader': uploader.decode('utf-8'),
  128. 'upload_date': None,
  129. 'title': json_data['name'],
  130. 'ext': file_url.split('.')[-1].decode('utf-8'),
  131. 'format': (format_param is None and u'NA' or format_param.decode('utf-8')),
  132. 'thumbnail': json_data['thumbnail_url'],
  133. 'description': json_data['description'],
  134. 'player_url': player_url.decode('utf-8'),
  135. }]
  136. class YoukuIE(InfoExtractor):
  137. _VALID_URL = r'(?:http://)?v\.youku\.com/v_show/id_(?P<ID>[A-Za-z0-9]+)\.html'
  138. def _gen_sid(self):
  139. nowTime = int(time.time() * 1000)
  140. random1 = random.randint(1000,1998)
  141. random2 = random.randint(1000,9999)
  142. return "%d%d%d" %(nowTime,random1,random2)
  143. def _get_file_ID_mix_string(self, seed):
  144. mixed = []
  145. source = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\:._-1234567890")
  146. seed = float(seed)
  147. for i in range(len(source)):
  148. seed = (seed * 211 + 30031 ) % 65536
  149. index = math.floor(seed / 65536 * len(source) )
  150. mixed.append(source[int(index)])
  151. source.remove(source[int(index)])
  152. #return ''.join(mixed)
  153. return mixed
  154. def _get_file_id(self, fileId, seed):
  155. mixed = self._get_file_ID_mix_string(seed)
  156. ids = fileId.split('*')
  157. realId = []
  158. for ch in ids:
  159. if ch:
  160. realId.append(mixed[int(ch)])
  161. return ''.join(realId)
  162. def _real_extract(self, url):
  163. mobj = re.match(self._VALID_URL, url)
  164. if mobj is None:
  165. raise ExtractorError(u'Invalid URL: %s' % url)
  166. video_id = mobj.group('ID')
  167. info_url = 'http://v.youku.com/player/getPlayList/VideoIDS/' + video_id
  168. jsondata = self._download_webpage(info_url, video_id)
  169. self.report_extraction(video_id)
  170. try:
  171. config = json.loads(jsondata)
  172. video_title = config['data'][0]['title']
  173. seed = config['data'][0]['seed']
  174. format = self._downloader.params.get('format', None)
  175. supported_format = list(config['data'][0]['streamfileids'].keys())
  176. if format is None or format == 'best':
  177. if 'hd2' in supported_format:
  178. format = 'hd2'
  179. else:
  180. format = 'flv'
  181. ext = u'flv'
  182. elif format == 'worst':
  183. format = 'mp4'
  184. ext = u'mp4'
  185. else:
  186. format = 'flv'
  187. ext = u'flv'
  188. fileid = config['data'][0]['streamfileids'][format]
  189. keys = [s['k'] for s in config['data'][0]['segs'][format]]
  190. except (UnicodeDecodeError, ValueError, KeyError):
  191. raise ExtractorError(u'Unable to extract info section')
  192. files_info=[]
  193. sid = self._gen_sid()
  194. fileid = self._get_file_id(fileid, seed)
  195. #column 8,9 of fileid represent the segment number
  196. #fileid[7:9] should be changed
  197. for index, key in enumerate(keys):
  198. temp_fileid = '%s%02X%s' % (fileid[0:8], index, fileid[10:])
  199. download_url = 'http://f.youku.com/player/getFlvPath/sid/%s_%02X/st/flv/fileid/%s?k=%s' % (sid, index, temp_fileid, key)
  200. info = {
  201. 'id': '%s_part%02d' % (video_id, index),
  202. 'url': download_url,
  203. 'uploader': None,
  204. 'upload_date': None,
  205. 'title': video_title,
  206. 'ext': ext,
  207. }
  208. files_info.append(info)
  209. return files_info
  210. class XNXXIE(InfoExtractor):
  211. """Information extractor for xnxx.com"""
  212. _VALID_URL = r'^(?:https?://)?video\.xnxx\.com/video([0-9]+)/(.*)'
  213. IE_NAME = u'xnxx'
  214. VIDEO_URL_RE = r'flv_url=(.*?)&amp;'
  215. VIDEO_TITLE_RE = r'<title>(.*?)\s+-\s+XNXX.COM'
  216. VIDEO_THUMB_RE = r'url_bigthumb=(.*?)&amp;'
  217. def _real_extract(self, url):
  218. mobj = re.match(self._VALID_URL, url)
  219. if mobj is None:
  220. raise ExtractorError(u'Invalid URL: %s' % url)
  221. video_id = mobj.group(1)
  222. # Get webpage content
  223. webpage = self._download_webpage(url, video_id)
  224. video_url = self._search_regex(self.VIDEO_URL_RE,
  225. webpage, u'video URL')
  226. video_url = compat_urllib_parse.unquote(video_url)
  227. video_title = self._html_search_regex(self.VIDEO_TITLE_RE,
  228. webpage, u'title')
  229. video_thumbnail = self._search_regex(self.VIDEO_THUMB_RE,
  230. webpage, u'thumbnail', fatal=False)
  231. return [{
  232. 'id': video_id,
  233. 'url': video_url,
  234. 'uploader': None,
  235. 'upload_date': None,
  236. 'title': video_title,
  237. 'ext': 'flv',
  238. 'thumbnail': video_thumbnail,
  239. 'description': None,
  240. }]
  241. class JustinTVIE(InfoExtractor):
  242. """Information extractor for justin.tv and twitch.tv"""
  243. # TODO: One broadcast may be split into multiple videos. The key
  244. # 'broadcast_id' is the same for all parts, and 'broadcast_part'
  245. # starts at 1 and increases. Can we treat all parts as one video?
  246. _VALID_URL = r"""(?x)^(?:http://)?(?:www\.)?(?:twitch|justin)\.tv/
  247. (?:
  248. (?P<channelid>[^/]+)|
  249. (?:(?:[^/]+)/b/(?P<videoid>[^/]+))|
  250. (?:(?:[^/]+)/c/(?P<chapterid>[^/]+))
  251. )
  252. /?(?:\#.*)?$
  253. """
  254. _JUSTIN_PAGE_LIMIT = 100
  255. IE_NAME = u'justin.tv'
  256. def report_download_page(self, channel, offset):
  257. """Report attempt to download a single page of videos."""
  258. self.to_screen(u'%s: Downloading video information from %d to %d' %
  259. (channel, offset, offset + self._JUSTIN_PAGE_LIMIT))
  260. # Return count of items, list of *valid* items
  261. def _parse_page(self, url, video_id):
  262. webpage = self._download_webpage(url, video_id,
  263. u'Downloading video info JSON',
  264. u'unable to download video info JSON')
  265. response = json.loads(webpage)
  266. if type(response) != list:
  267. error_text = response.get('error', 'unknown error')
  268. raise ExtractorError(u'Justin.tv API: %s' % error_text)
  269. info = []
  270. for clip in response:
  271. video_url = clip['video_file_url']
  272. if video_url:
  273. video_extension = os.path.splitext(video_url)[1][1:]
  274. video_date = re.sub('-', '', clip['start_time'][:10])
  275. video_uploader_id = clip.get('user_id', clip.get('channel_id'))
  276. video_id = clip['id']
  277. video_title = clip.get('title', video_id)
  278. info.append({
  279. 'id': video_id,
  280. 'url': video_url,
  281. 'title': video_title,
  282. 'uploader': clip.get('channel_name', video_uploader_id),
  283. 'uploader_id': video_uploader_id,
  284. 'upload_date': video_date,
  285. 'ext': video_extension,
  286. })
  287. return (len(response), info)
  288. def _real_extract(self, url):
  289. mobj = re.match(self._VALID_URL, url)
  290. if mobj is None:
  291. raise ExtractorError(u'invalid URL: %s' % url)
  292. api_base = 'http://api.justin.tv'
  293. paged = False
  294. if mobj.group('channelid'):
  295. paged = True
  296. video_id = mobj.group('channelid')
  297. api = api_base + '/channel/archives/%s.json' % video_id
  298. elif mobj.group('chapterid'):
  299. chapter_id = mobj.group('chapterid')
  300. webpage = self._download_webpage(url, chapter_id)
  301. m = re.search(r'PP\.archive_id = "([0-9]+)";', webpage)
  302. if not m:
  303. raise ExtractorError(u'Cannot find archive of a chapter')
  304. archive_id = m.group(1)
  305. api = api_base + '/broadcast/by_chapter/%s.xml' % chapter_id
  306. chapter_info_xml = self._download_webpage(api, chapter_id,
  307. note=u'Downloading chapter information',
  308. errnote=u'Chapter information download failed')
  309. doc = xml.etree.ElementTree.fromstring(chapter_info_xml)
  310. for a in doc.findall('.//archive'):
  311. if archive_id == a.find('./id').text:
  312. break
  313. else:
  314. raise ExtractorError(u'Could not find chapter in chapter information')
  315. video_url = a.find('./video_file_url').text
  316. video_ext = video_url.rpartition('.')[2] or u'flv'
  317. chapter_api_url = u'https://api.twitch.tv/kraken/videos/c' + chapter_id
  318. chapter_info_json = self._download_webpage(chapter_api_url, u'c' + chapter_id,
  319. note='Downloading chapter metadata',
  320. errnote='Download of chapter metadata failed')
  321. chapter_info = json.loads(chapter_info_json)
  322. bracket_start = int(doc.find('.//bracket_start').text)
  323. bracket_end = int(doc.find('.//bracket_end').text)
  324. # TODO determine start (and probably fix up file)
  325. # youtube-dl -v http://www.twitch.tv/firmbelief/c/1757457
  326. #video_url += u'?start=' + TODO:start_timestamp
  327. # bracket_start is 13290, but we want 51670615
  328. self._downloader.report_warning(u'Chapter detected, but we can just download the whole file. '
  329. u'Chapter starts at %s and ends at %s' % (formatSeconds(bracket_start), formatSeconds(bracket_end)))
  330. info = {
  331. 'id': u'c' + chapter_id,
  332. 'url': video_url,
  333. 'ext': video_ext,
  334. 'title': chapter_info['title'],
  335. 'thumbnail': chapter_info['preview'],
  336. 'description': chapter_info['description'],
  337. 'uploader': chapter_info['channel']['display_name'],
  338. 'uploader_id': chapter_info['channel']['name'],
  339. }
  340. return [info]
  341. else:
  342. video_id = mobj.group('videoid')
  343. api = api_base + '/broadcast/by_archive/%s.json' % video_id
  344. self.report_extraction(video_id)
  345. info = []
  346. offset = 0
  347. limit = self._JUSTIN_PAGE_LIMIT
  348. while True:
  349. if paged:
  350. self.report_download_page(video_id, offset)
  351. page_url = api + ('?offset=%d&limit=%d' % (offset, limit))
  352. page_count, page_info = self._parse_page(page_url, video_id)
  353. info.extend(page_info)
  354. if not paged or page_count != limit:
  355. break
  356. offset += limit
  357. return info
  358. class FunnyOrDieIE(InfoExtractor):
  359. _VALID_URL = r'^(?:https?://)?(?:www\.)?funnyordie\.com/videos/(?P<id>[0-9a-f]+)/.*$'
  360. def _real_extract(self, url):
  361. mobj = re.match(self._VALID_URL, url)
  362. if mobj is None:
  363. raise ExtractorError(u'invalid URL: %s' % url)
  364. video_id = mobj.group('id')
  365. webpage = self._download_webpage(url, video_id)
  366. video_url = self._html_search_regex(r'<video[^>]*>\s*<source[^>]*>\s*<source src="(?P<url>[^"]+)"',
  367. webpage, u'video URL', flags=re.DOTALL)
  368. title = self._html_search_regex((r"<h1 class='player_page_h1'.*?>(?P<title>.*?)</h1>",
  369. r'<title>(?P<title>[^<]+?)</title>'), webpage, 'title', flags=re.DOTALL)
  370. video_description = self._html_search_regex(r'<meta property="og:description" content="(?P<desc>.*?)"',
  371. webpage, u'description', fatal=False, flags=re.DOTALL)
  372. info = {
  373. 'id': video_id,
  374. 'url': video_url,
  375. 'ext': 'mp4',
  376. 'title': title,
  377. 'description': video_description,
  378. }
  379. return [info]
  380. class SteamIE(InfoExtractor):
  381. _VALID_URL = r"""http://store\.steampowered\.com/
  382. (agecheck/)?
  383. (?P<urltype>video|app)/ #If the page is only for videos or for a game
  384. (?P<gameID>\d+)/?
  385. (?P<videoID>\d*)(?P<extra>\??) #For urltype == video we sometimes get the videoID
  386. """
  387. _VIDEO_PAGE_TEMPLATE = 'http://store.steampowered.com/video/%s/'
  388. _AGECHECK_TEMPLATE = 'http://store.steampowered.com/agecheck/video/%s/?snr=1_agecheck_agecheck__age-gate&ageDay=1&ageMonth=January&ageYear=1970'
  389. @classmethod
  390. def suitable(cls, url):
  391. """Receives a URL and returns True if suitable for this IE."""
  392. return re.match(cls._VALID_URL, url, re.VERBOSE) is not None
  393. def _real_extract(self, url):
  394. m = re.match(self._VALID_URL, url, re.VERBOSE)
  395. gameID = m.group('gameID')
  396. videourl = self._VIDEO_PAGE_TEMPLATE % gameID
  397. webpage = self._download_webpage(videourl, gameID)
  398. if re.search('<h2>Please enter your birth date to continue:</h2>', webpage) is not None:
  399. videourl = self._AGECHECK_TEMPLATE % gameID
  400. self.report_age_confirmation()
  401. webpage = self._download_webpage(videourl, gameID)
  402. self.report_extraction(gameID)
  403. game_title = self._html_search_regex(r'<h2 class="pageheader">(.*?)</h2>',
  404. webpage, 'game title')
  405. urlRE = r"'movie_(?P<videoID>\d+)': \{\s*FILENAME: \"(?P<videoURL>[\w:/\.\?=]+)\"(,\s*MOVIE_NAME: \"(?P<videoName>[\w:/\.\?=\+-]+)\")?\s*\},"
  406. mweb = re.finditer(urlRE, webpage)
  407. namesRE = r'<span class="title">(?P<videoName>.+?)</span>'
  408. titles = re.finditer(namesRE, webpage)
  409. thumbsRE = r'<img class="movie_thumb" src="(?P<thumbnail>.+?)">'
  410. thumbs = re.finditer(thumbsRE, webpage)
  411. videos = []
  412. for vid,vtitle,thumb in zip(mweb,titles,thumbs):
  413. video_id = vid.group('videoID')
  414. title = vtitle.group('videoName')
  415. video_url = vid.group('videoURL')
  416. video_thumb = thumb.group('thumbnail')
  417. if not video_url:
  418. raise ExtractorError(u'Cannot find video url for %s' % video_id)
  419. info = {
  420. 'id':video_id,
  421. 'url':video_url,
  422. 'ext': 'flv',
  423. 'title': unescapeHTML(title),
  424. 'thumbnail': video_thumb
  425. }
  426. videos.append(info)
  427. return [self.playlist_result(videos, gameID, game_title)]
  428. class UstreamIE(InfoExtractor):
  429. _VALID_URL = r'https?://www\.ustream\.tv/recorded/(?P<videoID>\d+)'
  430. IE_NAME = u'ustream'
  431. def _real_extract(self, url):
  432. m = re.match(self._VALID_URL, url)
  433. video_id = m.group('videoID')
  434. video_url = u'http://tcdn.ustream.tv/video/%s' % video_id
  435. webpage = self._download_webpage(url, video_id)
  436. self.report_extraction(video_id)
  437. video_title = self._html_search_regex(r'data-title="(?P<title>.+)"',
  438. webpage, u'title')
  439. uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>',
  440. webpage, u'uploader', fatal=False, flags=re.DOTALL)
  441. thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"',
  442. webpage, u'thumbnail', fatal=False)
  443. info = {
  444. 'id': video_id,
  445. 'url': video_url,
  446. 'ext': 'flv',
  447. 'title': video_title,
  448. 'uploader': uploader,
  449. 'thumbnail': thumbnail,
  450. }
  451. return info
  452. class WorldStarHipHopIE(InfoExtractor):
  453. _VALID_URL = r'https?://(?:www|m)\.worldstar(?:candy|hiphop)\.com/videos/video\.php\?v=(?P<id>.*)'
  454. IE_NAME = u'WorldStarHipHop'
  455. def _real_extract(self, url):
  456. m = re.match(self._VALID_URL, url)
  457. video_id = m.group('id')
  458. webpage_src = self._download_webpage(url, video_id)
  459. video_url = self._search_regex(r'so\.addVariable\("file","(.*?)"\)',
  460. webpage_src, u'video URL')
  461. if 'mp4' in video_url:
  462. ext = 'mp4'
  463. else:
  464. ext = 'flv'
  465. video_title = self._html_search_regex(r"<title>(.*)</title>",
  466. webpage_src, u'title')
  467. # Getting thumbnail and if not thumbnail sets correct title for WSHH candy video.
  468. thumbnail = self._html_search_regex(r'rel="image_src" href="(.*)" />',
  469. webpage_src, u'thumbnail', fatal=False)
  470. if not thumbnail:
  471. _title = r"""candytitles.*>(.*)</span>"""
  472. mobj = re.search(_title, webpage_src)
  473. if mobj is not None:
  474. video_title = mobj.group(1)
  475. results = [{
  476. 'id': video_id,
  477. 'url' : video_url,
  478. 'title' : video_title,
  479. 'thumbnail' : thumbnail,
  480. 'ext' : ext,
  481. }]
  482. return results
  483. class RBMARadioIE(InfoExtractor):
  484. _VALID_URL = r'https?://(?:www\.)?rbmaradio\.com/shows/(?P<videoID>[^/]+)$'
  485. def _real_extract(self, url):
  486. m = re.match(self._VALID_URL, url)
  487. video_id = m.group('videoID')
  488. webpage = self._download_webpage(url, video_id)
  489. json_data = self._search_regex(r'window\.gon.*?gon\.show=(.+?);$',
  490. webpage, u'json data', flags=re.MULTILINE)
  491. try:
  492. data = json.loads(json_data)
  493. except ValueError as e:
  494. raise ExtractorError(u'Invalid JSON: ' + str(e))
  495. video_url = data['akamai_url'] + '&cbr=256'
  496. url_parts = compat_urllib_parse_urlparse(video_url)
  497. video_ext = url_parts.path.rpartition('.')[2]
  498. info = {
  499. 'id': video_id,
  500. 'url': video_url,
  501. 'ext': video_ext,
  502. 'title': data['title'],
  503. 'description': data.get('teaser_text'),
  504. 'location': data.get('country_of_origin'),
  505. 'uploader': data.get('host', {}).get('name'),
  506. 'uploader_id': data.get('host', {}).get('slug'),
  507. 'thumbnail': data.get('image', {}).get('large_url_2x'),
  508. 'duration': data.get('duration'),
  509. }
  510. return [info]
  511. class YouPornIE(InfoExtractor):
  512. """Information extractor for youporn.com."""
  513. _VALID_URL = r'^(?:https?://)?(?:\w+\.)?youporn\.com/watch/(?P<videoid>[0-9]+)/(?P<title>[^/]+)'
  514. def _print_formats(self, formats):
  515. """Print all available formats"""
  516. print(u'Available formats:')
  517. print(u'ext\t\tformat')
  518. print(u'---------------------------------')
  519. for format in formats:
  520. print(u'%s\t\t%s' % (format['ext'], format['format']))
  521. def _specific(self, req_format, formats):
  522. for x in formats:
  523. if(x["format"]==req_format):
  524. return x
  525. return None
  526. def _real_extract(self, url):
  527. mobj = re.match(self._VALID_URL, url)
  528. if mobj is None:
  529. raise ExtractorError(u'Invalid URL: %s' % url)
  530. video_id = mobj.group('videoid')
  531. req = compat_urllib_request.Request(url)
  532. req.add_header('Cookie', 'age_verified=1')
  533. webpage = self._download_webpage(req, video_id)
  534. # Get JSON parameters
  535. json_params = self._search_regex(r'var currentVideo = new Video\((.*)\);', webpage, u'JSON parameters')
  536. try:
  537. params = json.loads(json_params)
  538. except:
  539. raise ExtractorError(u'Invalid JSON')
  540. self.report_extraction(video_id)
  541. try:
  542. video_title = params['title']
  543. upload_date = unified_strdate(params['release_date_f'])
  544. video_description = params['description']
  545. video_uploader = params['submitted_by']
  546. thumbnail = params['thumbnails'][0]['image']
  547. except KeyError:
  548. raise ExtractorError('Missing JSON parameter: ' + sys.exc_info()[1])
  549. # Get all of the formats available
  550. DOWNLOAD_LIST_RE = r'(?s)<ul class="downloadList">(?P<download_list>.*?)</ul>'
  551. download_list_html = self._search_regex(DOWNLOAD_LIST_RE,
  552. webpage, u'download list').strip()
  553. # Get all of the links from the page
  554. LINK_RE = r'(?s)<a href="(?P<url>[^"]+)">'
  555. links = re.findall(LINK_RE, download_list_html)
  556. if(len(links) == 0):
  557. raise ExtractorError(u'ERROR: no known formats available for video')
  558. self.to_screen(u'Links found: %d' % len(links))
  559. formats = []
  560. for link in links:
  561. # A link looks like this:
  562. # 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
  563. # A path looks like this:
  564. # /201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4
  565. video_url = unescapeHTML( link )
  566. path = compat_urllib_parse_urlparse( video_url ).path
  567. extension = os.path.splitext( path )[1][1:]
  568. format = path.split('/')[4].split('_')[:2]
  569. size = format[0]
  570. bitrate = format[1]
  571. format = "-".join( format )
  572. # title = u'%s-%s-%s' % (video_title, size, bitrate)
  573. formats.append({
  574. 'id': video_id,
  575. 'url': video_url,
  576. 'uploader': video_uploader,
  577. 'upload_date': upload_date,
  578. 'title': video_title,
  579. 'ext': extension,
  580. 'format': format,
  581. 'thumbnail': thumbnail,
  582. 'description': video_description
  583. })
  584. if self._downloader.params.get('listformats', None):
  585. self._print_formats(formats)
  586. return
  587. req_format = self._downloader.params.get('format', None)
  588. self.to_screen(u'Format: %s' % req_format)
  589. if req_format is None or req_format == 'best':
  590. return [formats[0]]
  591. elif req_format == 'worst':
  592. return [formats[-1]]
  593. elif req_format in ('-1', 'all'):
  594. return formats
  595. else:
  596. format = self._specific( req_format, formats )
  597. if result is None:
  598. raise ExtractorError(u'Requested format not available')
  599. return [format]
  600. class PornotubeIE(InfoExtractor):
  601. """Information extractor for pornotube.com."""
  602. _VALID_URL = r'^(?:https?://)?(?:\w+\.)?pornotube\.com(/c/(?P<channel>[0-9]+))?(/m/(?P<videoid>[0-9]+))(/(?P<title>.+))$'
  603. def _real_extract(self, url):
  604. mobj = re.match(self._VALID_URL, url)
  605. if mobj is None:
  606. raise ExtractorError(u'Invalid URL: %s' % url)
  607. video_id = mobj.group('videoid')
  608. video_title = mobj.group('title')
  609. # Get webpage content
  610. webpage = self._download_webpage(url, video_id)
  611. # Get the video URL
  612. VIDEO_URL_RE = r'url: "(?P<url>http://video[0-9].pornotube.com/.+\.flv)",'
  613. video_url = self._search_regex(VIDEO_URL_RE, webpage, u'video url')
  614. video_url = compat_urllib_parse.unquote(video_url)
  615. #Get the uploaded date
  616. VIDEO_UPLOADED_RE = r'<div class="video_added_by">Added (?P<date>[0-9\/]+) by'
  617. upload_date = self._html_search_regex(VIDEO_UPLOADED_RE, webpage, u'upload date', fatal=False)
  618. if upload_date: upload_date = unified_strdate(upload_date)
  619. info = {'id': video_id,
  620. 'url': video_url,
  621. 'uploader': None,
  622. 'upload_date': upload_date,
  623. 'title': video_title,
  624. 'ext': 'flv',
  625. 'format': 'flv'}
  626. return [info]
  627. class YouJizzIE(InfoExtractor):
  628. """Information extractor for youjizz.com."""
  629. _VALID_URL = r'^(?:https?://)?(?:\w+\.)?youjizz\.com/videos/(?P<videoid>[^.]+).html$'
  630. def _real_extract(self, url):
  631. mobj = re.match(self._VALID_URL, url)
  632. if mobj is None:
  633. raise ExtractorError(u'Invalid URL: %s' % url)
  634. video_id = mobj.group('videoid')
  635. # Get webpage content
  636. webpage = self._download_webpage(url, video_id)
  637. # Get the video title
  638. video_title = self._html_search_regex(r'<title>(?P<title>.*)</title>',
  639. webpage, u'title').strip()
  640. # Get the embed page
  641. result = re.search(r'https?://www.youjizz.com/videos/embed/(?P<videoid>[0-9]+)', webpage)
  642. if result is None:
  643. raise ExtractorError(u'ERROR: unable to extract embed page')
  644. embed_page_url = result.group(0).strip()
  645. video_id = result.group('videoid')
  646. webpage = self._download_webpage(embed_page_url, video_id)
  647. # Get the video URL
  648. video_url = self._search_regex(r'so.addVariable\("file",encodeURIComponent\("(?P<source>[^"]+)"\)\);',
  649. webpage, u'video URL')
  650. info = {'id': video_id,
  651. 'url': video_url,
  652. 'title': video_title,
  653. 'ext': 'flv',
  654. 'format': 'flv',
  655. 'player_url': embed_page_url}
  656. return [info]
  657. class EightTracksIE(InfoExtractor):
  658. IE_NAME = '8tracks'
  659. _VALID_URL = r'https?://8tracks.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
  660. def _real_extract(self, url):
  661. mobj = re.match(self._VALID_URL, url)
  662. if mobj is None:
  663. raise ExtractorError(u'Invalid URL: %s' % url)
  664. playlist_id = mobj.group('id')
  665. webpage = self._download_webpage(url, playlist_id)
  666. json_like = self._search_regex(r"PAGE.mix = (.*?);\n", webpage, u'trax information', flags=re.DOTALL)
  667. data = json.loads(json_like)
  668. session = str(random.randint(0, 1000000000))
  669. mix_id = data['id']
  670. track_count = data['tracks_count']
  671. first_url = 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session, mix_id)
  672. next_url = first_url
  673. res = []
  674. for i in itertools.count():
  675. api_json = self._download_webpage(next_url, playlist_id,
  676. note=u'Downloading song information %s/%s' % (str(i+1), track_count),
  677. errnote=u'Failed to download song information')
  678. api_data = json.loads(api_json)
  679. track_data = api_data[u'set']['track']
  680. info = {
  681. 'id': track_data['id'],
  682. 'url': track_data['track_file_stream_url'],
  683. 'title': track_data['performer'] + u' - ' + track_data['name'],
  684. 'raw_title': track_data['name'],
  685. 'uploader_id': data['user']['login'],
  686. 'ext': 'm4a',
  687. }
  688. res.append(info)
  689. if api_data['set']['at_last_track']:
  690. break
  691. next_url = 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % (session, mix_id, track_data['id'])
  692. return res
  693. class KeekIE(InfoExtractor):
  694. _VALID_URL = r'http://(?:www\.)?keek\.com/(?:!|\w+/keeks/)(?P<videoID>\w+)'
  695. IE_NAME = u'keek'
  696. def _real_extract(self, url):
  697. m = re.match(self._VALID_URL, url)
  698. video_id = m.group('videoID')
  699. video_url = u'http://cdn.keek.com/keek/video/%s' % video_id
  700. thumbnail = u'http://cdn.keek.com/keek/thumbnail/%s/w100/h75' % video_id
  701. webpage = self._download_webpage(url, video_id)
  702. video_title = self._html_search_regex(r'<meta property="og:title" content="(?P<title>.*?)"',
  703. webpage, u'title')
  704. uploader = self._html_search_regex(r'<div class="user-name-and-bio">[\S\s]+?<h2>(?P<uploader>.+?)</h2>',
  705. webpage, u'uploader', fatal=False)
  706. info = {
  707. 'id': video_id,
  708. 'url': video_url,
  709. 'ext': 'mp4',
  710. 'title': video_title,
  711. 'thumbnail': thumbnail,
  712. 'uploader': uploader
  713. }
  714. return [info]
  715. class MySpassIE(InfoExtractor):
  716. _VALID_URL = r'http://www.myspass.de/.*'
  717. def _real_extract(self, url):
  718. META_DATA_URL_TEMPLATE = 'http://www.myspass.de/myspass/includes/apps/video/getvideometadataxml.php?id=%s'
  719. # video id is the last path element of the URL
  720. # usually there is a trailing slash, so also try the second but last
  721. url_path = compat_urllib_parse_urlparse(url).path
  722. url_parent_path, video_id = os.path.split(url_path)
  723. if not video_id:
  724. _, video_id = os.path.split(url_parent_path)
  725. # get metadata
  726. metadata_url = META_DATA_URL_TEMPLATE % video_id
  727. metadata_text = self._download_webpage(metadata_url, video_id)
  728. metadata = xml.etree.ElementTree.fromstring(metadata_text.encode('utf-8'))
  729. # extract values from metadata
  730. url_flv_el = metadata.find('url_flv')
  731. if url_flv_el is None:
  732. raise ExtractorError(u'Unable to extract download url')
  733. video_url = url_flv_el.text
  734. extension = os.path.splitext(video_url)[1][1:]
  735. title_el = metadata.find('title')
  736. if title_el is None:
  737. raise ExtractorError(u'Unable to extract title')
  738. title = title_el.text
  739. format_id_el = metadata.find('format_id')
  740. if format_id_el is None:
  741. format = ext
  742. else:
  743. format = format_id_el.text
  744. description_el = metadata.find('description')
  745. if description_el is not None:
  746. description = description_el.text
  747. else:
  748. description = None
  749. imagePreview_el = metadata.find('imagePreview')
  750. if imagePreview_el is not None:
  751. thumbnail = imagePreview_el.text
  752. else:
  753. thumbnail = None
  754. info = {
  755. 'id': video_id,
  756. 'url': video_url,
  757. 'title': title,
  758. 'ext': extension,
  759. 'format': format,
  760. 'thumbnail': thumbnail,
  761. 'description': description
  762. }
  763. return [info]
  764. class SpiegelIE(InfoExtractor):
  765. _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<videoID>[0-9]+)(?:\.html)?(?:#.*)?$'
  766. def _real_extract(self, url):
  767. m = re.match(self._VALID_URL, url)
  768. video_id = m.group('videoID')
  769. webpage = self._download_webpage(url, video_id)
  770. video_title = self._html_search_regex(r'<div class="module-title">(.*?)</div>',
  771. webpage, u'title')
  772. xml_url = u'http://video2.spiegel.de/flash/' + video_id + u'.xml'
  773. xml_code = self._download_webpage(xml_url, video_id,
  774. note=u'Downloading XML', errnote=u'Failed to download XML')
  775. idoc = xml.etree.ElementTree.fromstring(xml_code)
  776. last_type = idoc[-1]
  777. filename = last_type.findall('./filename')[0].text
  778. duration = float(last_type.findall('./duration')[0].text)
  779. video_url = 'http://video2.spiegel.de/flash/' + filename
  780. video_ext = filename.rpartition('.')[2]
  781. info = {
  782. 'id': video_id,
  783. 'url': video_url,
  784. 'ext': video_ext,
  785. 'title': video_title,
  786. 'duration': duration,
  787. }
  788. return [info]
  789. class LiveLeakIE(InfoExtractor):
  790. _VALID_URL = r'^(?:http?://)?(?:\w+\.)?liveleak\.com/view\?(?:.*?)i=(?P<video_id>[\w_]+)(?:.*)'
  791. IE_NAME = u'liveleak'
  792. def _real_extract(self, url):
  793. mobj = re.match(self._VALID_URL, url)
  794. if mobj is None:
  795. raise ExtractorError(u'Invalid URL: %s' % url)
  796. video_id = mobj.group('video_id')
  797. webpage = self._download_webpage(url, video_id)
  798. video_url = self._search_regex(r'file: "(.*?)",',
  799. webpage, u'video URL')
  800. video_title = self._html_search_regex(r'<meta property="og:title" content="(?P<title>.*?)"',
  801. webpage, u'title').replace('LiveLeak.com -', '').strip()
  802. video_description = self._html_search_regex(r'<meta property="og:description" content="(?P<desc>.*?)"',
  803. webpage, u'description', fatal=False)
  804. video_uploader = self._html_search_regex(r'By:.*?(\w+)</a>',
  805. webpage, u'uploader', fatal=False)
  806. info = {
  807. 'id': video_id,
  808. 'url': video_url,
  809. 'ext': 'mp4',
  810. 'title': video_title,
  811. 'description': video_description,
  812. 'uploader': video_uploader
  813. }
  814. return [info]
  815. class TumblrIE(InfoExtractor):
  816. _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/((post)|(video))/(?P<id>\d*)/(.*?)'
  817. def _real_extract(self, url):
  818. m_url = re.match(self._VALID_URL, url)
  819. video_id = m_url.group('id')
  820. blog = m_url.group('blog_name')
  821. url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
  822. webpage = self._download_webpage(url, video_id)
  823. re_video = r'src=\\x22(?P<video_url>http://%s\.tumblr\.com/video_file/%s/(.*?))\\x22 type=\\x22video/(?P<ext>.*?)\\x22' % (blog, video_id)
  824. video = re.search(re_video, webpage)
  825. if video is None:
  826. raise ExtractorError(u'Unable to extract video')
  827. video_url = video.group('video_url')
  828. ext = video.group('ext')
  829. video_thumbnail = self._search_regex(r'posters(.*?)\[\\x22(?P<thumb>.*?)\\x22',
  830. webpage, u'thumbnail', fatal=False) # We pick the first poster
  831. if video_thumbnail: video_thumbnail = video_thumbnail.replace('\\', '')
  832. # The only place where you can get a title, it's not complete,
  833. # but searching in other places doesn't work for all videos
  834. video_title = self._html_search_regex(r'<title>(?P<title>.*?)</title>',
  835. webpage, u'title', flags=re.DOTALL)
  836. return [{'id': video_id,
  837. 'url': video_url,
  838. 'title': video_title,
  839. 'thumbnail': video_thumbnail,
  840. 'ext': ext
  841. }]
  842. class BandcampIE(InfoExtractor):
  843. _VALID_URL = r'http://.*?\.bandcamp\.com/track/(?P<title>.*)'
  844. def _real_extract(self, url):
  845. mobj = re.match(self._VALID_URL, url)
  846. title = mobj.group('title')
  847. webpage = self._download_webpage(url, title)
  848. # We get the link to the free download page
  849. m_download = re.search(r'freeDownloadPage: "(.*?)"', webpage)
  850. if m_download is None:
  851. raise ExtractorError(u'No free songs found')
  852. download_link = m_download.group(1)
  853. id = re.search(r'var TralbumData = {(.*?)id: (?P<id>\d*?)$',
  854. webpage, re.MULTILINE|re.DOTALL).group('id')
  855. download_webpage = self._download_webpage(download_link, id,
  856. 'Downloading free downloads page')
  857. # We get the dictionary of the track from some javascrip code
  858. info = re.search(r'items: (.*?),$',
  859. download_webpage, re.MULTILINE).group(1)
  860. info = json.loads(info)[0]
  861. # We pick mp3-320 for now, until format selection can be easily implemented.
  862. mp3_info = info[u'downloads'][u'mp3-320']
  863. # If we try to use this url it says the link has expired
  864. initial_url = mp3_info[u'url']
  865. re_url = r'(?P<server>http://(.*?)\.bandcamp\.com)/download/track\?enc=mp3-320&fsig=(?P<fsig>.*?)&id=(?P<id>.*?)&ts=(?P<ts>.*)$'
  866. m_url = re.match(re_url, initial_url)
  867. #We build the url we will use to get the final track url
  868. # This url is build in Bandcamp in the script download_bunde_*.js
  869. 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'))
  870. final_url_webpage = self._download_webpage(request_url, id, 'Requesting download url')
  871. # If we could correctly generate the .rand field the url would be
  872. #in the "download_url" key
  873. final_url = re.search(r'"retry_url":"(.*?)"', final_url_webpage).group(1)
  874. track_info = {'id':id,
  875. 'title' : info[u'title'],
  876. 'ext' : 'mp3',
  877. 'url' : final_url,
  878. 'thumbnail' : info[u'thumb_url'],
  879. 'uploader' : info[u'artist']
  880. }
  881. return [track_info]
  882. class RedTubeIE(InfoExtractor):
  883. """Information Extractor for redtube"""
  884. _VALID_URL = r'(?:http://)?(?:www\.)?redtube\.com/(?P<id>[0-9]+)'
  885. def _real_extract(self,url):
  886. mobj = re.match(self._VALID_URL, url)
  887. if mobj is None:
  888. raise ExtractorError(u'Invalid URL: %s' % url)
  889. video_id = mobj.group('id')
  890. video_extension = 'mp4'
  891. webpage = self._download_webpage(url, video_id)
  892. self.report_extraction(video_id)
  893. video_url = self._html_search_regex(r'<source src="(.+?)" type="video/mp4">',
  894. webpage, u'video URL')
  895. video_title = self._html_search_regex('<h1 class="videoTitle slidePanelMovable">(.+?)</h1>',
  896. webpage, u'title')
  897. return [{
  898. 'id': video_id,
  899. 'url': video_url,
  900. 'ext': video_extension,
  901. 'title': video_title,
  902. }]
  903. class InaIE(InfoExtractor):
  904. """Information Extractor for Ina.fr"""
  905. _VALID_URL = r'(?:http://)?(?:www\.)?ina\.fr/video/(?P<id>I[0-9]+)/.*'
  906. def _real_extract(self,url):
  907. mobj = re.match(self._VALID_URL, url)
  908. video_id = mobj.group('id')
  909. mrss_url='http://player.ina.fr/notices/%s.mrss' % video_id
  910. video_extension = 'mp4'
  911. webpage = self._download_webpage(mrss_url, video_id)
  912. self.report_extraction(video_id)
  913. video_url = self._html_search_regex(r'<media:player url="(?P<mp4url>http://mp4.ina.fr/[^"]+\.mp4)',
  914. webpage, u'video URL')
  915. video_title = self._search_regex(r'<title><!\[CDATA\[(?P<titre>.*?)]]></title>',
  916. webpage, u'title')
  917. return [{
  918. 'id': video_id,
  919. 'url': video_url,
  920. 'ext': video_extension,
  921. 'title': video_title,
  922. }]
  923. class HowcastIE(InfoExtractor):
  924. """Information Extractor for Howcast.com"""
  925. _VALID_URL = r'(?:https?://)?(?:www\.)?howcast\.com/videos/(?P<id>\d+)'
  926. def _real_extract(self, url):
  927. mobj = re.match(self._VALID_URL, url)
  928. video_id = mobj.group('id')
  929. webpage_url = 'http://www.howcast.com/videos/' + video_id
  930. webpage = self._download_webpage(webpage_url, video_id)
  931. self.report_extraction(video_id)
  932. video_url = self._search_regex(r'\'?file\'?: "(http://mobile-media\.howcast\.com/[0-9]+\.mp4)',
  933. webpage, u'video URL')
  934. video_title = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') property=\'og:title\'',
  935. webpage, u'title')
  936. video_description = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') name=\'description\'',
  937. webpage, u'description', fatal=False)
  938. thumbnail = self._html_search_regex(r'<meta content=\'(.+?)\' property=\'og:image\'',
  939. webpage, u'thumbnail', fatal=False)
  940. return [{
  941. 'id': video_id,
  942. 'url': video_url,
  943. 'ext': 'mp4',
  944. 'title': video_title,
  945. 'description': video_description,
  946. 'thumbnail': thumbnail,
  947. }]
  948. class VineIE(InfoExtractor):
  949. """Information Extractor for Vine.co"""
  950. _VALID_URL = r'(?:https?://)?(?:www\.)?vine\.co/v/(?P<id>\w+)'
  951. def _real_extract(self, url):
  952. mobj = re.match(self._VALID_URL, url)
  953. video_id = mobj.group('id')
  954. webpage_url = 'https://vine.co/v/' + video_id
  955. webpage = self._download_webpage(webpage_url, video_id)
  956. self.report_extraction(video_id)
  957. video_url = self._html_search_regex(r'<meta property="twitter:player:stream" content="(.+?)"',
  958. webpage, u'video URL')
  959. video_title = self._html_search_regex(r'<meta property="og:title" content="(.+?)"',
  960. webpage, u'title')
  961. thumbnail = self._html_search_regex(r'<meta property="og:image" content="(.+?)(\?.*?)?"',
  962. webpage, u'thumbnail', fatal=False)
  963. uploader = self._html_search_regex(r'<div class="user">.*?<h2>(.+?)</h2>',
  964. webpage, u'uploader', fatal=False, flags=re.DOTALL)
  965. return [{
  966. 'id': video_id,
  967. 'url': video_url,
  968. 'ext': 'mp4',
  969. 'title': video_title,
  970. 'thumbnail': thumbnail,
  971. 'uploader': uploader,
  972. }]
  973. class FlickrIE(InfoExtractor):
  974. """Information Extractor for Flickr videos"""
  975. _VALID_URL = r'(?:https?://)?(?:www\.)?flickr\.com/photos/(?P<uploader_id>[\w\-_@]+)/(?P<id>\d+).*'
  976. def _real_extract(self, url):
  977. mobj = re.match(self._VALID_URL, url)
  978. video_id = mobj.group('id')
  979. video_uploader_id = mobj.group('uploader_id')
  980. webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id
  981. webpage = self._download_webpage(webpage_url, video_id)
  982. secret = self._search_regex(r"photo_secret: '(\w+)'", webpage, u'secret')
  983. first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self'
  984. first_xml = self._download_webpage(first_url, video_id, 'Downloading first data webpage')
  985. node_id = self._html_search_regex(r'<Item id="id">(\d+-\d+)</Item>',
  986. first_xml, u'node_id')
  987. 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'
  988. second_xml = self._download_webpage(second_url, video_id, 'Downloading second data webpage')
  989. self.report_extraction(video_id)
  990. mobj = re.search(r'<STREAM APP="(.+?)" FULLPATH="(.+?)"', second_xml)
  991. if mobj is None:
  992. raise ExtractorError(u'Unable to extract video url')
  993. video_url = mobj.group(1) + unescapeHTML(mobj.group(2))
  994. video_title = self._html_search_regex(r'<meta property="og:title" content=(?:"([^"]+)"|\'([^\']+)\')',
  995. webpage, u'video title')
  996. video_description = self._html_search_regex(r'<meta property="og:description" content=(?:"([^"]+)"|\'([^\']+)\')',
  997. webpage, u'description', fatal=False)
  998. thumbnail = self._html_search_regex(r'<meta property="og:image" content=(?:"([^"]+)"|\'([^\']+)\')',
  999. webpage, u'thumbnail', fatal=False)
  1000. return [{
  1001. 'id': video_id,
  1002. 'url': video_url,
  1003. 'ext': 'mp4',
  1004. 'title': video_title,
  1005. 'description': video_description,
  1006. 'thumbnail': thumbnail,
  1007. 'uploader_id': video_uploader_id,
  1008. }]
  1009. class TeamcocoIE(InfoExtractor):
  1010. _VALID_URL = r'http://teamcoco\.com/video/(?P<url_title>.*)'
  1011. def _real_extract(self, url):
  1012. mobj = re.match(self._VALID_URL, url)
  1013. if mobj is None:
  1014. raise ExtractorError(u'Invalid URL: %s' % url)
  1015. url_title = mobj.group('url_title')
  1016. webpage = self._download_webpage(url, url_title)
  1017. video_id = self._html_search_regex(r'<article class="video" data-id="(\d+?)"',
  1018. webpage, u'video id')
  1019. self.report_extraction(video_id)
  1020. video_title = self._html_search_regex(r'<meta property="og:title" content="(.+?)"',
  1021. webpage, u'title')
  1022. thumbnail = self._html_search_regex(r'<meta property="og:image" content="(.+?)"',
  1023. webpage, u'thumbnail', fatal=False)
  1024. video_description = self._html_search_regex(r'<meta property="og:description" content="(.*?)"',
  1025. webpage, u'description', fatal=False)
  1026. data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
  1027. data = self._download_webpage(data_url, video_id, 'Downloading data webpage')
  1028. video_url = self._html_search_regex(r'<file type="high".*?>(.*?)</file>',
  1029. data, u'video URL')
  1030. return [{
  1031. 'id': video_id,
  1032. 'url': video_url,
  1033. 'ext': 'mp4',
  1034. 'title': video_title,
  1035. 'thumbnail': thumbnail,
  1036. 'description': video_description,
  1037. }]
  1038. class XHamsterIE(InfoExtractor):
  1039. """Information Extractor for xHamster"""
  1040. _VALID_URL = r'(?:http://)?(?:www.)?xhamster\.com/movies/(?P<id>[0-9]+)/.*\.html'
  1041. def _real_extract(self,url):
  1042. mobj = re.match(self._VALID_URL, url)
  1043. video_id = mobj.group('id')
  1044. mrss_url = 'http://xhamster.com/movies/%s/.html' % video_id
  1045. webpage = self._download_webpage(mrss_url, video_id)
  1046. mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
  1047. if mobj is None:
  1048. raise ExtractorError(u'Unable to extract media URL')
  1049. if len(mobj.group('server')) == 0:
  1050. video_url = compat_urllib_parse.unquote(mobj.group('file'))
  1051. else:
  1052. video_url = mobj.group('server')+'/key='+mobj.group('file')
  1053. video_extension = video_url.split('.')[-1]
  1054. video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
  1055. webpage, u'title')
  1056. # Can't see the description anywhere in the UI
  1057. # video_description = self._html_search_regex(r'<span>Description: </span>(?P<description>[^<]+)',
  1058. # webpage, u'description', fatal=False)
  1059. # if video_description: video_description = unescapeHTML(video_description)
  1060. 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)
  1061. if mobj:
  1062. video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
  1063. else:
  1064. video_upload_date = None
  1065. self._downloader.report_warning(u'Unable to extract upload date')
  1066. video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
  1067. webpage, u'uploader id', default=u'anonymous')
  1068. video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
  1069. webpage, u'thumbnail', fatal=False)
  1070. return [{
  1071. 'id': video_id,
  1072. 'url': video_url,
  1073. 'ext': video_extension,
  1074. 'title': video_title,
  1075. # 'description': video_description,
  1076. 'upload_date': video_upload_date,
  1077. 'uploader_id': video_uploader_id,
  1078. 'thumbnail': video_thumbnail
  1079. }]
  1080. class HypemIE(InfoExtractor):
  1081. """Information Extractor for hypem"""
  1082. _VALID_URL = r'(?:http://)?(?:www\.)?hypem\.com/track/([^/]+)/([^/]+)'
  1083. def _real_extract(self, url):
  1084. mobj = re.match(self._VALID_URL, url)
  1085. if mobj is None:
  1086. raise ExtractorError(u'Invalid URL: %s' % url)
  1087. track_id = mobj.group(1)
  1088. data = { 'ax': 1, 'ts': time.time() }
  1089. data_encoded = compat_urllib_parse.urlencode(data)
  1090. complete_url = url + "?" + data_encoded
  1091. request = compat_urllib_request.Request(complete_url)
  1092. response, urlh = self._download_webpage_handle(request, track_id, u'Downloading webpage with the url')
  1093. cookie = urlh.headers.get('Set-Cookie', '')
  1094. self.report_extraction(track_id)
  1095. html_tracks = self._html_search_regex(r'<script type="application/json" id="displayList-data">(.*?)</script>',
  1096. response, u'tracks', flags=re.MULTILINE|re.DOTALL).strip()
  1097. try:
  1098. track_list = json.loads(html_tracks)
  1099. track = track_list[u'tracks'][0]
  1100. except ValueError:
  1101. raise ExtractorError(u'Hypemachine contained invalid JSON.')
  1102. key = track[u"key"]
  1103. track_id = track[u"id"]
  1104. artist = track[u"artist"]
  1105. title = track[u"song"]
  1106. serve_url = "http://hypem.com/serve/source/%s/%s" % (compat_str(track_id), compat_str(key))
  1107. request = compat_urllib_request.Request(serve_url, "" , {'Content-Type': 'application/json'})
  1108. request.add_header('cookie', cookie)
  1109. song_data_json = self._download_webpage(request, track_id, u'Downloading metadata')
  1110. try:
  1111. song_data = json.loads(song_data_json)
  1112. except ValueError:
  1113. raise ExtractorError(u'Hypemachine contained invalid JSON.')
  1114. final_url = song_data[u"url"]
  1115. return [{
  1116. 'id': track_id,
  1117. 'url': final_url,
  1118. 'ext': "mp3",
  1119. 'title': title,
  1120. 'artist': artist,
  1121. }]
  1122. class Vbox7IE(InfoExtractor):
  1123. """Information Extractor for Vbox7"""
  1124. _VALID_URL = r'(?:http://)?(?:www\.)?vbox7\.com/play:([^/]+)'
  1125. def _real_extract(self,url):
  1126. mobj = re.match(self._VALID_URL, url)
  1127. if mobj is None:
  1128. raise ExtractorError(u'Invalid URL: %s' % url)
  1129. video_id = mobj.group(1)
  1130. redirect_page, urlh = self._download_webpage_handle(url, video_id)
  1131. new_location = self._search_regex(r'window\.location = \'(.*)\';', redirect_page, u'redirect location')
  1132. redirect_url = urlh.geturl() + new_location
  1133. webpage = self._download_webpage(redirect_url, video_id, u'Downloading redirect page')
  1134. title = self._html_search_regex(r'<title>(.*)</title>',
  1135. webpage, u'title').split('/')[0].strip()
  1136. ext = "flv"
  1137. info_url = "http://vbox7.com/play/magare.do"
  1138. data = compat_urllib_parse.urlencode({'as3':'1','vid':video_id})
  1139. info_request = compat_urllib_request.Request(info_url, data)
  1140. info_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  1141. info_response = self._download_webpage(info_request, video_id, u'Downloading info webpage')
  1142. if info_response is None:
  1143. raise ExtractorError(u'Unable to extract the media url')
  1144. (final_url, thumbnail_url) = map(lambda x: x.split('=')[1], info_response.split('&'))
  1145. return [{
  1146. 'id': video_id,
  1147. 'url': final_url,
  1148. 'ext': ext,
  1149. 'title': title,
  1150. 'thumbnail': thumbnail_url,
  1151. }]
  1152. def gen_extractors():
  1153. """ Return a list of an instance of every supported extractor.
  1154. The order does matter; the first extractor matched is the one handling the URL.
  1155. """
  1156. return [
  1157. YoutubePlaylistIE(),
  1158. YoutubeChannelIE(),
  1159. YoutubeUserIE(),
  1160. YoutubeSearchIE(),
  1161. YoutubeIE(),
  1162. MetacafeIE(),
  1163. DailymotionIE(),
  1164. GoogleSearchIE(),
  1165. PhotobucketIE(),
  1166. YahooIE(),
  1167. YahooSearchIE(),
  1168. DepositFilesIE(),
  1169. FacebookIE(),
  1170. BlipTVIE(),
  1171. BlipTVUserIE(),
  1172. VimeoIE(),
  1173. MyVideoIE(),
  1174. ComedyCentralIE(),
  1175. EscapistIE(),
  1176. CollegeHumorIE(),
  1177. XVideosIE(),
  1178. SoundcloudSetIE(),
  1179. SoundcloudIE(),
  1180. InfoQIE(),
  1181. MixcloudIE(),
  1182. StanfordOpenClassroomIE(),
  1183. MTVIE(),
  1184. YoukuIE(),
  1185. XNXXIE(),
  1186. YouJizzIE(),
  1187. PornotubeIE(),
  1188. YouPornIE(),
  1189. GooglePlusIE(),
  1190. ArteTvIE(),
  1191. NBAIE(),
  1192. WorldStarHipHopIE(),
  1193. JustinTVIE(),
  1194. FunnyOrDieIE(),
  1195. SteamIE(),
  1196. UstreamIE(),
  1197. RBMARadioIE(),
  1198. EightTracksIE(),
  1199. KeekIE(),
  1200. TEDIE(),
  1201. MySpassIE(),
  1202. SpiegelIE(),
  1203. LiveLeakIE(),
  1204. ARDIE(),
  1205. ZDFIE(),
  1206. TumblrIE(),
  1207. BandcampIE(),
  1208. RedTubeIE(),
  1209. InaIE(),
  1210. HowcastIE(),
  1211. VineIE(),
  1212. FlickrIE(),
  1213. TeamcocoIE(),
  1214. XHamsterIE(),
  1215. HypemIE(),
  1216. Vbox7IE(),
  1217. GametrailersIE(),
  1218. StatigramIE(),
  1219. GenericIE()
  1220. ]
  1221. def get_info_extractor(ie_name):
  1222. """Returns the info extractor class with the given ie_name"""
  1223. return globals()[ie_name+'IE']