InfoExtractors.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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.bandcamp import BandcampIE
  22. from .extractor.bliptv import BlipTVIE, BlipTVUserIE
  23. from .extractor.comedycentral import ComedyCentralIE
  24. from .extractor.collegehumor import CollegeHumorIE
  25. from .extractor.dailymotion import DailymotionIE
  26. from .extractor.depositfiles import DepositFilesIE
  27. from .extractor.eighttracks import EightTracksIE
  28. from .extractor.escapist import EscapistIE
  29. from .extractor.facebook import FacebookIE
  30. from .extractor.funnyordie import FunnyOrDieIE
  31. from .extractor.gametrailers import GametrailersIE
  32. from .extractor.generic import GenericIE
  33. from .extractor.googleplus import GooglePlusIE
  34. from .extractor.googlesearch import GoogleSearchIE
  35. from .extractor.hypem import HypemIE
  36. from .extractor.ina import InaIE
  37. from .extractor.infoq import InfoQIE
  38. from .extractor.justintv import JustinTVIE
  39. from .extractor.keek import KeekIE
  40. from .extractor.liveleak import LiveLeakIE
  41. from .extractor.metacafe import MetacafeIE
  42. from .extractor.mixcloud import MixcloudIE
  43. from .extractor.mtv import MTVIE
  44. from .extractor.myspass import MySpassIE
  45. from .extractor.myvideo import MyVideoIE
  46. from .extractor.nba import NBAIE
  47. from .extractor.statigram import StatigramIE
  48. from .extractor.photobucket import PhotobucketIE
  49. from .extractor.pornotube import PornotubeIE
  50. from .extractor.rbmaradio import RBMARadioIE
  51. from .extractor.redtube import RedTubeIE
  52. from .extractor.soundcloud import SoundcloudIE, SoundcloudSetIE
  53. from .extractor.spiegel import SpiegelIE
  54. from .extractor.stanfordoc import StanfordOpenClassroomIE
  55. from .extractor.steam import SteamIE
  56. from .extractor.ted import TEDIE
  57. from .extractor.tumblr import TumblrIE
  58. from .extractor.ustream import UstreamIE
  59. from .extractor.vbox7 import Vbox7IE
  60. from .extractor.vimeo import VimeoIE
  61. from .extractor.vine import VineIE
  62. from .extractor.worldstarhiphop import WorldStarHipHopIE
  63. from .extractor.xnxx import XNXXIE
  64. from .extractor.xvideos import XVideosIE
  65. from .extractor.yahoo import YahooIE, YahooSearchIE
  66. from .extractor.youjizz import YouJizzIE
  67. from .extractor.youku import YoukuIE
  68. from .extractor.youporn import YouPornIE
  69. from .extractor.youtube import YoutubeIE, YoutubePlaylistIE, YoutubeSearchIE, YoutubeUserIE, YoutubeChannelIE
  70. from .extractor.zdf import ZDFIE
  71. class HowcastIE(InfoExtractor):
  72. """Information Extractor for Howcast.com"""
  73. _VALID_URL = r'(?:https?://)?(?:www\.)?howcast\.com/videos/(?P<id>\d+)'
  74. def _real_extract(self, url):
  75. mobj = re.match(self._VALID_URL, url)
  76. video_id = mobj.group('id')
  77. webpage_url = 'http://www.howcast.com/videos/' + video_id
  78. webpage = self._download_webpage(webpage_url, video_id)
  79. self.report_extraction(video_id)
  80. video_url = self._search_regex(r'\'?file\'?: "(http://mobile-media\.howcast\.com/[0-9]+\.mp4)',
  81. webpage, u'video URL')
  82. video_title = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') property=\'og:title\'',
  83. webpage, u'title')
  84. video_description = self._html_search_regex(r'<meta content=(?:"([^"]+)"|\'([^\']+)\') name=\'description\'',
  85. webpage, u'description', fatal=False)
  86. thumbnail = self._html_search_regex(r'<meta content=\'(.+?)\' property=\'og:image\'',
  87. webpage, u'thumbnail', fatal=False)
  88. return [{
  89. 'id': video_id,
  90. 'url': video_url,
  91. 'ext': 'mp4',
  92. 'title': video_title,
  93. 'description': video_description,
  94. 'thumbnail': thumbnail,
  95. }]
  96. class FlickrIE(InfoExtractor):
  97. """Information Extractor for Flickr videos"""
  98. _VALID_URL = r'(?:https?://)?(?:www\.)?flickr\.com/photos/(?P<uploader_id>[\w\-_@]+)/(?P<id>\d+).*'
  99. def _real_extract(self, url):
  100. mobj = re.match(self._VALID_URL, url)
  101. video_id = mobj.group('id')
  102. video_uploader_id = mobj.group('uploader_id')
  103. webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id
  104. webpage = self._download_webpage(webpage_url, video_id)
  105. secret = self._search_regex(r"photo_secret: '(\w+)'", webpage, u'secret')
  106. first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self'
  107. first_xml = self._download_webpage(first_url, video_id, 'Downloading first data webpage')
  108. node_id = self._html_search_regex(r'<Item id="id">(\d+-\d+)</Item>',
  109. first_xml, u'node_id')
  110. 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'
  111. second_xml = self._download_webpage(second_url, video_id, 'Downloading second data webpage')
  112. self.report_extraction(video_id)
  113. mobj = re.search(r'<STREAM APP="(.+?)" FULLPATH="(.+?)"', second_xml)
  114. if mobj is None:
  115. raise ExtractorError(u'Unable to extract video url')
  116. video_url = mobj.group(1) + unescapeHTML(mobj.group(2))
  117. video_title = self._html_search_regex(r'<meta property="og:title" content=(?:"([^"]+)"|\'([^\']+)\')',
  118. webpage, u'video title')
  119. video_description = self._html_search_regex(r'<meta property="og:description" content=(?:"([^"]+)"|\'([^\']+)\')',
  120. webpage, u'description', fatal=False)
  121. thumbnail = self._html_search_regex(r'<meta property="og:image" content=(?:"([^"]+)"|\'([^\']+)\')',
  122. webpage, u'thumbnail', fatal=False)
  123. return [{
  124. 'id': video_id,
  125. 'url': video_url,
  126. 'ext': 'mp4',
  127. 'title': video_title,
  128. 'description': video_description,
  129. 'thumbnail': thumbnail,
  130. 'uploader_id': video_uploader_id,
  131. }]
  132. class TeamcocoIE(InfoExtractor):
  133. _VALID_URL = r'http://teamcoco\.com/video/(?P<url_title>.*)'
  134. def _real_extract(self, url):
  135. mobj = re.match(self._VALID_URL, url)
  136. if mobj is None:
  137. raise ExtractorError(u'Invalid URL: %s' % url)
  138. url_title = mobj.group('url_title')
  139. webpage = self._download_webpage(url, url_title)
  140. video_id = self._html_search_regex(r'<article class="video" data-id="(\d+?)"',
  141. webpage, u'video id')
  142. self.report_extraction(video_id)
  143. video_title = self._html_search_regex(r'<meta property="og:title" content="(.+?)"',
  144. webpage, u'title')
  145. thumbnail = self._html_search_regex(r'<meta property="og:image" content="(.+?)"',
  146. webpage, u'thumbnail', fatal=False)
  147. video_description = self._html_search_regex(r'<meta property="og:description" content="(.*?)"',
  148. webpage, u'description', fatal=False)
  149. data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
  150. data = self._download_webpage(data_url, video_id, 'Downloading data webpage')
  151. video_url = self._html_search_regex(r'<file type="high".*?>(.*?)</file>',
  152. data, u'video URL')
  153. return [{
  154. 'id': video_id,
  155. 'url': video_url,
  156. 'ext': 'mp4',
  157. 'title': video_title,
  158. 'thumbnail': thumbnail,
  159. 'description': video_description,
  160. }]
  161. class XHamsterIE(InfoExtractor):
  162. """Information Extractor for xHamster"""
  163. _VALID_URL = r'(?:http://)?(?:www.)?xhamster\.com/movies/(?P<id>[0-9]+)/.*\.html'
  164. def _real_extract(self,url):
  165. mobj = re.match(self._VALID_URL, url)
  166. video_id = mobj.group('id')
  167. mrss_url = 'http://xhamster.com/movies/%s/.html' % video_id
  168. webpage = self._download_webpage(mrss_url, video_id)
  169. mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
  170. if mobj is None:
  171. raise ExtractorError(u'Unable to extract media URL')
  172. if len(mobj.group('server')) == 0:
  173. video_url = compat_urllib_parse.unquote(mobj.group('file'))
  174. else:
  175. video_url = mobj.group('server')+'/key='+mobj.group('file')
  176. video_extension = video_url.split('.')[-1]
  177. video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
  178. webpage, u'title')
  179. # Can't see the description anywhere in the UI
  180. # video_description = self._html_search_regex(r'<span>Description: </span>(?P<description>[^<]+)',
  181. # webpage, u'description', fatal=False)
  182. # if video_description: video_description = unescapeHTML(video_description)
  183. 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)
  184. if mobj:
  185. video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
  186. else:
  187. video_upload_date = None
  188. self._downloader.report_warning(u'Unable to extract upload date')
  189. video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
  190. webpage, u'uploader id', default=u'anonymous')
  191. video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
  192. webpage, u'thumbnail', fatal=False)
  193. return [{
  194. 'id': video_id,
  195. 'url': video_url,
  196. 'ext': video_extension,
  197. 'title': video_title,
  198. # 'description': video_description,
  199. 'upload_date': video_upload_date,
  200. 'uploader_id': video_uploader_id,
  201. 'thumbnail': video_thumbnail
  202. }]
  203. def gen_extractors():
  204. """ Return a list of an instance of every supported extractor.
  205. The order does matter; the first extractor matched is the one handling the URL.
  206. """
  207. return [
  208. YoutubePlaylistIE(),
  209. YoutubeChannelIE(),
  210. YoutubeUserIE(),
  211. YoutubeSearchIE(),
  212. YoutubeIE(),
  213. MetacafeIE(),
  214. DailymotionIE(),
  215. GoogleSearchIE(),
  216. PhotobucketIE(),
  217. YahooIE(),
  218. YahooSearchIE(),
  219. DepositFilesIE(),
  220. FacebookIE(),
  221. BlipTVIE(),
  222. BlipTVUserIE(),
  223. VimeoIE(),
  224. MyVideoIE(),
  225. ComedyCentralIE(),
  226. EscapistIE(),
  227. CollegeHumorIE(),
  228. XVideosIE(),
  229. SoundcloudSetIE(),
  230. SoundcloudIE(),
  231. InfoQIE(),
  232. MixcloudIE(),
  233. StanfordOpenClassroomIE(),
  234. MTVIE(),
  235. YoukuIE(),
  236. XNXXIE(),
  237. YouJizzIE(),
  238. PornotubeIE(),
  239. YouPornIE(),
  240. GooglePlusIE(),
  241. ArteTvIE(),
  242. NBAIE(),
  243. WorldStarHipHopIE(),
  244. JustinTVIE(),
  245. FunnyOrDieIE(),
  246. SteamIE(),
  247. UstreamIE(),
  248. RBMARadioIE(),
  249. EightTracksIE(),
  250. KeekIE(),
  251. TEDIE(),
  252. MySpassIE(),
  253. SpiegelIE(),
  254. LiveLeakIE(),
  255. ARDIE(),
  256. ZDFIE(),
  257. TumblrIE(),
  258. BandcampIE(),
  259. RedTubeIE(),
  260. InaIE(),
  261. HowcastIE(),
  262. VineIE(),
  263. FlickrIE(),
  264. TeamcocoIE(),
  265. XHamsterIE(),
  266. HypemIE(),
  267. Vbox7IE(),
  268. GametrailersIE(),
  269. StatigramIE(),
  270. GenericIE()
  271. ]
  272. def get_info_extractor(ie_name):
  273. """Returns the info extractor class with the given ie_name"""
  274. return globals()[ie_name+'IE']