2 from __future__
import unicode_literals
7 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': '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
, vod_data
, view_data
, prompt
=True):
56 episode_title
= view_data
['title']
57 content_id
= season_list
['contentId']
60 self
.to_screen('Downloading playlist %s - add --no-playlist to just download video %s' % (content_id
, video_id
))
63 self
.url_result(smuggle_url(
64 self
._URL
_TEMPLATE
% (view_data
['contentType'], episode
['contentId']),
65 {'force_noplaylist': True}
)) # To prevent infinite recursion
66 for episode
in season_list
['episode']]
68 return self
.playlist_result(all_episodes
, content_id
, episode_title
)
70 def _real_extract(self
, url
):
71 url
, data
= unsmuggle_url(url
, {})
73 video_id
= self
._match
_id
(url
)
75 noplaylist
= self
._downloader
.params
.get('noplaylist')
76 noplaylist_prompt
= True
77 if 'force_noplaylist' in data
:
78 noplaylist
= data
['force_noplaylist']
79 noplaylist_prompt
= False
81 webpage
= self
._download
_webpage
(url
, video_id
)
83 view_data
= dict(map(lambda t
: (t
[0], t
[2]), re
.findall(
84 r
'viewData\.([a-zA-Z]+)\s*=\s*(["\'])([^
"\']+)\2',
87 vod_data = self._parse_json(self._search_regex(
88 'var\s+vod\s*=\s*([^;]+)', webpage, 'VOD data', default='{}'),
91 season_list = list(vod_data.get('seasonList', {}).values())
94 return self._extract_playlist(
95 season_list[0], video_id, vod_data, view_data,
96 prompt=noplaylist_prompt)
99 self.to_screen('Downloading just video %s because of --no-playlist' % video_id)
101 # In browsers `getMainUrl` request is always issued. Usually this
102 # endpoint gives the same result as the data embedded in the webpage.
103 # If georestricted, there are no embedded data, so an extra request is
104 # necessary to get the error code
105 if 'assetId' not in view_data:
106 view_data = self._download_json(
107 'https://www.litv.tv/vod/ajax/getProgramInfo', video_id,
108 query={'contentId': video_id},
109 headers={'Accept': 'application/json'})
110 video_data = self._parse_json(self._search_regex(
111 r'uiHlsUrl\s*=\s*testBackendData\(([^;]+)\);',
112 webpage, 'video data', default='{}'), video_id)
115 'assetId': view_data['assetId'],
116 'watchDevices': view_data['watchDevices'],
117 'contentType': view_data['contentType'],
119 video_data = self._download_json(
120 'https://www.litv.tv/vod/getMainUrl', video_id,
121 data=json.dumps(payload).encode('utf-8'),
122 headers={'Content-Type': 'application/json'})
124 if not video_data.get('fullpath'):
125 error_msg = video_data.get('errorMessage')
126 if error_msg == 'vod.error.outsideregionerror':
127 self.raise_geo_restricted('This video is available in Taiwan only')
129 raise ExtractorError('%s said: %s' % (self.IE_NAME, error_msg), expected=True)
130 raise ExtractorError('Unexpected result from %s' % self.IE_NAME)
132 formats = self._extract_m3u8_formats(
133 video_data['fullpath'], video_id, ext='mp4',
134 entry_protocol='m3u8_native', m3u8_id='hls')
135 for a_format in formats:
136 # LiTV HLS segments doesn't like compressions
137 a_format.setdefault('http_headers', {})['Youtubedl-no-compression'] = True
139 title = view_data['title'] + view_data.get('secondaryMark', '')
140 description = view_data.get('description')
141 thumbnail = view_data.get('imageFile')
142 categories = [item['name'] for item in vod_data.get('category', [])]
143 episode = int_or_none(view_data.get('episode'))
149 'description': description,
150 'thumbnail': thumbnail,
151 'categories': categories,
152 'episode_number': episode,