Repository: yt-dlp/yt-dlp

Issue:
HTTP 405 on some of certain of site, eg: LiTV.
### 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 bug unrelated to a specific site
- [X] I've verified that I'm running yt-dlp version **2022.10.04** ([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)

### Provide a description that is worded well enough to be understood

I have issue with HTTP 405 on certain video site with along by example: `https://testweb/myfolder`

If this happens on extractors, please modify like this so the videos downloads happily: `http://testweb/myfolder/`

These problem is documented [here](https://social.msdn.microsoft.com/Forums/zh-TW/5bd2162e-935c-4f8c-8656-f00ac09b9363/3553125945post26178652922998629983303404053767935492?forum=236) 

### 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
yt-dlp -vUcw --user-agent "Mozilla/5.0 (Windows NT 10.0.22623; Win64; arm64) HTTP/3.0 Chrome/107.0.5300.0 Edg/107.0.1379.1 yt-dlp/$VERSION aria2/$VERSION wget/$VERSION Transmission/3.00 IPTV Pro/$VERSION" --referer "%(referer)s" -N 4294967295 -f mergeall --video-multistreams --audio-multistreams --merge-output-format mp4 --embed-subs --sub-langs all --sub-format best --embed-thumbnail --embed-chapters --downloader aria2c "https://www.litv.tv/vod/drama/content.do?brc_id=root&id=VOD00219257&isUHEnabled=true&autoPlay=0" --yes-playlist
[debug] Command-line config: ['-vUcw', '--user-agent', 'Mozilla/5.0 (Windows NT 10.0.22623; Win64; arm64) HTTP/3.0 Chrome/107.0.5300.0 Edg/107.0.1379.1 yt-dlp/ aria2/ wget/ Transmission/3.00 IPTV Pro/', '--referer', '%(referer)s', '-N', '4294967295', '-f', 'mergeall', '--video-multistreams', '--audio-multistreams', '--merge-output-format', 'mp4', '--embed-subs', '--sub-langs', 'all', '--sub-format', 'best', '--embed-thumbnail', '--embed-chapters', '--downloader', 'aria2c', 'https://www.litv.tv/vod/drama/content.do?brc_id=root&id=VOD00219257&isUHEnabled=true&autoPlay=0', '--yes-playlist']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.10.04 [4e0511f] (pip) API
[debug] Python 3.10.8 (CPython 64bit) - Linux-4.9.186-22986754-aarch64-with-libc (libc)
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 5.1.2 (setts), ffprobe 5.1.2
[debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[debug] Proxy map: {}
[debug] Loaded 1690 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: 2022.10.04, Current version: 2022.10.04
yt-dlp is up to date (2022.10.04)
[debug] [LiTV] Extracting URL: https://www.litv.tv/vod/drama/content.do?brc_id=root&id=VOD00219257&isUHEnabled=true&autoPlay=0
[LiTV] VOD00219257: Downloading webpage
[LiTV] VOD00219257: Downloading JSON metadata
ERROR: [LiTV] VOD00219257: Unable to download JSON metadata: HTTP Error 405: Method Not Allowed (caused by <HTTPError 405: 'Method Not Allowed'>); please report this issue on
https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using
yt-dlp -U
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 672, in extract
ie_result = self._real_extract(url)
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/yt_dlp/extractor/litv.py", line 98, in _real_extract
video_data = self._download_json(
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 1032, in download_content
res = getattr(self, download_handle.__name__)(url_or_request, video_id, **kwargs)
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 996, in download_handle
res = self._download_webpage_handle(
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 866, 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 "/data/data/com.termux/files/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 823, in _request_webpage
raise ExtractorError(errmsg, cause=err)
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 805, in _request_webpage
return self._downloader.urlopen(self._create_request(url_or_request, data, headers, query))
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/yt_dlp/YoutubeDL.py", line 3682, in urlopen
return self._opener.open(req, timeout=self._socket_timeout)
File "/data/data/com.termux/files/usr/lib/python3.10/urllib/request.py", line 525, in open
response = meth(req, response)
File "/data/data/com.termux/files/usr/lib/python3.10/urllib/request.py", line 634, in http_response
response = self.parent.error(
File "/data/data/com.termux/files/usr/lib/python3.10/urllib/request.py", line 563, in error
return self._call_chain(*args)
File "/data/data/com.termux/files/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/data/data/com.termux/files/usr/lib/python3.10/urllib/request.py", line 643, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 405: Method Not Allowed
```



Discussion:
Hi,
I have encountered this exact Error 405 too when using Odysee.  It began happening for me approx three days ago, i.e. November 15th.  I'm in Europe.  Now I cannot download anything on Odysee.

I would be grateful if a solution could be found to this issue as soon as possible.
Thank you!

Resolving patch:
diff --git a/yt_dlp/extractor/litv.py b/yt_dlp/extractor/litv.py
--- a/yt_dlp/extractor/litv.py
+++ b/yt_dlp/extractor/litv.py
@@ -13,7 +13,7 @@
 class LiTVIE(InfoExtractor):
     _VALID_URL = r'https?://(?:www\.)?litv\.tv/(?:vod|promo)/[^/]+/(?:content\.do)?\?.*?\b(?:content_)?id=(?P<id>[^&]+)'
 
-    _URL_TEMPLATE = 'https://www.litv.tv/vod/%s/content.do?id=%s'
+    _URL_TEMPLATE = 'https://www.litv.tv/vod/%s/content.do?content_id=%s'
 
     _TESTS = [{
         'url': 'https://www.litv.tv/vod/drama/content.do?brc_id=root&id=VOD00041610&isUHEnabled=true&autoPlay=1',
@@ -21,16 +21,18 @@ class LiTVIE(InfoExtractor):
             'id': 'VOD00041606',
             'title': '花千骨',
         },
-        'playlist_count': 50,
+        'playlist_count': 51,  # 50 episodes + 1 trailer
     }, {
         'url': 'https://www.litv.tv/vod/drama/content.do?brc_id=root&id=VOD00041610&isUHEnabled=true&autoPlay=1',
-        'md5': '969e343d9244778cb29acec608e53640',
+        'md5': 'b90ff1e9f1d8f5cfcd0a44c3e2b34c7a',
         'info_dict': {
             'id': 'VOD00041610',
             'ext': 'mp4',
             'title': '花千骨第1集',
             'thumbnail': r're:https?://.*\.jpg$',
-            'description': 'md5:c7017aa144c87467c4fb2909c4b05d6f',
+            'description': '《花千骨》陸劇線上看。十六年前，平靜的村莊內，一名女嬰隨異相出生，途徑此地的蜀山掌門清虛道長算出此女命運非同一般，她體內散發的異香易招惹妖魔。一念慈悲下，他在村莊周邊設下結界阻擋妖魔入侵，讓其年滿十六後去蜀山，並賜名花千骨。',
+            'categories': ['奇幻', '愛情', '中國', '仙俠'],
+            'episode': 'Episode 1',
             'episode_number': 1,
         },
         'params': {
@@ -46,20 +48,17 @@ class LiTVIE(InfoExtractor):
             'title': '芈月傳第1集　霸星芈月降世楚國',
             'description': '楚威王二年，太史令唐昧夜觀星象，發現霸星即將現世。王后得知霸星的預言後，想盡辦法不讓孩子順利出生，幸得莒姬相護化解危機。沒想到眾人期待下出生的霸星卻是位公主，楚威王對此失望至極。楚王后命人將女嬰丟棄河中，居然奇蹟似的被少司命像攔下，楚威王認為此女非同凡響，為她取名芈月。',
         },
-        'skip': 'Georestricted to Taiwan',
+        'skip': 'No longer exists',
     }]
 
-    def _extract_playlist(self, season_list, video_id, program_info, prompt=True):
-        episode_title = program_info['title']
-        content_id = season_list['contentId']
-
+    def _extract_playlist(self, playlist_data, content_type):
         all_episodes = [
             self.url_result(smuggle_url(
-                self._URL_TEMPLATE % (program_info['contentType'], episode['contentId']),
+                self._URL_TEMPLATE % (content_type, episode['contentId']),
                 {'force_noplaylist': True}))  # To prevent infinite recursion
-            for episode in season_list['episode']]
+            for episode in traverse_obj(playlist_data, ('seasons', ..., 'episode', lambda _, v: v['contentId']))]
 
-        return self.playlist_result(all_episodes, content_id, episode_title)
+        return self.playlist_result(all_episodes, playlist_data['contentId'], playlist_data.get('title'))
 
     def _real_extract(self, url):
         url, smuggled_data = unsmuggle_url(url, {})
@@ -68,24 +67,31 @@ def _real_extract(self, url):
 
         webpage = self._download_webpage(url, video_id)
 
+        if self._search_regex(
+                r'(?i)<meta\s[^>]*http-equiv="refresh"\s[^>]*content="[0-9]+;\s*url=https://www\.litv\.tv/"',
+                webpage, 'meta refresh redirect', default=False, group=0):
+            raise ExtractorError('No such content found', expected=True)
+
         program_info = self._parse_json(self._search_regex(
             r'var\s+programInfo\s*=\s*([^;]+)', webpage, 'VOD data', default='{}'),
             video_id)
 
-        season_list = list(program_info.get('seasonList', {}).values())
-        playlist_id = traverse_obj(season_list, 0, 'contentId')
-        if self._yes_playlist(playlist_id, video_id, smuggled_data):
-            return self._extract_playlist(season_list[0], video_id, program_info)
-
-        # In browsers `getMainUrl` request is always issued. Usually this
+        # In browsers `getProgramInfo` request is always issued. Usually this
         # endpoint gives the same result as the data embedded in the webpage.
-        # If georestricted, there are no embedded data, so an extra request is
-        # necessary to get the error code
+        # If, for some reason, there are no embedded data, we do an extra request.
         if 'assetId' not in program_info:
             program_info = self._download_json(
                 'https://www.litv.tv/vod/ajax/getProgramInfo', video_id,
                 query={'contentId': video_id},
                 headers={'Accept': 'application/json'})
+
+        series_id = program_info['seriesId']
+        if self._yes_playlist(series_id, video_id, smuggled_data):
+            playlist_data = self._download_json(
+                'https://www.litv.tv/vod/ajax/getSeriesTree', video_id,
+                query={'seriesId': series_id}, headers={'Accept': 'application/json'})
+            return self._extract_playlist(playlist_data, program_info['contentType'])
+
         video_data = self._parse_json(self._search_regex(
             r'uiHlsUrl\s*=\s*testBackendData\(([^;]+)\);',
             webpage, 'video data', default='{}'), video_id)
@@ -96,7 +102,7 @@ def _real_extract(self, url):
                 'contentType': program_info['contentType'],
             }
             video_data = self._download_json(
-                'https://www.litv.tv/vod/getMainUrl', video_id,
+                'https://www.litv.tv/vod/ajax/getMainUrlNoAuth', video_id,
                 data=json.dumps(payload).encode('utf-8'),
                 headers={'Content-Type': 'application/json'})
 


Test patch: