You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

352 lines
12 KiB

Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
10 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
10 years ago
10 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_str,
  8. compat_urllib_parse,
  9. )
  10. from ..utils import (
  11. ExtractorError,
  12. orderedSet,
  13. sanitized_Request,
  14. str_to_int,
  15. unescapeHTML,
  16. unified_strdate,
  17. )
  18. from .vimeo import VimeoIE
  19. from .pladform import PladformIE
  20. class VKIE(InfoExtractor):
  21. IE_NAME = 'vk'
  22. IE_DESC = 'VK'
  23. _VALID_URL = r'''(?x)
  24. https?://
  25. (?:
  26. (?:m\.)?vk\.com/video_ext\.php\?.*?\boid=(?P<oid>-?\d+).*?\bid=(?P<id>\d+)|
  27. (?:
  28. (?:m\.)?vk\.com/(?:.+?\?.*?z=)?video|
  29. (?:www\.)?biqle\.ru/watch/
  30. )
  31. (?P<videoid>[^s].*?)(?:\?(?:.*\blist=(?P<list_id>[\da-f]+))?|%2F|$)
  32. )
  33. '''
  34. _NETRC_MACHINE = 'vk'
  35. _TESTS = [
  36. {
  37. 'url': 'http://vk.com/videos-77521?z=video-77521_162222515%2Fclub77521',
  38. 'md5': '0deae91935c54e00003c2a00646315f0',
  39. 'info_dict': {
  40. 'id': '162222515',
  41. 'ext': 'flv',
  42. 'title': 'ProtivoGunz - Хуёвая песня',
  43. 'uploader': 're:(?:Noize MC|Alexander Ilyashenko).*',
  44. 'duration': 195,
  45. 'upload_date': '20120212',
  46. 'view_count': int,
  47. },
  48. },
  49. {
  50. 'url': 'http://vk.com/video205387401_165548505',
  51. 'md5': '6c0aeb2e90396ba97035b9cbde548700',
  52. 'info_dict': {
  53. 'id': '165548505',
  54. 'ext': 'mp4',
  55. 'uploader': 'Tom Cruise',
  56. 'title': 'No name',
  57. 'duration': 9,
  58. 'upload_date': '20130721',
  59. 'view_count': int,
  60. }
  61. },
  62. {
  63. 'note': 'Embedded video',
  64. 'url': 'http://vk.com/video_ext.php?oid=32194266&id=162925554&hash=7d8c2e0d5e05aeaa&hd=1',
  65. 'md5': 'c7ce8f1f87bec05b3de07fdeafe21a0a',
  66. 'info_dict': {
  67. 'id': '162925554',
  68. 'ext': 'mp4',
  69. 'uploader': 'Vladimir Gavrin',
  70. 'title': 'Lin Dan',
  71. 'duration': 101,
  72. 'upload_date': '20120730',
  73. 'view_count': int,
  74. }
  75. },
  76. {
  77. # VIDEO NOW REMOVED
  78. # please update if you find a video whose URL follows the same pattern
  79. 'url': 'http://vk.com/video-8871596_164049491',
  80. 'md5': 'a590bcaf3d543576c9bd162812387666',
  81. 'note': 'Only available for registered users',
  82. 'info_dict': {
  83. 'id': '164049491',
  84. 'ext': 'mp4',
  85. 'uploader': 'Триллеры',
  86. 'title': '► Бойцовский клуб / Fight Club 1999 [HD 720]',
  87. 'duration': 8352,
  88. 'upload_date': '20121218',
  89. 'view_count': int,
  90. },
  91. 'skip': 'Requires vk account credentials',
  92. },
  93. {
  94. 'url': 'http://vk.com/hd_kino_mania?z=video-43215063_168067957%2F15c66b9b533119788d',
  95. 'md5': '4d7a5ef8cf114dfa09577e57b2993202',
  96. 'info_dict': {
  97. 'id': '168067957',
  98. 'ext': 'mp4',
  99. 'uploader': 'Киномания - лучшее из мира кино',
  100. 'title': ' ',
  101. 'duration': 7291,
  102. 'upload_date': '20140328',
  103. },
  104. 'skip': 'Requires vk account credentials',
  105. },
  106. {
  107. 'url': 'http://m.vk.com/video-43215063_169084319?list=125c627d1aa1cebb83&from=wall-43215063_2566540',
  108. 'md5': '0c45586baa71b7cb1d0784ee3f4e00a6',
  109. 'note': 'ivi.ru embed',
  110. 'info_dict': {
  111. 'id': '60690',
  112. 'ext': 'mp4',
  113. 'title': 'Книга Илая',
  114. 'duration': 6771,
  115. 'upload_date': '20140626',
  116. 'view_count': int,
  117. },
  118. 'skip': 'Only works from Russia',
  119. },
  120. {
  121. # video (removed?) only available with list id
  122. 'url': 'https://vk.com/video30481095_171201961?list=8764ae2d21f14088d4',
  123. 'md5': '091287af5402239a1051c37ec7b92913',
  124. 'info_dict': {
  125. 'id': '171201961',
  126. 'ext': 'mp4',
  127. 'title': 'ТюменцевВВ_09.07.2015',
  128. 'uploader': 'Anton Ivanov',
  129. 'duration': 109,
  130. 'upload_date': '20150709',
  131. 'view_count': int,
  132. },
  133. },
  134. {
  135. # youtube embed
  136. 'url': 'https://vk.com/video276849682_170681728',
  137. 'info_dict': {
  138. 'id': 'V3K4mi0SYkc',
  139. 'ext': 'mp4',
  140. 'title': "DSWD Awards 'Children's Joy Foundation, Inc.' Certificate of Registration and License to Operate",
  141. 'description': 'md5:bf9c26cfa4acdfb146362682edd3827a',
  142. 'duration': 179,
  143. 'upload_date': '20130116',
  144. 'uploader': "Children's Joy Foundation",
  145. 'uploader_id': 'thecjf',
  146. 'view_count': int,
  147. },
  148. },
  149. {
  150. # removed video, just testing that we match the pattern
  151. 'url': 'http://vk.com/feed?z=video-43215063_166094326%2Fbb50cacd3177146d7a',
  152. 'only_matching': True,
  153. },
  154. {
  155. # age restricted video, requires vk account credentials
  156. 'url': 'https://vk.com/video205387401_164765225',
  157. 'only_matching': True,
  158. },
  159. {
  160. # vk wrapper
  161. 'url': 'http://www.biqle.ru/watch/847655_160197695',
  162. 'only_matching': True,
  163. },
  164. {
  165. # pladform embed
  166. 'url': 'https://vk.com/video-76116461_171554880',
  167. 'only_matching': True,
  168. }
  169. ]
  170. def _login(self):
  171. (username, password) = self._get_login_info()
  172. if username is None:
  173. return
  174. login_page = self._download_webpage(
  175. 'https://vk.com', None, 'Downloading login page')
  176. login_form = self._hidden_inputs(login_page)
  177. login_form.update({
  178. 'email': username.encode('cp1251'),
  179. 'pass': password.encode('cp1251'),
  180. })
  181. request = sanitized_Request(
  182. 'https://login.vk.com/?act=login',
  183. compat_urllib_parse.urlencode(login_form).encode('utf-8'))
  184. login_page = self._download_webpage(
  185. request, None, note='Logging in as %s' % username)
  186. if re.search(r'onLoginFailed', login_page):
  187. raise ExtractorError(
  188. 'Unable to login, incorrect username and/or password', expected=True)
  189. def _real_initialize(self):
  190. self._login()
  191. def _real_extract(self, url):
  192. mobj = re.match(self._VALID_URL, url)
  193. video_id = mobj.group('videoid')
  194. if not video_id:
  195. video_id = '%s_%s' % (mobj.group('oid'), mobj.group('id'))
  196. info_url = 'https://vk.com/al_video.php?act=show&al=1&module=video&video=%s' % video_id
  197. # Some videos (removed?) can only be downloaded with list id specified
  198. list_id = mobj.group('list_id')
  199. if list_id:
  200. info_url += '&list=%s' % list_id
  201. info_page = self._download_webpage(info_url, video_id)
  202. error_message = self._html_search_regex(
  203. r'(?s)<!><div[^>]+class="video_layer_message"[^>]*>(.+?)</div>',
  204. info_page, 'error message', default=None)
  205. if error_message:
  206. raise ExtractorError(error_message, expected=True)
  207. if re.search(r'<!>/login\.php\?.*\bact=security_check', info_page):
  208. raise ExtractorError(
  209. 'You are trying to log in from an unusual location. You should confirm ownership at vk.com to log in with this IP.',
  210. expected=True)
  211. ERRORS = {
  212. r'>Видеозапись .*? была изъята из публичного доступа в связи с обращением правообладателя.<':
  213. 'Video %s has been removed from public access due to rightholder complaint.',
  214. r'<!>Please log in or <':
  215. 'Video %s is only available for registered users, '
  216. 'use --username and --password options to provide account credentials.',
  217. r'<!>Unknown error':
  218. 'Video %s does not exist.',
  219. r'<!>Видео временно недоступно':
  220. 'Video %s is temporarily unavailable.',
  221. r'<!>Access denied':
  222. 'Access denied to video %s.',
  223. }
  224. for error_re, error_msg in ERRORS.items():
  225. if re.search(error_re, info_page):
  226. raise ExtractorError(error_msg % video_id, expected=True)
  227. youtube_url = self._search_regex(
  228. r'<iframe[^>]+src="((?:https?:)?//www.youtube.com/embed/[^"]+)"',
  229. info_page, 'youtube iframe', default=None)
  230. if youtube_url:
  231. return self.url_result(youtube_url, 'Youtube')
  232. vimeo_url = VimeoIE._extract_vimeo_url(url, info_page)
  233. if vimeo_url is not None:
  234. return self.url_result(vimeo_url)
  235. pladform_url = PladformIE._extract_url(info_page)
  236. if pladform_url:
  237. return self.url_result(pladform_url)
  238. m_rutube = re.search(
  239. r'\ssrc="((?:https?:)?//rutube\.ru\\?/video\\?/embed(?:.*?))\\?"', info_page)
  240. if m_rutube is not None:
  241. rutube_url = self._proto_relative_url(
  242. m_rutube.group(1).replace('\\', ''))
  243. return self.url_result(rutube_url)
  244. m_opts = re.search(r'(?s)var\s+opts\s*=\s*({.+?});', info_page)
  245. if m_opts:
  246. m_opts_url = re.search(r"url\s*:\s*'((?!/\b)[^']+)", m_opts.group(1))
  247. if m_opts_url:
  248. opts_url = m_opts_url.group(1)
  249. if opts_url.startswith('//'):
  250. opts_url = 'http:' + opts_url
  251. return self.url_result(opts_url)
  252. data_json = self._search_regex(r'var\s+vars\s*=\s*({.+?});', info_page, 'vars')
  253. data = json.loads(data_json)
  254. # Extract upload date
  255. upload_date = None
  256. mobj = re.search(r'id="mv_date(?:_views)?_wrap"[^>]*>([a-zA-Z]+ [0-9]+), ([0-9]+) at', info_page)
  257. if mobj is not None:
  258. mobj.group(1) + ' ' + mobj.group(2)
  259. upload_date = unified_strdate(mobj.group(1) + ' ' + mobj.group(2))
  260. view_count = None
  261. views = self._html_search_regex(
  262. r'"mv_views_count_number"[^>]*>(.+?\bviews?)<',
  263. info_page, 'view count', fatal=False)
  264. if views:
  265. view_count = str_to_int(self._search_regex(
  266. r'([\d,.]+)', views, 'view count', fatal=False))
  267. formats = [{
  268. 'format_id': k,
  269. 'url': v,
  270. 'width': int(k[len('url'):]),
  271. } for k, v in data.items()
  272. if k.startswith('url')]
  273. self._sort_formats(formats)
  274. return {
  275. 'id': compat_str(data['vid']),
  276. 'formats': formats,
  277. 'title': unescapeHTML(data['md_title']),
  278. 'thumbnail': data.get('jpg'),
  279. 'uploader': data.get('md_author'),
  280. 'duration': data.get('duration'),
  281. 'upload_date': upload_date,
  282. 'view_count': view_count,
  283. }
  284. class VKUserVideosIE(InfoExtractor):
  285. IE_NAME = 'vk:uservideos'
  286. IE_DESC = "VK - User's Videos"
  287. _VALID_URL = r'https?://vk\.com/videos(?P<id>-?[0-9]+)$'
  288. _TEMPLATE_URL = 'https://vk.com/videos'
  289. _TESTS = [{
  290. 'url': 'http://vk.com/videos205387401',
  291. 'info_dict': {
  292. 'id': '205387401',
  293. 'title': "Tom Cruise's Videos",
  294. },
  295. 'playlist_mincount': 4,
  296. }, {
  297. 'url': 'http://vk.com/videos-77521',
  298. 'only_matching': True,
  299. }]
  300. def _real_extract(self, url):
  301. page_id = self._match_id(url)
  302. webpage = self._download_webpage(url, page_id)
  303. entries = [
  304. self.url_result(
  305. 'http://vk.com/video' + video_id, 'VK', video_id=video_id)
  306. for video_id in orderedSet(re.findall(r'href="/video(-?[0-9_]+)"', webpage))]
  307. title = unescapeHTML(self._search_regex(
  308. r'<title>\s*([^<]+?)\s+\|\s+\d+\s+videos',
  309. webpage, 'title', default=page_id))
  310. return self.playlist_result(entries, page_id, title)