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