aboutsummaryrefslogtreecommitdiffstats
path: root/hypervideo_dl/extractor/vk.py
diff options
context:
space:
mode:
Diffstat (limited to 'hypervideo_dl/extractor/vk.py')
-rw-r--r--hypervideo_dl/extractor/vk.py118
1 files changed, 63 insertions, 55 deletions
diff --git a/hypervideo_dl/extractor/vk.py b/hypervideo_dl/extractor/vk.py
index d8a9b9a..cbc3159 100644
--- a/hypervideo_dl/extractor/vk.py
+++ b/hypervideo_dl/extractor/vk.py
@@ -2,7 +2,6 @@
from __future__ import unicode_literals
import collections
-import functools
import re
from .common import InfoExtractor
@@ -12,7 +11,6 @@ from ..utils import (
ExtractorError,
get_element_by_class,
int_or_none,
- OnDemandPagedList,
orderedSet,
str_or_none,
str_to_int,
@@ -31,11 +29,7 @@ from .youtube import YoutubeIE
class VKBaseIE(InfoExtractor):
_NETRC_MACHINE = 'vk'
- def _login(self):
- username, password = self._get_login_info()
- if username is None:
- return
-
+ def _perform_login(self, username, password):
login_page, url_handle = self._download_webpage_handle(
'https://vk.com', None, 'Downloading login page')
@@ -51,7 +45,7 @@ class VKBaseIE(InfoExtractor):
self._apply_first_set_cookie_header(url_handle, 'remixlhk')
login_page = self._download_webpage(
- 'https://login.vk.com/?act=login', None,
+ 'https://vk.com/login', None,
note='Logging in',
data=urlencode_postdata(login_form))
@@ -59,9 +53,6 @@ class VKBaseIE(InfoExtractor):
raise ExtractorError(
'Unable to login, incorrect username and/or password', expected=True)
- def _real_initialize(self):
- self._login()
-
def _download_payload(self, path, video_id, data, fatal=True):
data['al'] = 1
code, payload = self._download_json(
@@ -87,10 +78,10 @@ class VKIE(VKBaseIE):
)
ext\.php\?(?P<embed_query>.*?\boid=(?P<oid>-?\d+).*?\bid=(?P<id>\d+).*)|
(?:
- (?:(?:m|new)\.)?vk\.com/(?:.+?\?.*?z=)?video|
+ (?:(?:m|new)\.)?vk\.com/(?:.+?\?.*?z=)?(?:video|clip)|
(?:www\.)?daxab.com/embed/
)
- (?P<videoid>-?\d+_\d+)(?:.*\blist=(?P<list_id>[\da-f]+))?
+ (?P<videoid>-?\d+_\d+)(?:.*\blist=(?P<list_id>([\da-f]+)|(ln-[\da-zA-Z]+)))?
)
'''
_TESTS = [
@@ -182,6 +173,17 @@ class VKIE(VKBaseIE):
'skip': 'Removed',
},
{
+ 'url': 'https://vk.com/video-93049196_456239755?list=ln-cBjJ7S4jYYx3ADnmDT',
+ 'info_dict': {
+ 'id': '-93049196_456239755',
+ 'ext': 'mp4',
+ 'title': '8 серия (озвучка)',
+ 'duration': 8383,
+ 'upload_date': '20211222',
+ 'view_count': int,
+ },
+ },
+ {
# video (removed?) only available with list id
'url': 'https://vk.com/video30481095_171201961?list=8764ae2d21f14088d4',
'md5': '091287af5402239a1051c37ec7b92913',
@@ -298,6 +300,10 @@ class VKIE(VKBaseIE):
# The video is not available in your region.
'url': 'https://vk.com/video-51812607_171445436',
'only_matching': True,
+ },
+ {
+ 'url': 'https://vk.com/clip30014565_456240946',
+ 'only_matching': True,
}]
@staticmethod
@@ -434,8 +440,6 @@ class VKIE(VKBaseIE):
# 2 = live
# 3 = post live (finished live)
is_live = data.get('live') == 2
- if is_live:
- title = self._live_title(title)
timestamp = unified_timestamp(self._html_search_regex(
r'class=["\']mv_info_date[^>]+>([^<]+)(?:<|from)', info_page,
@@ -471,6 +475,13 @@ class VKIE(VKBaseIE):
})
self._sort_formats(formats)
+ subtitles = {}
+ for sub in data.get('subs') or {}:
+ subtitles.setdefault(sub.get('lang', 'en'), []).append({
+ 'ext': sub.get('title', '.srt').split('.')[-1],
+ 'url': url_or_none(sub.get('url')),
+ })
+
return {
'id': video_id,
'formats': formats,
@@ -484,69 +495,66 @@ class VKIE(VKBaseIE):
'like_count': int_or_none(mv_data.get('likes')),
'comment_count': int_or_none(mv_data.get('commcount')),
'is_live': is_live,
+ 'subtitles': subtitles,
}
class VKUserVideosIE(VKBaseIE):
IE_NAME = 'vk:uservideos'
IE_DESC = "VK - User's Videos"
- _VALID_URL = r'https?://(?:(?:m|new)\.)?vk\.com/videos(?P<id>-?[0-9]+)(?!\?.*\bz=video)(?:[/?#&](?:.*?\bsection=(?P<section>\w+))?|$)'
+ _VALID_URL = r'https?://(?:(?:m|new)\.)?vk\.com/video/@(?P<id>[^?$#/&]+)(?!\?.*\bz=video)(?:[/?#&](?:.*?\bsection=(?P<section>\w+))?|$)'
_TEMPLATE_URL = 'https://vk.com/videos'
_TESTS = [{
- 'url': 'https://vk.com/videos-767561',
+ 'url': 'https://vk.com/video/@mobidevices',
'info_dict': {
- 'id': '-767561_all',
+ 'id': '-17892518_all',
},
- 'playlist_mincount': 1150,
+ 'playlist_mincount': 1355,
}, {
- 'url': 'https://vk.com/videos-767561?section=uploaded',
+ 'url': 'https://vk.com/video/@mobidevices?section=uploaded',
'info_dict': {
- 'id': '-767561_uploaded',
+ 'id': '-17892518_uploaded',
},
- 'playlist_mincount': 425,
- }, {
- 'url': 'http://vk.com/videos205387401',
- 'only_matching': True,
- }, {
- 'url': 'http://vk.com/videos-77521',
- 'only_matching': True,
- }, {
- 'url': 'http://vk.com/videos-97664626?section=all',
- 'only_matching': True,
- }, {
- 'url': 'http://m.vk.com/videos205387401',
- 'only_matching': True,
- }, {
- 'url': 'http://new.vk.com/videos205387401',
- 'only_matching': True,
+ 'playlist_mincount': 182,
}]
- _PAGE_SIZE = 1000
_VIDEO = collections.namedtuple('Video', ['owner_id', 'id'])
- def _fetch_page(self, page_id, section, page):
- l = self._download_payload('al_video', page_id, {
+ def _entries(self, page_id, section):
+ video_list_json = self._download_payload('al_video', page_id, {
'act': 'load_videos_silent',
- 'offset': page * self._PAGE_SIZE,
+ 'offset': 0,
'oid': page_id,
'section': section,
- })[0][section]['list']
-
- for video in l:
- v = self._VIDEO._make(video[:2])
- video_id = '%d_%d' % (v.owner_id, v.id)
- yield self.url_result(
- 'http://vk.com/video' + video_id, VKIE.ie_key(), video_id)
+ })[0][section]
+ count = video_list_json['count']
+ total = video_list_json['total']
+ video_list = video_list_json['list']
+
+ while True:
+ for video in video_list:
+ v = self._VIDEO._make(video[:2])
+ video_id = '%d_%d' % (v.owner_id, v.id)
+ yield self.url_result(
+ 'http://vk.com/video' + video_id, VKIE.ie_key(), video_id)
+ if count >= total:
+ break
+ video_list_json = self._download_payload('al_video', page_id, {
+ 'act': 'load_videos_silent',
+ 'offset': count,
+ 'oid': page_id,
+ 'section': section,
+ })[0][section]
+ count += video_list_json['count']
+ video_list = video_list_json['list']
def _real_extract(self, url):
- page_id, section = self._match_valid_url(url).groups()
+ u_id, section = self._match_valid_url(url).groups()
+ webpage = self._download_webpage(url, u_id)
+ page_id = self._search_regex(r'data-owner-id\s?=\s?"([^"]+)"', webpage, 'page_id')
if not section:
section = 'all'
- entries = OnDemandPagedList(
- functools.partial(self._fetch_page, page_id, section),
- self._PAGE_SIZE)
-
- return self.playlist_result(entries, '%s_%s' % (page_id, section))
+ return self.playlist_result(self._entries(page_id, section), '%s_%s' % (page_id, section))
class VKWallPostIE(VKBaseIE):
@@ -673,7 +681,7 @@ class VKWallPostIE(VKBaseIE):
'artist': performer,
'track': title,
'ext': 'mp4',
- 'protocol': 'm3u8',
+ 'protocol': 'm3u8_native',
})
for video in re.finditer(