Repository: ytdl-org/youtube-dl

Issue:
Videa extractor crashes
<!--

######################################################################
  WARNING!
  IGNORING THE FOLLOWING TEMPLATE WILL RESULT IN ISSUE CLOSED AS INCOMPLETE
######################################################################

-->


## Checklist

<!--
Carefully read and work through this check list in order to prevent the most common mistakes and misuse of youtube-dl:
- First of, make sure you are using the latest version of youtube-dl. Run `youtube-dl --version` and ensure your version is 2021.12.17. If it's not, see https://yt-dl.org/update on how to update. Issues with outdated version will be REJECTED.
- Make sure that all provided video/audio/playlist URLs (if any) are alive and playable in a browser.
- Make sure that all URLs and arguments with special characters are properly quoted or escaped as explained in http://yt-dl.org/escape.
- Search the bugtracker for similar issues: http://yt-dl.org/search-issues. DO NOT post duplicates.
- Read bugs section in FAQ: http://yt-dl.org/reporting
- Finally, put x into all relevant boxes (like this [x])
-->

- [x] I'm reporting a broken site support issue
- [x] I've verified that I'm running youtube-dl version **2021.12.17**
- [x] I've checked that all provided URLs are alive and playable in a browser
- [x] I've checked that all URLs and arguments with special characters are properly quoted or escaped
- [x] I've searched the bugtracker for similar bug reports including closed ones
- [x] I've read bugs section in FAQ


## Verbose log

<!--
Provide the complete verbose output of youtube-dl that clearly demonstrates the problem.
Add the `-v` flag to your command line you run youtube-dl with (`youtube-dl -v <your command line>`), copy the WHOLE output and insert it below. It should look similar to this:
 [debug] System config: []
 [debug] User config: []
 [debug] Command-line args: [u'-v', u'http://www.youtube.com/watch?v=BaW_jenozKcj']
 [debug] Encodings: locale cp1251, fs mbcs, out cp866, pref cp1251
 [debug] youtube-dl version 2021.12.17
 [debug] Python version 2.7.11 - Windows-2003Server-5.2.3790-SP2
 [debug] exe versions: ffmpeg N-75573-g1d0487f, ffprobe N-75573-g1d0487f, rtmpdump 2.4
 [debug] Proxy map: {}
 <more lines>
-->

```
~$ youtube-dl --verbose https://videa.hu/videok/film-animacio/stephen-king-a-ragyogas-1980.-115-perc-angol-amerikai-thriller-AbnZmvpLVyvkrVCn
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'--verbose', u'https://videa.hu/videok/film-animacio/stephen-king-a-ragyogas-1980.-115-perc-angol-amerikai-thriller-AbnZmvpLVyvkrVCn']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2021.12.17
[debug] Python version 2.7.17 (CPython) - Linux-4.15.0-163-generic-i686-with-Ubuntu-18.04-bionic
[debug] exe versions: ffmpeg 3.4.8, ffprobe 3.4.8, rtmpdump 2.4
[debug] Proxy map: {}
[Videa] AbnZmvpLVyvkrVCn: Downloading webpage
[Videa] AbnZmvpLVyvkrVCn: Downloading webpage
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "./youtube-dl/youtube-dl/__main__.py", line 19, in <module>
  File "./youtube-dl/youtube-dl/youtube_dl/__init__.py", line 475, in main
  File "./youtube-dl/youtube-dl/youtube_dl/__init__.py", line 465, in _real_main
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 2069, in download
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 808, in extract_info
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 815, in wrapper
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 836, in __extract_info
  File "./youtube-dl/youtube-dl/youtube_dl/extractor/common.py", line 534, in extract
  File "./youtube-dl/youtube-dl/youtube_dl/extractor/videa.py", line 121, in _real_extract
  File "./youtube-dl/youtube-dl/youtube_dl/extractor/videa.py", line 94, in rc4
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 168: ordinal not in range(128)
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
ImportError: No module named apport.fileutils

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "./youtube-dl/youtube-dl/__main__.py", line 19, in <module>
  File "./youtube-dl/youtube-dl/youtube_dl/__init__.py", line 475, in main
  File "./youtube-dl/youtube-dl/youtube_dl/__init__.py", line 465, in _real_main
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 2069, in download
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 808, in extract_info
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 815, in wrapper
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 836, in __extract_info
  File "./youtube-dl/youtube-dl/youtube_dl/extractor/common.py", line 534, in extract
  File "./youtube-dl/youtube-dl/youtube_dl/extractor/videa.py", line 121, in _real_extract
  File "./youtube-dl/youtube-dl/youtube_dl/extractor/videa.py", line 94, in rc4
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 168: ordinal not in range(128)

```


