]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/kakao.py
   3 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
   6 from ..compat 
import compat_str
 
  14 class KakaoIE(InfoExtractor
): 
  15     _VALID_URL 
= r
'https?://tv\.kakao\.com/channel/(?P<channel>\d+)/cliplink/(?P<id>\d+)' 
  16     _API_BASE 
= 'http://tv.kakao.com/api/v1/ft/cliplinks' 
  19         'url': 'http://tv.kakao.com/channel/2671005/cliplink/301965083', 
  20         'md5': '702b2fbdeb51ad82f5c904e8c0766340', 
  24             'title': '乃木坂46 バナナマン 「3期生紹介コーナーが始動!顔高低差GPも!」 『乃木坂工事中』', 
  25             'uploader_id': 2671005, 
  27             'timestamp': 1488160199, 
  28             'upload_date': '20170227', 
  31         'url': 'http://tv.kakao.com/channel/2653210/cliplink/300103180', 
  32         'md5': 'a8917742069a4dd442516b86e7d66529', 
  36             'description': '러블리즈 - Destiny (나의 지구) (Lovelyz - Destiny)\r\n\r\n[쇼! 음악중심] 20160611, 507회', 
  37             'title': '러블리즈 - Destiny (나의 지구) (Lovelyz - Destiny)', 
  38             'uploader_id': 2653210, 
  40             'timestamp': 1485684628, 
  41             'upload_date': '20170129', 
  45     def _real_extract(self
, url
): 
  46         video_id 
= self
._match
_id
(url
) 
  49             'Referer': update_url_query( 
  50                 'http://tv.kakao.com/embed/player/cliplink/%s' % video_id
, { 
  51                     'service': 'kakao_tv', 
  54                     'wmode': 'transparent', 
  59             'player': 'monet_html5', 
  62             'service': 'kakao_tv', 
  67         query 
= QUERY_COMMON
.copy() 
  68         query
['fields'] = 'clipLink,clip,channel,hasPlusFriend,-service,-tagList' 
  69         impress 
= self
._download
_json
( 
  70             '%s/%s/impress' % (self
._API
_BASE
, video_id
), 
  71             video_id
, 'Downloading video info', 
  72             query
=query
, headers
=player_header
) 
  74         clip_link 
= impress
['clipLink'] 
  75         clip 
= clip_link
['clip'] 
  77         title 
= clip
.get('title') or clip_link
.get('displayTitle') 
  79         tid 
= impress
.get('tid', '') 
  81         query 
= QUERY_COMMON
.copy() 
  86         raw 
= self
._download
_json
( 
  87             '%s/%s/raw' % (self
._API
_BASE
, video_id
), 
  88             video_id
, 'Downloading video formats info', 
  89             query
=query
, headers
=player_header
) 
  92         for fmt 
in raw
.get('outputList', []): 
  94                 profile_name 
= fmt
['profile'] 
  95                 fmt_url_json 
= self
._download
_json
( 
  96                     '%s/%s/raw/videolocation' % (self
._API
_BASE
, video_id
), 
  98                     'Downloading video URL for profile %s' % profile_name
, 
 100                         'service': 'kakao_tv', 
 103                         'profile': profile_name
 
 104                     }, headers
=player_header
, fatal
=False) 
 106                 if fmt_url_json 
is None: 
 109                 fmt_url 
= fmt_url_json
['url'] 
 112                     'format_id': profile_name
, 
 113                     'width': int_or_none(fmt
.get('width')), 
 114                     'height': int_or_none(fmt
.get('height')), 
 115                     'format_note': fmt
.get('label'), 
 116                     'filesize': int_or_none(fmt
.get('filesize')) 
 120         self
._sort
_formats
(formats
) 
 123         for thumb 
in clip
.get('clipChapterThumbnailList', []): 
 125                 'url': thumb
.get('thumbnailUrl'), 
 126                 'id': compat_str(thumb
.get('timeInSec')), 
 127                 'preference': -1 if thumb
.get('isDefault') else 0 
 129         top_thumbnail 
= clip
.get('thumbnailUrl') 
 132                 'url': top_thumbnail
, 
 139             'description': clip
.get('description'), 
 140             'uploader': clip_link
.get('channel', {}).get('name'), 
 141             'uploader_id': clip_link
.get('channelId'), 
 142             'thumbnails': thumbs
, 
 143             'timestamp': unified_timestamp(clip_link
.get('createTime')), 
 144             'duration': int_or_none(clip
.get('duration')), 
 145             'view_count': int_or_none(clip
.get('playCount')), 
 146             'like_count': int_or_none(clip
.get('likeCount')), 
 147             'comment_count': int_or_none(clip
.get('commentCount')),