mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-11-04 08:35:12 +00:00 
			
		
		
		
	
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							b506289fe2
						
					
				
				
					commit
					870efdee28
				
			@@ -1,77 +1,94 @@
 | 
				
			|||||||
# coding: utf-8
 | 
					# coding: utf-8
 | 
				
			||||||
from __future__ import unicode_literals
 | 
					from __future__ import unicode_literals
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
from .common import InfoExtractor
 | 
					from .common import InfoExtractor
 | 
				
			||||||
from ..compat import compat_str
 | 
					 | 
				
			||||||
from ..utils import (
 | 
					from ..utils import (
 | 
				
			||||||
    ExtractorError,
 | 
					    ExtractorError,
 | 
				
			||||||
    int_or_none,
 | 
					 | 
				
			||||||
    remove_start,
 | 
					 | 
				
			||||||
    smuggle_url,
 | 
					    smuggle_url,
 | 
				
			||||||
 | 
					    str_or_none,
 | 
				
			||||||
    traverse_obj,
 | 
					    traverse_obj,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TVerIE(InfoExtractor):
 | 
					class TVerIE(InfoExtractor):
 | 
				
			||||||
    _VALID_URL = r'https?://(?:www\.)?tver\.jp/(?P<path>corner|episode|feature|lp|tokyo2020/video)/(?P<id>[fc]?\d+)'
 | 
					    _VALID_URL = r'https?://(?:www\.)?tver\.jp/(?:(?P<type>lp|corner|series|episodes?|feature|tokyo2020/video)/)+(?P<id>[a-zA-Z0-9]+)'
 | 
				
			||||||
    # videos are only available for 7 days
 | 
					 | 
				
			||||||
    _TESTS = [{
 | 
					    _TESTS = [{
 | 
				
			||||||
        'url': 'https://tver.jp/corner/f0062178',
 | 
					        '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'],
 | 
				
			||||||
 | 
					    }, {
 | 
				
			||||||
 | 
					        '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/corner/f0103888',
 | 
				
			||||||
        'only_matching': True,
 | 
					        'only_matching': True,
 | 
				
			||||||
    }, {
 | 
					    }, {
 | 
				
			||||||
        'url': 'https://tver.jp/feature/f0062413',
 | 
					        'url': 'https://tver.jp/lp/f0033031',
 | 
				
			||||||
        '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,
 | 
					 | 
				
			||||||
    }, {
 | 
					 | 
				
			||||||
        'url': 'https://tver.jp/lp/c0000239',
 | 
					 | 
				
			||||||
        'only_matching': True,
 | 
					 | 
				
			||||||
    }, {
 | 
					 | 
				
			||||||
        'url': 'https://tver.jp/tokyo2020/video/6264525510001',
 | 
					 | 
				
			||||||
        'only_matching': True,
 | 
					        'only_matching': True,
 | 
				
			||||||
    }]
 | 
					    }]
 | 
				
			||||||
    _TOKEN = None
 | 
					 | 
				
			||||||
    BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
 | 
					    BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
 | 
				
			||||||
 | 
					    _PLATFORM_UID = None
 | 
				
			||||||
 | 
					    _PLATFORM_TOKEN = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _real_initialize(self):
 | 
					    def _real_initialize(self):
 | 
				
			||||||
        self._TOKEN = self._download_json(
 | 
					        create_response = self._download_json(
 | 
				
			||||||
            'https://tver.jp/api/access_token.php', None)['token']
 | 
					            '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):
 | 
					    def _real_extract(self, url):
 | 
				
			||||||
        path, video_id = self._match_valid_url(url).groups()
 | 
					        video_id, video_type = self._match_valid_url(url).group('id', 'type')
 | 
				
			||||||
        if path == 'lp':
 | 
					        if video_type not in {'series', 'episodes'}:
 | 
				
			||||||
            webpage = self._download_webpage(url, video_id)
 | 
					            webpage = self._download_webpage(url, video_id, note='Resolving to new URL')
 | 
				
			||||||
            redirect_path = self._search_regex(r'to_href="([^"]+)', webpage, 'redirect path')
 | 
					            video_id = self._match_id(self._search_regex(
 | 
				
			||||||
            path, video_id = self._match_valid_url(f'https://tver.jp{redirect_path}').groups()
 | 
					                (r'canonical"\s*href="(https?://tver\.jp/[^"]+)"', r'&link=(https?://tver\.jp/[^?&]+)[?&]'),
 | 
				
			||||||
        api_response = self._download_json(f'https://api.tver.jp/v4/{path}/{video_id}', video_id, query={'token': self._TOKEN})
 | 
					                webpage, 'url regex'))
 | 
				
			||||||
        p_id = traverse_obj(api_response, ('main', 'publisher_id'))
 | 
					        video_info = self._download_json(
 | 
				
			||||||
        if not p_id:
 | 
					            f'https://statics.tver.jp/content/episode/{video_id}.json', video_id,
 | 
				
			||||||
            error_msg, expected = traverse_obj(api_response, ('episode', 0, 'textbar', 0, ('text', 'longer')), get_all=False), True
 | 
					            query={'v': '5'}, headers={
 | 
				
			||||||
            if not error_msg:
 | 
					                'Origin': 'https://tver.jp',
 | 
				
			||||||
                error_msg, expected = 'Failed to extract publisher ID', False
 | 
					                'Referer': 'https://tver.jp/',
 | 
				
			||||||
            raise ExtractorError(error_msg, expected=expected)
 | 
					            })
 | 
				
			||||||
        service = remove_start(traverse_obj(api_response, ('main', 'service')), 'ts_')
 | 
					        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'))
 | 
					        additional_info = self._download_json(
 | 
				
			||||||
        if service not in ('tx', 'russia2018', 'sebare2018live', 'gorin'):
 | 
					            f'https://platform-api.tver.jp/service/api/v1/callEpisode/{video_id}?require_data=mylist,later[epefy106ur],good[epefy106ur],resume[epefy106ur]',
 | 
				
			||||||
            r_id = 'ref:' + r_id
 | 
					            video_id, fatal=False,
 | 
				
			||||||
        bc_url = smuggle_url(
 | 
					            query={
 | 
				
			||||||
            self.BRIGHTCOVE_URL_TEMPLATE % (p_id, r_id),
 | 
					                'platform_uid': self._PLATFORM_UID,
 | 
				
			||||||
            {'geo_countries': ['JP']})
 | 
					                'platform_token': self._PLATFORM_TOKEN,
 | 
				
			||||||
 | 
					            }, headers={
 | 
				
			||||||
 | 
					                'x-tver-platform-type': 'web'
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            '_type': 'url_transparent',
 | 
					            '_type': 'url_transparent',
 | 
				
			||||||
            'description': traverse_obj(api_response, ('main', 'note', 0, 'text'), expected_type=compat_str),
 | 
					            'title': str_or_none(video_info.get('title')),
 | 
				
			||||||
            'episode_number': int_or_none(traverse_obj(api_response, ('main', 'ext', 'episode_number'), expected_type=compat_str)),
 | 
					            'description': str_or_none(video_info.get('description')),
 | 
				
			||||||
            'url': bc_url,
 | 
					            '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',
 | 
					            'ie_key': 'BrightcoveNew',
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user