Repository: yt-dlp/yt-dlp

Issue:
TVer support broken
### Checklist

- [X] I'm reporting a broken site
- [X] I've verified that I'm running yt-dlp version **2022.03.08.1**. ([update instructions](https://github.com/yt-dlp/yt-dlp#update))
- [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](https://github.com/ytdl-org/youtube-dl#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)
- [X] 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

Japan

### Description

It used to be possible to download from TVer (tver.jp) when its URL was in this format.
https://tver.jp/feature/f0101104

Today, TVer revamped its website, and the URL is now like this.
https://tver.jp/episodes/epgqep1rqb

This throws an "Unsupported URL" error when using yt-dlp.

### Verbose log

```shell
[debug] Command-line config: ['-vU', 'https://tver.jp/episodes/epgqep1rqb']
[debug] User config "/home/teck/.config/yt-dlp/config": ['-o', '~/Downloads/%(title)s.%(ext)s', '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4', '--trim-filenames', '80', '--no-mtime', '--all-subs', '--embed-subs']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, err utf-8, pref UTF-8
[debug] yt-dlp version 2022.03.08.1 [c0c2c57d3] (zip)
[debug] Python version 3.8.10 (CPython 64bit) - Linux-5.13.0-39-generic-x86_64-with-glibc2.29
[debug] exe versions: ffmpeg 4.2.4, ffprobe 4.2.4, rtmpdump 2.4
[debug] Optional libraries: Cryptodome, secretstorage, sqlite
[debug] Proxy map: {}
Latest version: 2022.03.08.1, Current version: 2022.03.08.1
yt-dlp is up to date (2022.03.08.1)
[debug] [generic] Extracting URL: https://tver.jp/episodes/epgqep1rqb
[generic] epgqep1rqb: Requesting header
WARNING: [generic] Falling back on generic information extractor.
[generic] epgqep1rqb: Downloading webpage
[generic] epgqep1rqb: Extracting information
[debug] Looking for video embeds
ERROR: Unsupported URL: https://tver.jp/episodes/epgqep1rqb
Traceback (most recent call last):
  File "/usr/local/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 1389, in wrapper
    return func(self, *args, **kwargs)
  File "/usr/local/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 1459, in __extract_info
    ie_result = ie.extract(url)
  File "/usr/local/bin/yt-dlp/yt_dlp/extractor/common.py", line 617, in extract
    ie_result = self._real_extract(url)
  File "/usr/local/bin/yt-dlp/yt_dlp/extractor/generic.py", line 3985, in _real_extract
    raise UnsupportedError(url)
yt_dlp.utils.UnsupportedError: Unsupported URL: https://tver.jp/episodes/epgqep1rqb
```



Discussion:
I can confirm the issue, for some reason link processing is sent to Generic extractor.
Here's another test link:
https://tver.jp/episodes/ep07dpaso7

Resolving patch:
diff --git a/yt_dlp/extractor/tver.py b/yt_dlp/extractor/tver.py
--- a/yt_dlp/extractor/tver.py
+++ b/yt_dlp/extractor/tver.py
@@ -1,77 +1,94 @@
 # coding: utf-8
 from __future__ import unicode_literals
 
-
 from .common import InfoExtractor
-from ..compat import compat_str
 from ..utils import (
     ExtractorError,
-    int_or_none,
-    remove_start,
     smuggle_url,
+    str_or_none,
     traverse_obj,
 )
 
 
 class TVerIE(InfoExtractor):
-    _VALID_URL = r'https?://(?:www\.)?tver\.jp/(?P<path>corner|episode|feature|lp|tokyo2020/video)/(?P<id>[fc]?\d+)'
-    # videos are only available for 7 days
+    _VALID_URL = r'https?://(?:www\.)?tver\.jp/(?:(?P<type>lp|corner|series|episodes?|feature|tokyo2020/video)/)+(?P<id>[a-zA-Z0-9]+)'
     _TESTS = [{
-        'url': 'https://tver.jp/corner/f0062178',
-        'only_matching': True,
+        'skip': 'videos are only available for 7 days',
+        'url': 'https://tver.jp/episodes/ephss8yveb',
+        'info_dict': {
+            'title': '#44　料理と値段と店主にびっくり　オモてなしすぎウマい店　2時間SP',
+            'description': 'md5:66985373a66fed8ad3cd595a3cfebb13',
+        },
+        'add_ie': ['BrightcoveNew'],
     }, {
-        'url': 'https://tver.jp/feature/f0062413',
-        'only_matching': True,
-    }, {
-        'url': 'https://tver.jp/episode/79622438',
-        'only_matching': True,
-    }, {
-        # subtitle = ' '
-        'url': 'https://tver.jp/corner/f0068870',
-        'only_matching': True,
-    }, {
-        'url': 'https://tver.jp/lp/f0009694',
-        'only_matching': True,
+        'skip': 'videos are only available for 7 days',
+        'url': 'https://tver.jp/lp/episodes/ep6f16g26p',
+        'info_dict': {
+            # sorry but this is "correct"
+            'title': '4月11日(月)23時06分 ~ 放送予定',
+            'description': 'md5:4029cc5f4b1e8090dfc5b7bd2bc5cd0b',
+        },
+        'add_ie': ['BrightcoveNew'],
     }, {
-        'url': 'https://tver.jp/lp/c0000239',
+        'url': 'https://tver.jp/corner/f0103888',
         'only_matching': True,
     }, {
-        'url': 'https://tver.jp/tokyo2020/video/6264525510001',
+        'url': 'https://tver.jp/lp/f0033031',
         'only_matching': True,
     }]
-    _TOKEN = None
     BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
+    _PLATFORM_UID = None
+    _PLATFORM_TOKEN = None
 
     def _real_initialize(self):
-        self._TOKEN = self._download_json(
-            'https://tver.jp/api/access_token.php', None)['token']
+        create_response = self._download_json(
+            'https://platform-api.tver.jp/v2/api/platform_users/browser/create', None,
+            note='Creating session', data=b'device_type=pc', headers={
+                'Origin': 'https://s.tver.jp',
+                'Referer': 'https://s.tver.jp/',
+                'Content-Type': 'application/x-www-form-urlencoded',
+            })
+        self._PLATFORM_UID = traverse_obj(create_response, ('result', 'platform_uid'))
+        self._PLATFORM_TOKEN = traverse_obj(create_response, ('result', 'platform_token'))
 
     def _real_extract(self, url):
-        path, video_id = self._match_valid_url(url).groups()
-        if path == 'lp':
-            webpage = self._download_webpage(url, video_id)
-            redirect_path = self._search_regex(r'to_href="([^"]+)', webpage, 'redirect path')
-            path, video_id = self._match_valid_url(f'https://tver.jp{redirect_path}').groups()
-        api_response = self._download_json(f'https://api.tver.jp/v4/{path}/{video_id}', video_id, query={'token': self._TOKEN})
-        p_id = traverse_obj(api_response, ('main', 'publisher_id'))
-        if not p_id:
-            error_msg, expected = traverse_obj(api_response, ('episode', 0, 'textbar', 0, ('text', 'longer')), get_all=False), True
-            if not error_msg:
-                error_msg, expected = 'Failed to extract publisher ID', False
-            raise ExtractorError(error_msg, expected=expected)
-        service = remove_start(traverse_obj(api_response, ('main', 'service')), 'ts_')
+        video_id, video_type = self._match_valid_url(url).group('id', 'type')
+        if video_type not in {'series', 'episodes'}:
+            webpage = self._download_webpage(url, video_id, note='Resolving to new URL')
+            video_id = self._match_id(self._search_regex(
+                (r'canonical"\s*href="(https?://tver\.jp/[^"]+)"', r'&link=(https?://tver\.jp/[^?&]+)[?&]'),
+                webpage, 'url regex'))
+        video_info = self._download_json(
+            f'https://statics.tver.jp/content/episode/{video_id}.json', video_id,
+            query={'v': '5'}, headers={
+                'Origin': 'https://tver.jp',
+                'Referer': 'https://tver.jp/',
+            })
+        p_id = video_info['video']['accountID']
+        r_id = traverse_obj(video_info, ('video', ('videoRefID', 'videoID')), get_all=False)
+        if not r_id:
+            raise ExtractorError('Failed to extract reference ID for Brightcove')
+        if not r_id.isdigit():
+            r_id = f'ref:{r_id}'
 
-        r_id = traverse_obj(api_response, ('main', 'reference_id'))
-        if service not in ('tx', 'russia2018', 'sebare2018live', 'gorin'):
-            r_id = 'ref:' + r_id
-        bc_url = smuggle_url(
-            self.BRIGHTCOVE_URL_TEMPLATE % (p_id, r_id),
-            {'geo_countries': ['JP']})
+        additional_info = self._download_json(
+            f'https://platform-api.tver.jp/service/api/v1/callEpisode/{video_id}?require_data=mylist,later[epefy106ur],good[epefy106ur],resume[epefy106ur]',
+            video_id, fatal=False,
+            query={
+                'platform_uid': self._PLATFORM_UID,
+                'platform_token': self._PLATFORM_TOKEN,
+            }, headers={
+                'x-tver-platform-type': 'web'
+            })
 
         return {
             '_type': 'url_transparent',
-            'description': traverse_obj(api_response, ('main', 'note', 0, 'text'), expected_type=compat_str),
-            'episode_number': int_or_none(traverse_obj(api_response, ('main', 'ext', 'episode_number'), expected_type=compat_str)),
-            'url': bc_url,
+            'title': str_or_none(video_info.get('title')),
+            'description': str_or_none(video_info.get('description')),
+            'url': smuggle_url(
+                self.BRIGHTCOVE_URL_TEMPLATE % (p_id, r_id), {'geo_countries': ['JP']}),
+            'series': traverse_obj(
+                additional_info, ('result', ('episode', 'series'), 'content', ('seriesTitle', 'title')),
+                get_all=False),
             'ie_key': 'BrightcoveNew',
         }


Test patch: