2016-05-08 02:34:38 -04:00
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
|
from ..utils import (
|
|
|
|
|
ExtractorError,
|
|
|
|
|
int_or_none,
|
|
|
|
|
smuggle_url,
|
2023-05-24 14:00:43 -04:00
|
|
|
|
traverse_obj,
|
2023-12-24 11:33:16 -05:00
|
|
|
|
try_call,
|
2016-05-08 02:34:38 -04:00
|
|
|
|
unsmuggle_url,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LiTVIE(InfoExtractor):
|
2016-09-08 07:29:05 -04:00
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?litv\.tv/(?:vod|promo)/[^/]+/(?:content\.do)?\?.*?\b(?:content_)?id=(?P<id>[^&]+)'
|
2016-05-08 02:34:38 -04:00
|
|
|
|
|
2023-10-06 18:27:54 -04:00
|
|
|
|
_URL_TEMPLATE = 'https://www.litv.tv/vod/%s/content.do?content_id=%s'
|
2016-05-08 02:34:38 -04:00
|
|
|
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
|
'url': 'https://www.litv.tv/vod/drama/content.do?brc_id=root&id=VOD00041610&isUHEnabled=true&autoPlay=1',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'VOD00041606',
|
|
|
|
|
'title': '花千骨',
|
|
|
|
|
},
|
2023-10-06 18:27:54 -04:00
|
|
|
|
'playlist_count': 51, # 50 episodes + 1 trailer
|
2016-05-08 02:34:38 -04:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.litv.tv/vod/drama/content.do?brc_id=root&id=VOD00041610&isUHEnabled=true&autoPlay=1',
|
2023-10-06 18:27:54 -04:00
|
|
|
|
'md5': 'b90ff1e9f1d8f5cfcd0a44c3e2b34c7a',
|
2016-05-08 02:34:38 -04:00
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'VOD00041610',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': '花千骨第1集',
|
2017-01-02 07:08:07 -05:00
|
|
|
|
'thumbnail': r're:https?://.*\.jpg$',
|
2023-10-06 18:27:54 -04:00
|
|
|
|
'description': '《花千骨》陸劇線上看。十六年前,平靜的村莊內,一名女嬰隨異相出生,途徑此地的蜀山掌門清虛道長算出此女命運非同一般,她體內散發的異香易招惹妖魔。一念慈悲下,他在村莊周邊設下結界阻擋妖魔入侵,讓其年滿十六後去蜀山,並賜名花千骨。',
|
|
|
|
|
'categories': ['奇幻', '愛情', '中國', '仙俠'],
|
|
|
|
|
'episode': 'Episode 1',
|
2016-05-08 02:34:38 -04:00
|
|
|
|
'episode_number': 1,
|
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
'noplaylist': True,
|
2016-08-19 12:52:37 -04:00
|
|
|
|
},
|
|
|
|
|
'skip': 'Georestricted to Taiwan',
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.litv.tv/promo/miyuezhuan/?content_id=VOD00044841&',
|
|
|
|
|
'md5': '88322ea132f848d6e3e18b32a832b918',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'VOD00044841',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': '芈月傳第1集 霸星芈月降世楚國',
|
|
|
|
|
'description': '楚威王二年,太史令唐昧夜觀星象,發現霸星即將現世。王后得知霸星的預言後,想盡辦法不讓孩子順利出生,幸得莒姬相護化解危機。沒想到眾人期待下出生的霸星卻是位公主,楚威王對此失望至極。楚王后命人將女嬰丟棄河中,居然奇蹟似的被少司命像攔下,楚威王認為此女非同凡響,為她取名芈月。',
|
2016-05-08 02:34:38 -04:00
|
|
|
|
},
|
2023-10-06 18:27:54 -04:00
|
|
|
|
'skip': 'No longer exists',
|
2016-05-08 02:34:38 -04:00
|
|
|
|
}]
|
|
|
|
|
|
2023-10-06 18:27:54 -04:00
|
|
|
|
def _extract_playlist(self, playlist_data, content_type):
|
2016-05-08 02:34:38 -04:00
|
|
|
|
all_episodes = [
|
|
|
|
|
self.url_result(smuggle_url(
|
2023-10-06 18:27:54 -04:00
|
|
|
|
self._URL_TEMPLATE % (content_type, episode['contentId']),
|
2016-05-08 02:34:38 -04:00
|
|
|
|
{'force_noplaylist': True})) # To prevent infinite recursion
|
2023-10-06 18:27:54 -04:00
|
|
|
|
for episode in traverse_obj(playlist_data, ('seasons', ..., 'episode', lambda _, v: v['contentId']))]
|
2016-05-08 02:34:38 -04:00
|
|
|
|
|
2023-10-06 18:27:54 -04:00
|
|
|
|
return self.playlist_result(all_episodes, playlist_data['contentId'], playlist_data.get('title'))
|
2016-05-08 02:34:38 -04:00
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2022-01-23 14:51:39 -05:00
|
|
|
|
url, smuggled_data = unsmuggle_url(url, {})
|
2016-05-08 02:34:38 -04:00
|
|
|
|
|
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
|
2023-10-06 18:27:54 -04:00
|
|
|
|
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)
|
|
|
|
|
|
2016-10-23 11:22:09 -04:00
|
|
|
|
program_info = self._parse_json(self._search_regex(
|
2017-01-02 07:08:07 -05:00
|
|
|
|
r'var\s+programInfo\s*=\s*([^;]+)', webpage, 'VOD data', default='{}'),
|
2016-05-08 02:34:38 -04:00
|
|
|
|
video_id)
|
|
|
|
|
|
2023-10-06 18:27:54 -04:00
|
|
|
|
# In browsers `getProgramInfo` request is always issued. Usually this
|
2016-05-08 02:34:38 -04:00
|
|
|
|
# endpoint gives the same result as the data embedded in the webpage.
|
2023-10-06 18:27:54 -04:00
|
|
|
|
# If, for some reason, there are no embedded data, we do an extra request.
|
2016-10-23 11:22:09 -04:00
|
|
|
|
if 'assetId' not in program_info:
|
|
|
|
|
program_info = self._download_json(
|
2016-08-19 12:52:37 -04:00
|
|
|
|
'https://www.litv.tv/vod/ajax/getProgramInfo', video_id,
|
|
|
|
|
query={'contentId': video_id},
|
|
|
|
|
headers={'Accept': 'application/json'})
|
2023-10-06 18:27:54 -04:00
|
|
|
|
|
|
|
|
|
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'])
|
|
|
|
|
|
2016-05-08 02:34:38 -04:00
|
|
|
|
video_data = self._parse_json(self._search_regex(
|
|
|
|
|
r'uiHlsUrl\s*=\s*testBackendData\(([^;]+)\);',
|
|
|
|
|
webpage, 'video data', default='{}'), video_id)
|
|
|
|
|
if not video_data:
|
2023-12-24 11:33:16 -05:00
|
|
|
|
payload = {'assetId': program_info['assetId']}
|
|
|
|
|
puid = try_call(lambda: self._get_cookies('https://www.litv.tv/')['PUID'].value)
|
|
|
|
|
if puid:
|
|
|
|
|
payload.update({
|
|
|
|
|
'type': 'auth',
|
|
|
|
|
'puid': puid,
|
|
|
|
|
})
|
|
|
|
|
endpoint = 'getUrl'
|
|
|
|
|
else:
|
|
|
|
|
payload.update({
|
|
|
|
|
'watchDevices': program_info['watchDevices'],
|
|
|
|
|
'contentType': program_info['contentType'],
|
|
|
|
|
})
|
|
|
|
|
endpoint = 'getMainUrlNoAuth'
|
2016-05-08 02:34:38 -04:00
|
|
|
|
video_data = self._download_json(
|
2023-12-24 11:33:16 -05:00
|
|
|
|
f'https://www.litv.tv/vod/ajax/{endpoint}', video_id,
|
2024-06-11 19:09:58 -04:00
|
|
|
|
data=json.dumps(payload).encode(),
|
2016-05-08 02:34:38 -04:00
|
|
|
|
headers={'Content-Type': 'application/json'})
|
|
|
|
|
|
|
|
|
|
if not video_data.get('fullpath'):
|
|
|
|
|
error_msg = video_data.get('errorMessage')
|
|
|
|
|
if error_msg == 'vod.error.outsideregionerror':
|
|
|
|
|
self.raise_geo_restricted('This video is available in Taiwan only')
|
|
|
|
|
if error_msg:
|
2024-06-11 19:09:58 -04:00
|
|
|
|
raise ExtractorError(f'{self.IE_NAME} said: {error_msg}', expected=True)
|
|
|
|
|
raise ExtractorError(f'Unexpected result from {self.IE_NAME}')
|
2016-05-08 02:34:38 -04:00
|
|
|
|
|
|
|
|
|
formats = self._extract_m3u8_formats(
|
2016-08-19 12:52:37 -04:00
|
|
|
|
video_data['fullpath'], video_id, ext='mp4',
|
|
|
|
|
entry_protocol='m3u8_native', m3u8_id='hls')
|
2016-05-08 02:34:38 -04:00
|
|
|
|
for a_format in formats:
|
|
|
|
|
# LiTV HLS segments doesn't like compressions
|
2023-05-20 18:55:09 -04:00
|
|
|
|
a_format.setdefault('http_headers', {})['Accept-Encoding'] = 'identity'
|
2016-05-08 02:34:38 -04:00
|
|
|
|
|
2016-10-23 11:22:09 -04:00
|
|
|
|
title = program_info['title'] + program_info.get('secondaryMark', '')
|
|
|
|
|
description = program_info.get('description')
|
|
|
|
|
thumbnail = program_info.get('imageFile')
|
|
|
|
|
categories = [item['name'] for item in program_info.get('category', [])]
|
|
|
|
|
episode = int_or_none(program_info.get('episode'))
|
2016-05-08 02:34:38 -04:00
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
'id': video_id,
|
|
|
|
|
'formats': formats,
|
|
|
|
|
'title': title,
|
|
|
|
|
'description': description,
|
|
|
|
|
'thumbnail': thumbnail,
|
|
|
|
|
'categories': categories,
|
|
|
|
|
'episode_number': episode,
|
|
|
|
|
}
|