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