## Description

<!--
Provide an explanation of your issue in an arbitrary form. Please make sure the description is worded well enough to be understood, see https://github.com/ytdl-org/youtube-dl#is-the-description-of-the-issue-itself-sufficient. Provide any additional information, suggested solution and as much context and examples as possible.
If work on your issue requires account credentials please provide them or explain how one can obtain them.
-->

Youtube-dl crashes when download from Videa is requested. Example URL is provided above.

Videa extractor crashes
<!--

######################################################################
  WARNING!
  IGNORING THE FOLLOWING TEMPLATE WILL RESULT IN ISSUE CLOSED AS INCOMPLETE
######################################################################

-->


## Checklist

<!--
Carefully read and work through this check list in order to prevent the most common mistakes and misuse of youtube-dl:
- First of, make sure you are using the latest version of youtube-dl. Run `youtube-dl --version` and ensure your version is 2021.12.17. If it's not, see https://yt-dl.org/update on how to update. Issues with outdated version will be REJECTED.
- Make sure that all provided video/audio/playlist URLs (if any) are alive and playable in a browser.
- Make sure that all URLs and arguments with special characters are properly quoted or escaped as explained in http://yt-dl.org/escape.
- Search the bugtracker for similar issues: http://yt-dl.org/search-issues. DO NOT post duplicates.
- Read bugs section in FAQ: http://yt-dl.org/reporting
- Finally, put x into all relevant boxes (like this [x])
-->

- [x] I'm reporting a broken site support issue
- [x] I've verified that I'm running youtube-dl version **2021.12.17**
- [x] I've checked that all provided URLs are alive and playable in a browser
- [x] I've checked that all URLs and arguments with special characters are properly quoted or escaped
- [x] I've searched the bugtracker for similar bug reports including closed ones
- [x] I've read bugs section in FAQ


## Verbose log

<!--
Provide the complete verbose output of youtube-dl that clearly demonstrates the problem.
Add the `-v` flag to your command line you run youtube-dl with (`youtube-dl -v <your command line>`), copy the WHOLE output and insert it below. It should look similar to this:
 [debug] System config: []
 [debug] User config: []
 [debug] Command-line args: [u'-v', u'http://www.youtube.com/watch?v=BaW_jenozKcj']
 [debug] Encodings: locale cp1251, fs mbcs, out cp866, pref cp1251
 [debug] youtube-dl version 2021.12.17
 [debug] Python version 2.7.11 - Windows-2003Server-5.2.3790-SP2
 [debug] exe versions: ffmpeg N-75573-g1d0487f, ffprobe N-75573-g1d0487f, rtmpdump 2.4
 [debug] Proxy map: {}
 <more lines>
-->

```
~$ youtube-dl --verbose https://videa.hu/videok/film-animacio/stephen-king-a-ragyogas-1980.-115-perc-angol-amerikai-thriller-AbnZmvpLVyvkrVCn
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'--verbose', u'https://videa.hu/videok/film-animacio/stephen-king-a-ragyogas-1980.-115-perc-angol-amerikai-thriller-AbnZmvpLVyvkrVCn']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2021.12.17
[debug] Python version 2.7.17 (CPython) - Linux-4.15.0-163-generic-i686-with-Ubuntu-18.04-bionic
[debug] exe versions: ffmpeg 3.4.8, ffprobe 3.4.8, rtmpdump 2.4
[debug] Proxy map: {}
[Videa] AbnZmvpLVyvkrVCn: Downloading webpage
[Videa] AbnZmvpLVyvkrVCn: Downloading webpage
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "./youtube-dl/youtube-dl/__main__.py", line 19, in <module>
  File "./youtube-dl/youtube-dl/youtube_dl/__init__.py", line 475, in main
  File "./youtube-dl/youtube-dl/youtube_dl/__init__.py", line 465, in _real_main
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 2069, in download
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 808, in extract_info
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 815, in wrapper
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 836, in __extract_info
  File "./youtube-dl/youtube-dl/youtube_dl/extractor/common.py", line 534, in extract
  File "./youtube-dl/youtube-dl/youtube_dl/extractor/videa.py", line 121, in _real_extract
  File "./youtube-dl/youtube-dl/youtube_dl/extractor/videa.py", line 94, in rc4
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 168: ordinal not in range(128)
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
ImportError: No module named apport.fileutils

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "./youtube-dl/youtube-dl/__main__.py", line 19, in <module>
  File "./youtube-dl/youtube-dl/youtube_dl/__init__.py", line 475, in main
  File "./youtube-dl/youtube-dl/youtube_dl/__init__.py", line 465, in _real_main
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 2069, in download
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 808, in extract_info
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 815, in wrapper
  File "./youtube-dl/youtube-dl/youtube_dl/YoutubeDL.py", line 836, in __extract_info
  File "./youtube-dl/youtube-dl/youtube_dl/extractor/common.py", line 534, in extract
  File "./youtube-dl/youtube-dl/youtube_dl/extractor/videa.py", line 121, in _real_extract
  File "./youtube-dl/youtube-dl/youtube_dl/extractor/videa.py", line 94, in rc4
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 168: ordinal not in range(128)

```


## Description

<!--
Provide an explanation of your issue in an arbitrary form. Please make sure the description is worded well enough to be understood, see https://github.com/ytdl-org/youtube-dl#is-the-description-of-the-issue-itself-sufficient. Provide any additional information, suggested solution and as much context and examples as possible.
If work on your issue requires account credentials please provide them or explain how one can obtain them.
-->

Youtube-dl crashes when download from Videa is requested. Example URL is provided above.



Discussion:
Reproduces with 2.7. Works with 3.9, so if you can use 3.x, that may be a faster solution than waiting for a fix.

The fix is easy, though:
```
--- old/youtube-dl/youtube_dl/extractor/videa.py
+++ new/youtube-dl/youtube_dl/extractor/videa.py
@@ -91,7 +91,7 @@
             k = S[(S[i] + S[j]) % 256]
             res += compat_struct_pack('B', k ^ compat_ord(cipher_text[m]))
 
-        return res.decode()
+        return res.decode('utf-8')
 
     def _real_extract(self, url):
         video_id = self._match_id(url)
```
Reproduces with 2.7. Works with 3.9, so if you can use 3.x, that may be a faster solution than waiting for a fix.

The fix is easy, though:
```
--- old/youtube-dl/youtube_dl/extractor/videa.py
+++ new/youtube-dl/youtube_dl/extractor/videa.py
@@ -91,7 +91,7 @@
             k = S[(S[i] + S[j]) % 256]
             res += compat_struct_pack('B', k ^ compat_ord(cipher_text[m]))
 
-        return res.decode()
+        return res.decode('utf-8')
 
     def _real_extract(self, url):
         video_id = self._match_id(url)
```

Resolving patch:
diff --git a/youtube_dl/extractor/videa.py b/youtube_dl/extractor/videa.py
--- a/youtube_dl/extractor/videa.py
+++ b/youtube_dl/extractor/videa.py
@@ -12,6 +12,7 @@
     mimetype2ext,
     parse_codecs,
     update_url_query,
+    urljoin,
     xpath_element,
     xpath_text,
 )
@@ -19,6 +20,7 @@
     compat_b64decode,
     compat_ord,
     compat_struct_pack,
+    compat_urlparse,
 )
 
 
@@ -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,
@@ -91,13 +107,20 @@ def rc4(cipher_text, key):
             k = S[(S[i] + S[j]) % 256]
             res += compat_struct_pack('B', k ^ compat_ord(cipher_text[m]))
 
-        return res.decode()
+        return res.decode('utf-8')
 
     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')
@@ -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]
@@ -121,13 +145,13 @@ def _real_extract(self, url):
                 compat_b64decode(b64_info), key), video_id)
 
         video = xpath_element(info, './video', 'video')
-        if not video:
+        if video is None:
             raise ExtractorError(xpath_element(
                 info, './error', fatal=True), expected=True)
         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)
 
@@ -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),


Test patch: