3 from .common
import InfoExtractor
13 class LiTVIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://(?:www\.)?litv\.tv/(?:vod|promo)/[^/]+/(?:content\.do)?\?.*?\b(?:content_)?id=(?P<id>[^&]+)'
16 _URL_TEMPLATE
= 'https://www.litv.tv/vod/%s/content.do?id=%s'
19 'url': 'https://www.litv.tv/vod/drama/content.do?brc_id=root&id=VOD00041610&isUHEnabled=true&autoPlay=1',
26 'url': 'https://www.litv.tv/vod/drama/content.do?brc_id=root&id=VOD00041610&isUHEnabled=true&autoPlay=1',
27 'md5': '969e343d9244778cb29acec608e53640',
32 'thumbnail': r
're:https?://.*\.jpg$',
33 'description': 'md5:c7017aa144c87467c4fb2909c4b05d6f',
39 'skip': 'Georestricted to Taiwan',
41 'url': 'https://www.litv.tv/promo/miyuezhuan/?content_id=VOD00044841&',
42 'md5': '88322ea132f848d6e3e18b32a832b918',
46 'title': '芈月傳第1集 霸星芈月降世楚國',
47 'description': '楚威王二年,太史令唐昧夜觀星象,發現霸星即將現世。王后得知霸星的預言後,想盡辦法不讓孩子順利出生,幸得莒姬相護化解危機。沒想到眾人期待下出生的霸星卻是位公主,楚威王對此失望至極。楚王后命人將女嬰丟棄河中,居然奇蹟似的被少司命像攔下,楚威王認為此女非同凡響,為她取名芈月。',
49 'skip': 'Georestricted to Taiwan',
52 def _extract_playlist(self
, season_list
, video_id
, program_info
, prompt
=True):
53 episode_title
= program_info
['title']
54 content_id
= season_list
['contentId']
57 self
.url_result(smuggle_url(
58 self
._URL
_TEMPLATE
% (program_info
['contentType'], episode
['contentId']),
59 {'force_noplaylist': True}
)) # To prevent infinite recursion
60 for episode
in season_list
['episode']]
62 return self
.playlist_result(all_episodes
, content_id
, episode_title
)
64 def _real_extract(self
, url
):
65 url
, smuggled_data
= unsmuggle_url(url
, {})
67 video_id
= self
._match
_id
(url
)
69 webpage
= self
._download
_webpage
(url
, video_id
)
71 program_info
= self
._parse
_json
(self
._search
_regex
(
72 r
'var\s+programInfo\s*=\s*([^;]+)', webpage
, 'VOD data', default
='{}'),
75 season_list
= list(program_info
.get('seasonList', {}).values())
76 playlist_id
= traverse_obj(season_list
, 0, 'contentId')
77 if self
._yes
_playlist
(playlist_id
, video_id
, smuggled_data
):
78 return self
._extract
_playlist
(season_list
[0], video_id
, program_info
)
80 # In browsers `getMainUrl` request is always issued. Usually this
81 # endpoint gives the same result as the data embedded in the webpage.
82 # If georestricted, there are no embedded data, so an extra request is
83 # necessary to get the error code
84 if 'assetId' not in program_info
:
85 program_info
= self
._download
_json
(
86 'https://www.litv.tv/vod/ajax/getProgramInfo', video_id
,
87 query
={'contentId': video_id}
,
88 headers
={'Accept': 'application/json'}
)
89 video_data
= self
._parse
_json
(self
._search
_regex
(
90 r
'uiHlsUrl\s*=\s*testBackendData\(([^;]+)\);',
91 webpage
, 'video data', default
='{}'), video_id
)
94 'assetId': program_info
['assetId'],
95 'watchDevices': program_info
['watchDevices'],
96 'contentType': program_info
['contentType'],
98 video_data
= self
._download
_json
(
99 'https://www.litv.tv/vod/getMainUrl', video_id
,
100 data
=json
.dumps(payload
).encode('utf-8'),
101 headers
={'Content-Type': 'application/json'}
)
103 if not video_data
.get('fullpath'):
104 error_msg
= video_data
.get('errorMessage')
105 if error_msg
== 'vod.error.outsideregionerror':
106 self
.raise_geo_restricted('This video is available in Taiwan only')
108 raise ExtractorError('%s said: %s' % (self
.IE_NAME
, error_msg
), expected
=True)
109 raise ExtractorError('Unexpected result from %s' % self
.IE_NAME
)
111 formats
= self
._extract
_m
3u8_formats
(
112 video_data
['fullpath'], video_id
, ext
='mp4',
113 entry_protocol
='m3u8_native', m3u8_id
='hls')
114 for a_format
in formats
:
115 # LiTV HLS segments doesn't like compressions
116 a_format
.setdefault('http_headers', {})['Youtubedl-no-compression'] = True
118 title
= program_info
['title'] + program_info
.get('secondaryMark', '')
119 description
= program_info
.get('description')
120 thumbnail
= program_info
.get('imageFile')
121 categories
= [item
['name'] for item
in program_info
.get('category', [])]
122 episode
= int_or_none(program_info
.get('episode'))
128 'description': description
,
129 'thumbnail': thumbnail
,
130 'categories': categories
,
131 'episode_number': episode
,