]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/litv.py
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
16 class LiTVIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://www\.litv\.tv/vod/[^/]+/content\.do\?.*?\bid=(?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',
34 'thumbnail': 're:https?://.*\.jpg$',
35 'description': 'md5:c7017aa144c87467c4fb2909c4b05d6f',
40 'skip_download': True, # m3u8 download
42 'skip': 'Georestricted to Taiwan',
45 def _extract_playlist(self
, season_list
, video_id
, vod_data
, view_data
, prompt
=True):
46 episode_title
= view_data
['title']
47 content_id
= season_list
['contentId']
50 self
.to_screen('Downloading playlist %s - add --no-playlist to just download video %s' % (content_id
, video_id
))
53 self
.url_result(smuggle_url(
54 self
._URL
_TEMPLATE
% (view_data
['contentType'], episode
['contentId']),
55 {'force_noplaylist': True})) # To prevent infinite recursion
56 for episode
in season_list
['episode']]
58 return self
.playlist_result(all_episodes
, content_id
, episode_title
)
60 def _real_extract(self
, url
):
61 url
, data
= unsmuggle_url(url
, {})
63 video_id
= self
._match
_id
(url
)
65 noplaylist
= self
._downloader
.params
.get('noplaylist')
66 noplaylist_prompt
= True
67 if 'force_noplaylist' in data
:
68 noplaylist
= data
['force_noplaylist']
69 noplaylist_prompt
= False
71 webpage
= self
._download
_webpage
(url
, video_id
)
73 view_data
= dict(map(lambda t
: (t
[0], t
[2]), re
.findall(
74 r
'viewData\.([a-zA-Z]+)\s*=\s*(["\'])([^
"\']+)\2',
77 vod_data = self._parse_json(self._search_regex(
78 'var\s+vod\s*=\s*([^;]+)', webpage, 'VOD data', default='{}'),
81 season_list = list(vod_data.get('seasonList', {}).values())
84 return self._extract_playlist(
85 season_list[0], video_id, vod_data, view_data,
86 prompt=noplaylist_prompt)
89 self.to_screen('Downloading just video %s because of --no-playlist' % video_id)
91 # In browsers `getMainUrl` request is always issued. Usually this
92 # endpoint gives the same result as the data embedded in the webpage.
93 # If georestricted, there are no embedded data, so an extra request is
94 # necessary to get the error code
95 video_data = self._parse_json(self._search_regex(
96 r'uiHlsUrl\s*=\s*testBackendData\(([^;]+)\);',
97 webpage, 'video data', default='{}'), video_id)
100 'assetId': view_data['assetId'],
101 'watchDevices': vod_data['watchDevices'],
102 'contentType': view_data['contentType'],
104 video_data = self._download_json(
105 'https://www.litv.tv/vod/getMainUrl', video_id,
106 data=json.dumps(payload).encode('utf-8'),
107 headers={'Content-Type': 'application/json'})
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')
114 raise ExtractorError('%s said: %s' % (self.IE_NAME, error_msg), expected=True)
115 raise ExtractorError('Unexpected result from %s' % self.IE_NAME)
117 formats = self._extract_m3u8_formats(
118 video_data['fullpath'], video_id, ext='mp4', m3u8_id='hls')
119 for a_format in formats:
120 # LiTV HLS segments doesn't like compressions
121 a_format.setdefault('http_headers', {})['Youtubedl-no-compression'] = True
123 title = view_data['title'] + view_data.get('secondaryMark', '')
124 description = view_data.get('description')
125 thumbnail = view_data.get('imageFile')
126 categories = [item['name'] for item in vod_data.get('category', [])]
127 episode = int_or_none(view_data.get('episode'))
133 'description': description,
134 'thumbnail': thumbnail,
135 'categories': categories,
136 'episode_number': episode,