Repository: yt-dlp/yt-dlp

Issue:
Tnaflix HTTP Error 500: Internal Server Error
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting a broken site
- [X] I've verified that I'm running yt-dlp version **2022.09.01** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [ ] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

_No response_

### Provide a description that is worded well enough to be understood

HTTP Error 500: Internal Server Error

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
F:\downloader\tnaflix>yt-dlp https://www.tnaflix.com/hd-videos/Pantat-Bulat-dan-Montok-Dedek-Hijab-bikin-Tegang/video4651785 --verbose
[debug] Command-line config: ['https://www.tnaflix.com/hd-videos/Pantat-Bulat-dan-Montok-Dedek-Hijab-bikin-Tegang/video4651785', '--verbose']
[debug] User config "D:\OS Files\Users\X\AppData\Roaming\yt-dlp\config": ['--continue', '--format-sort', 'vbr,abr', '--http-chunk-size', '1M', '--buffer-size', '16K', '--sub-lang', 'english', '--no-embed-thumbnail', '--embed-metadata', '--abort-on-unavailable-fragment', '-o', '%(uploader)s\\%(title)s [%(id)s].%(ext)s', '-f', 'bestvideo+bestaudio/Source/hls-original/0/4320p/2160p/1440p/1080p/720p/540p/480p/240p', '--ffmpeg-location', 'D:\\OS Files\\Program Files\\ffmpeg\\bin', '--no-lock']
[debug] Encodings: locale cp65001, fs utf-8, pref cp65001, out utf-8, error utf-8, screen utf-8
[debug] ytdl-yt-dlp version 2022.09.01 [5d7c7d656]
[debug] ** Please make bug reports at https://github.com/ytdl-yt-dlp/ytdl-yt-dlp/issues/new/choose instead.
[debug] Lazy loading extractors is disabled
[debug] Python 3.10.4 (CPython 64bit) - Windows-10-10.0.19043-SP0
[debug] Checking exe version: "D:\OS Files\Program Files\ffmpeg\bin\ffmpeg" -bsfs
[debug] Checking exe version: "D:\OS Files\Program Files\ffmpeg\bin\ffprobe" -bsfs
[debug] exe versions: ffmpeg 5.0.1-essentials_build-www.gyan.dev (setts), ffprobe 5.0.1-essentials_build-www.gyan.dev
[debug] Optional libraries: Cryptodome-3.14.1, WebSocketsWrapper-None, brotli-1.0.9, certifi-2021.10.08, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.2
[debug] Proxy map: {}
[debug] Loaded 1717 extractors
[debug] [TNAFlix] Extracting URL: https://www.tnaflix.com/hd-videos/Pantat-Bulat-dan-Montok-Dedek-Hijab-bikin-Tegang/video4651785
[TNAFlix] Pantat-Bulat-dan-Montok-Dedek-Hijab-bikin-Tegang: Downloading webpage
[TNAFlix] [debug] Fetching webpage from https://www.tnaflix.com/hd-videos/Pantat-Bulat-dan-Montok-Dedek-Hijab-bikin-Tegang/video4651785
[TNAFlix] Pantat-Bulat-dan-Montok-Dedek-Hijab-bikin-Tegang: Downloading metadata
[TNAFlix] [debug] Fetching webpage from https://cdn-fck.tnaflix.com/tnaflix/ce9536510b66e11c6bd6.fid?key=e16735fe01baed06dea5fc291891508d&VID=4651785&premium=1&vip=1&alpha
ERROR: [TNAFlix] 4651785: Unable to download XML: HTTP Error 500: Internal Server Error (caused by <HTTPError 500: 'Internal Server Error'>); please report this issue on  https://github.com/ytdl-yt-dlp/ytdl-yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
  File "C:\Python\Python310\lib\site-packages\yt_dlp\extractor\common.py", line 702, in extract
    ie_result = self._real_extract(url)
  File "C:\Python\Python310\lib\site-packages\yt_dlp\extractor\tnaflix.py", line 93, in _real_extract
    cfg_xml = self._download_xml(
  File "C:\Python\Python310\lib\site-packages\yt_dlp\extractor\common.py", line 1087, in download_content
    res = getattr(self, download_handle.__name__)(url_or_request, video_id, **kwargs)
  File "C:\Python\Python310\lib\site-packages\yt_dlp\extractor\common.py", line 1046, in download_handle
    res = self._download_webpage_handle(
  File "C:\Python\Python310\lib\site-packages\yt_dlp\extractor\common.py", line 912, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal, data=data, headers=headers, query=query, expected_status=expected_status)
  File "C:\Python\Python310\lib\site-packages\yt_dlp\extractor\common.py", line 857, in _request_webpage
    raise ExtractorError(errmsg, cause=err)

  File "C:\Python\Python310\lib\site-packages\yt_dlp\extractor\common.py", line 839, in _request_webpage
    return self._downloader.urlopen(self._create_request(url_or_request, data, headers, query))
  File "C:\Python\Python310\lib\site-packages\yt_dlp\YoutubeDL.py", line 3079, in wrapper
    result = func(self, *args, **kwargs)
  File "C:\Python\Python310\lib\site-packages\yt_dlp\YoutubeDL.py", line 3979, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "C:\Python\Python310\lib\urllib\request.py", line 525, in open
    response = meth(req, response)
  File "C:\Python\Python310\lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
  File "C:\Python\Python310\lib\urllib\request.py", line 563, in error
    return self._call_chain(*args)
  File "C:\Python\Python310\lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
  File "C:\Python\Python310\lib\urllib\request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error
```



Discussion:

Resolving patch:
diff --git a/yt_dlp/extractor/tnaflix.py b/yt_dlp/extractor/tnaflix.py
--- a/yt_dlp/extractor/tnaflix.py
+++ b/yt_dlp/extractor/tnaflix.py
@@ -19,6 +19,7 @@ class TNAFlixNetworkBaseIE(InfoExtractor):
         r'config\s*=\s*(["\'])(?P<url>(?:https?:)?//(?:(?!\1).)+)\1',
     ]
     _HOST = 'tna'
+    _VIDEO_XML_URL = 'https://www.tnaflix.com/cdn/cdn.php?file={}.fid&key={}&VID={}&nomp4=1&catID=0&rollover=1&startThumb=12&embed=0&utm_source=0&multiview=0&premium=1&country=0user=0&vip=1&cd=0&ref=0&alpha'
     _VKEY_SUFFIX = ''
     _TITLE_REGEX = r'<input[^>]+name="title" value="([^"]+)"'
     _DESCRIPTION_REGEX = r'<input[^>]+name="description" value="([^"]+)"'
@@ -71,6 +72,10 @@ def get_child(elem, names):
     def _real_extract(self, url):
         mobj = self._match_valid_url(url)
         video_id = mobj.group('id')
+
+        def extract_field(pattern, name):
+            return self._html_search_regex(pattern, webpage, name, default=None) if pattern else None
+
         for display_id_key in ('display_id', 'display_id_2'):
             if display_id_key in mobj.groupdict():
                 display_id = mobj.group(display_id_key)
@@ -85,6 +90,13 @@ def _real_extract(self, url):
             self._CONFIG_REGEX, webpage, 'flashvars.config', default=None,
             group='url'), 'http:')
 
+        if not cfg_url:
+            vkey = extract_field(r'<input\b[^>]+\bid="vkey"\b[^>]+\bvalue="([^"]+)"', 'vkey')
+            nkey = extract_field(r'<input\b[^>]+\bid="nkey"\b[^>]+\bvalue="([^"]+)"', 'nkey')
+            vid = extract_field(r'<input\b[^>]+\bid="VID"\b[^>]+\bvalue="([^"]+)"', 'vid')
+            if vkey and nkey and vid:
+                cfg_url = self._proto_relative_url(self._VIDEO_XML_URL.format(vkey, nkey, vid), 'http:')
+
         if not cfg_url:
             inputs = self._hidden_inputs(webpage)
             cfg_url = ('https://cdn-fck.%sflix.com/%sflix/%s%s.fid?key=%s&VID=%s&premium=1&vip=1&alpha'
@@ -139,9 +151,6 @@ def extract_video_url(vl):
         duration = parse_duration(self._html_search_meta(
             'duration', webpage, 'duration', default=None))
 
-        def extract_field(pattern, name):
-            return self._html_search_regex(pattern, webpage, name, default=None) if pattern else None
-
         description = extract_field(self._DESCRIPTION_REGEX, 'description')
         uploader = extract_field(self._UPLOADER_REGEX, 'uploader')
         view_count = str_to_int(extract_field(self._VIEW_COUNT_REGEX, 'view count'))


Test patch: