From 2a4c11ddb49095cb18fab39c47849dbf7ba457b8 Mon Sep 17 00:00:00 2001 From: vvto33 <54504675+vvto33@users.noreply.github.com> Date: Thu, 15 Jul 2021 16:36:21 +0900 Subject: [PATCH] [TVer] Support redirect from landing page --- youtube_dl/extractor/tver.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/tver.py b/youtube_dl/extractor/tver.py index a4a30b1e6..dbb3914a2 100644 --- a/youtube_dl/extractor/tver.py +++ b/youtube_dl/extractor/tver.py @@ -6,6 +6,7 @@ import re from .common import InfoExtractor from ..compat import compat_str from ..utils import ( + ExtractorError, int_or_none, remove_start, smuggle_url, @@ -14,7 +15,7 @@ from ..utils import ( class TVerIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?tver\.jp/(?P(?:corner|episode|feature)/(?Pf?\d+))' + _VALID_URL = r'https?://(?:www\.)?tver\.jp/(?P(?:corner|episode|feature|lp)/(?P[fc]?\d+))' # videos are only available for 7 days _TESTS = [{ 'url': 'https://tver.jp/corner/f0062178', @@ -29,16 +30,33 @@ class TVerIE(InfoExtractor): # subtitle = ' ' 'url': 'https://tver.jp/corner/f0068870', 'only_matching': True, + }, { + # redirect "f" + 'url': 'https://tver.jp/lp/f0009694', + 'only_matching': True, + }, { + # redirect "c" + 'url': 'https://tver.jp/lp/c0000239', + 'only_matching': True, }] _TOKEN = None BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s' + def _extract_redirect(self, url): + webpage = self._download_webpage(url, "") + newpath = re.search(r'to_href="(.+?)";', webpage) + if newpath is None: + raise ExtractorError('Not found redirect path', expected=True) + return re.match(self._VALID_URL, "https://tver.jp" + newpath.group(1)).groups() + def _real_initialize(self): self._TOKEN = self._download_json( 'https://tver.jp/api/access_token.php', None)['token'] def _real_extract(self, url): path, video_id = re.match(self._VALID_URL, url).groups() + if path[0:2] == "lp": + path, video_id = self._extract_redirect(url) main = self._download_json( 'https://api.tver.jp/v4/' + path, video_id, query={'token': self._TOKEN})['main']