]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/coub.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
14 class CoubIE(InfoExtractor
):
15 _VALID_URL
= r
'(?:coub:|https?://(?:coub\.com/(?:view|embed|coubs)/|c-cdn\.coub\.com/fb-player\.swf\?.*\bcoub(?:ID|id)=))(?P<id>[\da-z]+)'
18 'url': 'http://coub.com/view/5u5n1',
22 'title': 'The Matrix Moonwalk',
23 'thumbnail': r
're:^https?://.*\.jpg$',
25 'timestamp': 1428527772,
26 'upload_date': '20150408',
27 'uploader': 'Artyom Loskutnikov',
28 'uploader_id': 'artyom.loskutnikov',
35 'url': 'http://c-cdn.coub.com/fb-player.swf?bot_type=vk&coubID=7w5a4',
36 'only_matching': True,
39 'only_matching': True,
42 'url': 'http://coub.com/view/237d5l5h',
43 'only_matching': True,
46 def _real_extract(self
, url
):
47 video_id
= self
._match
_id
(url
)
49 coub
= self
._download
_json
(
50 'http://coub.com/api/v2/coubs/%s.json' % video_id
, video_id
)
54 '%s said: %s' % (self
.IE_NAME
, coub
['error']), expected
=True)
58 file_versions
= coub
['file_versions']
60 QUALITIES
= ('low', 'med', 'high', 'higher')
66 SOURCE_PREFERENCE
= (MOBILE
, IPHONE
, HTML5
)
68 quality_key
= qualities(QUALITIES
)
69 preference_key
= qualities(SOURCE_PREFERENCE
)
73 for kind
, items
in file_versions
.get(HTML5
, {}).items():
74 if kind
not in ('video', 'audio'):
76 if not isinstance(items
, dict):
78 for quality
, item
in items
.items():
79 if not isinstance(item
, dict):
81 item_url
= item
.get('url')
86 'format_id': '%s-%s-%s' % (HTML5
, kind
, quality
),
87 'filesize': int_or_none(item
.get('size')),
88 'vcodec': 'none' if kind
== 'audio' else None,
89 'acodec': 'none' if kind
== 'video' else None,
90 'quality': quality_key(quality
),
91 'source_preference': preference_key(HTML5
),
94 iphone_url
= file_versions
.get(IPHONE
, {}).get('url')
99 'source_preference': preference_key(IPHONE
),
102 mobile_url
= file_versions
.get(MOBILE
, {}).get('audio_url')
106 'format_id': '%s-audio' % MOBILE
,
107 'source_preference': preference_key(MOBILE
),
110 self
._sort
_formats
(formats
)
112 thumbnail
= coub
.get('picture')
113 duration
= float_or_none(coub
.get('duration'))
114 timestamp
= parse_iso8601(coub
.get('published_at') or coub
.get('created_at'))
115 uploader
= coub
.get('channel', {}).get('title')
116 uploader_id
= coub
.get('channel', {}).get('permalink')
118 view_count
= int_or_none(coub
.get('views_count') or coub
.get('views_increase_count'))
119 like_count
= int_or_none(coub
.get('likes_count'))
120 repost_count
= int_or_none(coub
.get('recoubs_count'))
122 age_restricted
= coub
.get('age_restricted', coub
.get('age_restricted_by_admin'))
123 if age_restricted
is not None:
124 age_limit
= 18 if age_restricted
is True else 0
131 'thumbnail': thumbnail
,
132 'duration': duration
,
133 'timestamp': timestamp
,
134 'uploader': uploader
,
135 'uploader_id': uploader_id
,
136 'view_count': view_count
,
137 'like_count': like_count
,
138 'repost_count': repost_count
,
139 'age_limit': age_limit
,