[kanal2]: Revert "[kanal2]: avoid shadowing variables from outer scope"
This reverts commits 4dc705f6d and 4dc705f6d
This commit is contained in:
parent
9ee6cd55b2
commit
f3bc82bcb7
@ -42,81 +42,78 @@ class Kanal2IE(InfoExtractor):
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
def _real_extract(self, url_):
|
def _real_extract(self, url):
|
||||||
def get_title(info):
|
video_id = self._match_id(url)
|
||||||
title = info['title']
|
playlist = self.get_playlist(video_id)
|
||||||
|
|
||||||
if info['subtitle']:
|
# return a dict, description from here:
|
||||||
title += ' / ' + info['subtitle']
|
# https://github.com/rg3/youtube-dl/blob/7f41a598b3fba1bcab2817de64a08941200aa3c8/youtube_dl/extractor/common.py#L94-L303
|
||||||
|
info = {
|
||||||
|
'id': video_id,
|
||||||
|
'title': self.get_title(playlist['info']),
|
||||||
|
'description': playlist['info'].get('description'),
|
||||||
|
'webpage_url': playlist['data'].get('url'),
|
||||||
|
'thumbnail': playlist['data'].get('image'),
|
||||||
|
'formats': self.get_formats(playlist, video_id),
|
||||||
|
'timestamp': self.get_timestamp(playlist['info']['subtitle']),
|
||||||
|
}
|
||||||
|
|
||||||
return title
|
return info
|
||||||
|
|
||||||
def get_timestamp(subtitle):
|
def get_title(self, info):
|
||||||
# Extract timestamp from:
|
title = info['title']
|
||||||
# "subtitle": "Osa 53 (05.08.2016 20:00)",
|
|
||||||
match = self._search_regex(self.SUBTITLE_DATE_RE, subtitle, 'dateandtime', default=None)
|
|
||||||
if not match:
|
|
||||||
return None
|
|
||||||
|
|
||||||
# https://stackoverflow.com/a/27914405/2314626
|
if info['subtitle']:
|
||||||
date = datetime.strptime(match, '%d.%m.%Y %H:%M')
|
title += ' / ' + info['subtitle']
|
||||||
unixtime = time.mktime(date.timetuple())
|
|
||||||
|
|
||||||
return int(unixtime)
|
return title
|
||||||
|
|
||||||
def get_formats(playlist, video_id):
|
def get_timestamp(self, subtitle):
|
||||||
formats = []
|
# Extract timestamp from:
|
||||||
session = get_session(playlist['data']['path'], video_id)
|
# "subtitle": "Osa 53 (05.08.2016 20:00)",
|
||||||
sid = session.get('session')
|
match = self._search_regex(self.SUBTITLE_DATE_RE, subtitle, 'dateandtime', default=None)
|
||||||
for stream in playlist['data']['streams']:
|
if not match:
|
||||||
formats.append({
|
return None
|
||||||
'protocol': 'm3u8',
|
|
||||||
'ext': 'mp4',
|
|
||||||
'url': stream.get('file') + '&s=' + sid,
|
|
||||||
})
|
|
||||||
|
|
||||||
self._sort_formats(formats)
|
# https://stackoverflow.com/a/27914405/2314626
|
||||||
|
date = datetime.strptime(match, '%d.%m.%Y %H:%M')
|
||||||
|
unixtime = time.mktime(date.timetuple())
|
||||||
|
|
||||||
return formats
|
return int(unixtime)
|
||||||
|
|
||||||
def get_playlist(video_id):
|
def get_formats(self, playlist, video_id):
|
||||||
url = 'https://kanal2.postimees.ee/player/playlist/%(video_id)s?type=episodes' % {'video_id': video_id}
|
formats = []
|
||||||
headers = {
|
session = self.get_session(playlist['data']['path'], video_id)
|
||||||
'X-Requested-With': 'XMLHttpRequest',
|
sid = session.get('session')
|
||||||
}
|
for stream in playlist['data']['streams']:
|
||||||
|
formats.append({
|
||||||
|
'protocol': 'm3u8',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'url': stream.get('file') + '&s=' + sid,
|
||||||
|
})
|
||||||
|
|
||||||
return self._download_json(url, video_id, headers=headers)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
def get_session(path, video_id):
|
return formats
|
||||||
url = 'https://sts.postimees.ee/session/register'
|
|
||||||
headers = {
|
|
||||||
'X-Original-URI': path,
|
|
||||||
'Accept': 'application/json',
|
|
||||||
}
|
|
||||||
session = self._download_json(url, video_id, headers=headers,
|
|
||||||
note='Creating session',
|
|
||||||
errnote='Error creating session')
|
|
||||||
if session['reason'] != 'OK':
|
|
||||||
raise ExtractorError('%s: Unable to obtain session' % self.IE_NAME)
|
|
||||||
|
|
||||||
return session
|
def get_playlist(self, video_id):
|
||||||
|
url = 'https://kanal2.postimees.ee/player/playlist/%(video_id)s?type=episodes' % {'video_id': video_id}
|
||||||
|
headers = {
|
||||||
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
|
}
|
||||||
|
|
||||||
def extract_info(url):
|
return self._download_json(url, video_id, headers=headers)
|
||||||
video_id = self._match_id(url)
|
|
||||||
playlist = get_playlist(video_id)
|
|
||||||
|
|
||||||
# return a dict, description from here:
|
def get_session(self, path, video_id):
|
||||||
# https://github.com/rg3/youtube-dl/blob/7f41a598b3fba1bcab2817de64a08941200aa3c8/youtube_dl/extractor/common.py#L94-L303
|
url = 'https://sts.postimees.ee/session/register'
|
||||||
info = {
|
headers = {
|
||||||
'id': video_id,
|
'X-Original-URI': path,
|
||||||
'title': get_title(playlist['info']),
|
'Accept': 'application/json',
|
||||||
'description': playlist['info'].get('description'),
|
}
|
||||||
'webpage_url': playlist['data'].get('url'),
|
session = self._download_json(url, video_id, headers=headers,
|
||||||
'thumbnail': playlist['data'].get('image'),
|
note='Creating session',
|
||||||
'formats': get_formats(playlist, video_id),
|
errnote='Error creating session')
|
||||||
'timestamp': get_timestamp(playlist['info']['subtitle']),
|
if session['reason'] != 'OK':
|
||||||
}
|
raise ExtractorError('%s: Unable to obtain session' % self.IE_NAME)
|
||||||
|
|
||||||
return info
|
return session
|
||||||
|
|
||||||
return extract_info(url_)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user