Merge pull request #96 from blackjack4494/kakao-new-apis

[kakao] new apis
This commit is contained in:
Tom-Oliver Heidel 2020-09-13 12:47:12 +02:00 committed by GitHub
commit acd0a71894
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 23 deletions

View File

@ -8,13 +8,13 @@ from ..utils import (
int_or_none, int_or_none,
strip_or_none, strip_or_none,
unified_timestamp, unified_timestamp,
update_url_query,
) )
class KakaoIE(InfoExtractor): class KakaoIE(InfoExtractor):
_VALID_URL = r'https?://(?:play-)?tv\.kakao\.com/(?:channel/\d+|embed/player)/cliplink/(?P<id>\d+|[^?#&]+@my)' _VALID_URL = r'https?://(?:play-)?tv\.kakao\.com/(?:channel/\d+|embed/player)/cliplink/(?P<id>\d+|[^?#&]+@my)'
_API_BASE_TMPL = 'http://tv.kakao.com/api/v1/ft/cliplinks/%s/' _API_BASE_TMPL = 'http://tv.kakao.com/api/v1/ft/playmeta/cliplink/%s/'
_CDN_API = 'https://tv.kakao.com/katz/v1/ft/cliplink/%s/readyNplay?'
_TESTS = [{ _TESTS = [{
'url': 'http://tv.kakao.com/channel/2671005/cliplink/301965083', 'url': 'http://tv.kakao.com/channel/2671005/cliplink/301965083',
@ -45,18 +45,8 @@ class KakaoIE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
display_id = video_id.rstrip('@my')
api_base = self._API_BASE_TMPL % video_id api_base = self._API_BASE_TMPL % video_id
cdn_api_base = self._CDN_API % video_id
player_header = {
'Referer': update_url_query(
'http://tv.kakao.com/embed/player/cliplink/%s' % video_id, {
'service': 'kakao_tv',
'autoplay': '1',
'profile': 'HIGH',
'wmode': 'transparent',
})
}
query = { query = {
'player': 'monet_html5', 'player': 'monet_html5',
@ -73,17 +63,14 @@ class KakaoIE(InfoExtractor):
'videoOutputList', 'width', 'height', 'kbps', 'profile', 'label']) 'videoOutputList', 'width', 'height', 'kbps', 'profile', 'label'])
} }
impress = self._download_json( api_json = self._download_json(
api_base + 'impress', display_id, 'Downloading video info', api_base, video_id, 'Downloading video info')
query=query, headers=player_header)
clip_link = impress['clipLink'] clip_link = api_json['clipLink']
clip = clip_link['clip'] clip = clip_link['clip']
title = clip.get('title') or clip_link.get('displayTitle') title = clip.get('title') or clip_link.get('displayTitle')
query['tid'] = impress.get('tid', '')
formats = [] formats = []
for fmt in clip.get('videoOutputList', []): for fmt in clip.get('videoOutputList', []):
try: try:
@ -94,15 +81,17 @@ class KakaoIE(InfoExtractor):
'profile': profile_name, 'profile': profile_name,
'fields': '-*,url', 'fields': '-*,url',
}) })
fmt_url_json = self._download_json( fmt_url_json = self._download_json(
api_base + 'raw/videolocation', display_id, cdn_api_base, video_id,
'Downloading video URL for profile %s' % profile_name, 'Downloading video URL for profile %s' % profile_name,
query=query, headers=player_header, fatal=False) query=query, fatal=False)
if fmt_url_json is None: if fmt_url_json is None:
continue continue
fmt_url = fmt_url_json['url'] fmt_vidLocation = fmt_url_json['videoLocation']
fmt_url = fmt_vidLocation['url']
formats.append({ formats.append({
'url': fmt_url, 'url': fmt_url,
'format_id': profile_name, 'format_id': profile_name,
@ -131,7 +120,7 @@ class KakaoIE(InfoExtractor):
}) })
return { return {
'id': display_id, 'id': video_id,
'title': title, 'title': title,
'description': strip_or_none(clip.get('description')), 'description': strip_or_none(clip.get('description')),
'uploader': clip_link.get('channel', {}).get('name'), 'uploader': clip_link.get('channel', {}).get('name'),