]>
Commit | Line | Data |
---|---|---|
3b01a9fb | 1 | import json |
3b01a9fb YCH |
2 | |
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | ExtractorError, | |
6 | int_or_none, | |
7 | smuggle_url, | |
4823ec9f | 8 | traverse_obj, |
3b01a9fb YCH |
9 | unsmuggle_url, |
10 | ) | |
11 | ||
12 | ||
13 | class LiTVIE(InfoExtractor): | |
92519402 | 14 | _VALID_URL = r'https?://(?:www\.)?litv\.tv/(?:vod|promo)/[^/]+/(?:content\.do)?\?.*?\b(?:content_)?id=(?P<id>[^&]+)' |
3b01a9fb | 15 | |
91a670a4 | 16 | _URL_TEMPLATE = 'https://www.litv.tv/vod/%s/content.do?content_id=%s' |
3b01a9fb YCH |
17 | |
18 | _TESTS = [{ | |
19 | 'url': 'https://www.litv.tv/vod/drama/content.do?brc_id=root&id=VOD00041610&isUHEnabled=true&autoPlay=1', | |
20 | 'info_dict': { | |
21 | 'id': 'VOD00041606', | |
22 | 'title': '花千骨', | |
23 | }, | |
91a670a4 | 24 | 'playlist_count': 51, # 50 episodes + 1 trailer |
3b01a9fb YCH |
25 | }, { |
26 | 'url': 'https://www.litv.tv/vod/drama/content.do?brc_id=root&id=VOD00041610&isUHEnabled=true&autoPlay=1', | |
91a670a4 | 27 | 'md5': 'b90ff1e9f1d8f5cfcd0a44c3e2b34c7a', |
3b01a9fb YCH |
28 | 'info_dict': { |
29 | 'id': 'VOD00041610', | |
30 | 'ext': 'mp4', | |
31 | 'title': '花千骨第1集', | |
ec85ded8 | 32 | 'thumbnail': r're:https?://.*\.jpg$', |
91a670a4 | 33 | 'description': '《花千骨》陸劇線上看。十六年前,平靜的村莊內,一名女嬰隨異相出生,途徑此地的蜀山掌門清虛道長算出此女命運非同一般,她體內散發的異香易招惹妖魔。一念慈悲下,他在村莊周邊設下結界阻擋妖魔入侵,讓其年滿十六後去蜀山,並賜名花千骨。', |
34 | 'categories': ['奇幻', '愛情', '中國', '仙俠'], | |
35 | 'episode': 'Episode 1', | |
3b01a9fb YCH |
36 | 'episode_number': 1, |
37 | }, | |
38 | 'params': { | |
39 | 'noplaylist': True, | |
39e1c4f0 YCH |
40 | }, |
41 | 'skip': 'Georestricted to Taiwan', | |
42 | }, { | |
43 | 'url': 'https://www.litv.tv/promo/miyuezhuan/?content_id=VOD00044841&', | |
44 | 'md5': '88322ea132f848d6e3e18b32a832b918', | |
45 | 'info_dict': { | |
46 | 'id': 'VOD00044841', | |
47 | 'ext': 'mp4', | |
48 | 'title': '芈月傳第1集 霸星芈月降世楚國', | |
49 | 'description': '楚威王二年,太史令唐昧夜觀星象,發現霸星即將現世。王后得知霸星的預言後,想盡辦法不讓孩子順利出生,幸得莒姬相護化解危機。沒想到眾人期待下出生的霸星卻是位公主,楚威王對此失望至極。楚王后命人將女嬰丟棄河中,居然奇蹟似的被少司命像攔下,楚威王認為此女非同凡響,為她取名芈月。', | |
3b01a9fb | 50 | }, |
91a670a4 | 51 | 'skip': 'No longer exists', |
3b01a9fb YCH |
52 | }] |
53 | ||
91a670a4 | 54 | def _extract_playlist(self, playlist_data, content_type): |
3b01a9fb YCH |
55 | all_episodes = [ |
56 | self.url_result(smuggle_url( | |
91a670a4 | 57 | self._URL_TEMPLATE % (content_type, episode['contentId']), |
3b01a9fb | 58 | {'force_noplaylist': True})) # To prevent infinite recursion |
91a670a4 | 59 | for episode in traverse_obj(playlist_data, ('seasons', ..., 'episode', lambda _, v: v['contentId']))] |
3b01a9fb | 60 | |
91a670a4 | 61 | return self.playlist_result(all_episodes, playlist_data['contentId'], playlist_data.get('title')) |
3b01a9fb YCH |
62 | |
63 | def _real_extract(self, url): | |
88f23a18 | 64 | url, smuggled_data = unsmuggle_url(url, {}) |
3b01a9fb YCH |
65 | |
66 | video_id = self._match_id(url) | |
67 | ||
3b01a9fb YCH |
68 | webpage = self._download_webpage(url, video_id) |
69 | ||
91a670a4 | 70 | if self._search_regex( |
71 | r'(?i)<meta\s[^>]*http-equiv="refresh"\s[^>]*content="[0-9]+;\s*url=https://www\.litv\.tv/"', | |
72 | webpage, 'meta refresh redirect', default=False, group=0): | |
73 | raise ExtractorError('No such content found', expected=True) | |
74 | ||
9dde0e04 | 75 | program_info = self._parse_json(self._search_regex( |
ec85ded8 | 76 | r'var\s+programInfo\s*=\s*([^;]+)', webpage, 'VOD data', default='{}'), |
3b01a9fb YCH |
77 | video_id) |
78 | ||
91a670a4 | 79 | # In browsers `getProgramInfo` request is always issued. Usually this |
3b01a9fb | 80 | # endpoint gives the same result as the data embedded in the webpage. |
91a670a4 | 81 | # If, for some reason, there are no embedded data, we do an extra request. |
9dde0e04 YCH |
82 | if 'assetId' not in program_info: |
83 | program_info = self._download_json( | |
39e1c4f0 YCH |
84 | 'https://www.litv.tv/vod/ajax/getProgramInfo', video_id, |
85 | query={'contentId': video_id}, | |
86 | headers={'Accept': 'application/json'}) | |
91a670a4 | 87 | |
88 | series_id = program_info['seriesId'] | |
89 | if self._yes_playlist(series_id, video_id, smuggled_data): | |
90 | playlist_data = self._download_json( | |
91 | 'https://www.litv.tv/vod/ajax/getSeriesTree', video_id, | |
92 | query={'seriesId': series_id}, headers={'Accept': 'application/json'}) | |
93 | return self._extract_playlist(playlist_data, program_info['contentType']) | |
94 | ||
3b01a9fb YCH |
95 | video_data = self._parse_json(self._search_regex( |
96 | r'uiHlsUrl\s*=\s*testBackendData\(([^;]+)\);', | |
97 | webpage, 'video data', default='{}'), video_id) | |
98 | if not video_data: | |
99 | payload = { | |
9dde0e04 YCH |
100 | 'assetId': program_info['assetId'], |
101 | 'watchDevices': program_info['watchDevices'], | |
102 | 'contentType': program_info['contentType'], | |
3b01a9fb YCH |
103 | } |
104 | video_data = self._download_json( | |
91a670a4 | 105 | 'https://www.litv.tv/vod/ajax/getMainUrlNoAuth', video_id, |
3b01a9fb YCH |
106 | data=json.dumps(payload).encode('utf-8'), |
107 | headers={'Content-Type': 'application/json'}) | |
108 | ||
109 | if not video_data.get('fullpath'): | |
110 | error_msg = video_data.get('errorMessage') | |
111 | if error_msg == 'vod.error.outsideregionerror': | |
112 | self.raise_geo_restricted('This video is available in Taiwan only') | |
113 | if error_msg: | |
114 | raise ExtractorError('%s said: %s' % (self.IE_NAME, error_msg), expected=True) | |
115 | raise ExtractorError('Unexpected result from %s' % self.IE_NAME) | |
116 | ||
117 | formats = self._extract_m3u8_formats( | |
39e1c4f0 YCH |
118 | video_data['fullpath'], video_id, ext='mp4', |
119 | entry_protocol='m3u8_native', m3u8_id='hls') | |
3b01a9fb YCH |
120 | for a_format in formats: |
121 | # LiTV HLS segments doesn't like compressions | |
955c8958 | 122 | a_format.setdefault('http_headers', {})['Accept-Encoding'] = 'identity' |
3b01a9fb | 123 | |
9dde0e04 YCH |
124 | title = program_info['title'] + program_info.get('secondaryMark', '') |
125 | description = program_info.get('description') | |
126 | thumbnail = program_info.get('imageFile') | |
127 | categories = [item['name'] for item in program_info.get('category', [])] | |
128 | episode = int_or_none(program_info.get('episode')) | |
3b01a9fb YCH |
129 | |
130 | return { | |
131 | 'id': video_id, | |
132 | 'formats': formats, | |
133 | 'title': title, | |
134 | 'description': description, | |
135 | 'thumbnail': thumbnail, | |
136 | 'categories': categories, | |
137 | 'episode_number': episode, | |
138 | } |