Skip to content

Commit

Permalink
[extractor/videa] Back-port from yt-dlp PRs 463+1028
Browse files Browse the repository at this point in the history
Authored by: nyuszika7h
  • Loading branch information
dirkf committed Feb 11, 2022
1 parent 8ff961d commit 74f8cc4
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions youtube_dl/extractor/videa.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
mimetype2ext,
parse_codecs,
update_url_query,
urljoin,
xpath_element,
xpath_text,
)
from ..compat import (
compat_b64decode,
compat_ord,
compat_struct_pack,
compat_urlparse,
)


Expand All @@ -45,10 +47,24 @@ class VideaIE(InfoExtractor):
},
}, {
'url': 'http://videa.hu/videok/origo/jarmuvek/supercars-elozes-jAHDWfWSJH5XuFhH',
'only_matching': True,
'md5': 'd57ccd8812c7fd491d33b1eab8c99975',
'info_dict': {
'id': 'jAHDWfWSJH5XuFhH',
'ext': 'mp4',
'title': 'Supercars előzés',
'thumbnail': r're:^https?://.*',
'duration': 64,
},
}, {
'url': 'http://videa.hu/player?v=8YfIAjxwWGwT8HVQ',
'only_matching': True,
'md5': '97a7af41faeaffd9f1fc864a7c7e7603',
'info_dict': {
'id': '8YfIAjxwWGwT8HVQ',
'ext': 'mp4',
'title': 'Az őrült kígyász 285 kígyót enged szabadon',
'thumbnail': r're:^https?://.*',
'duration': 21,
},
}, {
'url': 'http://videa.hu/player/v/8YfIAjxwWGwT8HVQ?autoplay=1',
'only_matching': True,
Expand Down Expand Up @@ -95,9 +111,16 @@ def rc4(cipher_text, key):

def _real_extract(self, url):
video_id = self._match_id(url)
query = {'v': video_id}
player_page = self._download_webpage(
'https://videa.hu/player', video_id, query=query)
video_page = self._download_webpage(url, video_id)

if 'videa.hu/player' in url:
player_url = url
player_page = video_page
else:
player_url = self._search_regex(
r'<iframe.*?src="(/player\?[^"]+)"', video_page, 'player url')
player_url = urljoin(url, player_url)
player_page = self._download_webpage(player_url, video_id)

nonce = self._search_regex(
r'_xt\s*=\s*"([^"]+)"', player_page, 'nonce')
Expand All @@ -107,6 +130,7 @@ def _real_extract(self, url):
for i in range(0, 32):
result += s[i - (self._STATIC_SECRET.index(l[i]) - 31)]

query = compat_urlparse.parse_qs(compat_urlparse.urlparse(player_url).query)
random_seed = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(8))
query['_s'] = random_seed
query['_t'] = result[:16]
Expand All @@ -127,7 +151,7 @@ def _real_extract(self, url):
sources = xpath_element(
info, './video_sources', 'sources', fatal=True)
hash_values = xpath_element(
info, './hash_values', 'hash values', fatal=True)
info, './hash_values', 'hash values', fatal=False)

title = xpath_text(video, './title', fatal=True)

Expand All @@ -136,15 +160,16 @@ def _real_extract(self, url):
source_url = source.text
source_name = source.get('name')
source_exp = source.get('exp')
if not (source_url and source_name and source_exp):
if not (source_url and source_name):
continue
hash_value = xpath_text(hash_values, 'hash_value_' + source_name)
if not hash_value:
continue
source_url = update_url_query(source_url, {
'md5': hash_value,
'expires': source_exp,
})
hash_value = (
xpath_text(hash_values, 'hash_value_' + source_name)
if hash_values is not None else None)
if hash_value and source_exp:
source_url = update_url_query(source_url, {
'md5': hash_value,
'expires': source_exp,
})
f = parse_codecs(source.get('codecs'))
f.update({
'url': self._proto_relative_url(source_url),
Expand Down

0 comments on commit 74f8cc4

Please sign in to comment.