1 from .common
import InfoExtractor
11 class CoubIE(InfoExtractor
):
12 _VALID_URL
= r
'(?:coub:|https?://(?:coub\.com/(?:view|embed|coubs)/|c-cdn\.coub\.com/fb-player\.swf\?.*\bcoub(?:ID|id)=))(?P<id>[\da-z]+)'
15 'url': 'http://coub.com/view/5u5n1',
19 'title': 'The Matrix Moonwalk',
20 'thumbnail': r
're:^https?://.*\.jpg$',
22 'timestamp': 1428527772,
23 'upload_date': '20150408',
24 'uploader': 'Artyom Loskutnikov',
25 'uploader_id': 'artyom.loskutnikov',
32 'url': 'http://c-cdn.coub.com/fb-player.swf?bot_type=vk&coubID=7w5a4',
33 'only_matching': True,
36 'only_matching': True,
39 'url': 'http://coub.com/view/237d5l5h',
40 'only_matching': True,
43 def _real_extract(self
, url
):
44 video_id
= self
._match
_id
(url
)
46 coub
= self
._download
_json
(
47 f
'http://coub.com/api/v2/coubs/{video_id}.json', video_id
)
51 '{} said: {}'.format(self
.IE_NAME
, coub
['error']), expected
=True)
55 file_versions
= coub
['file_versions']
57 QUALITIES
= ('low', 'med', 'high', 'higher')
63 SOURCE_PREFERENCE
= (MOBILE
, IPHONE
, HTML5
)
65 quality_key
= qualities(QUALITIES
)
66 preference_key
= qualities(SOURCE_PREFERENCE
)
70 for kind
, items
in file_versions
.get(HTML5
, {}).items():
71 if kind
not in ('video', 'audio'):
73 if not isinstance(items
, dict):
75 for quality
, item
in items
.items():
76 if not isinstance(item
, dict):
78 item_url
= item
.get('url')
83 'format_id': f
'{HTML5}-{kind}-{quality}',
84 'filesize': int_or_none(item
.get('size')),
85 'vcodec': 'none' if kind
== 'audio' else None,
86 'acodec': 'none' if kind
== 'video' else None,
87 'quality': quality_key(quality
),
88 'source_preference': preference_key(HTML5
),
91 iphone_url
= file_versions
.get(IPHONE
, {}).get('url')
96 'source_preference': preference_key(IPHONE
),
99 mobile_url
= file_versions
.get(MOBILE
, {}).get('audio_url')
103 'format_id': f
'{MOBILE}-audio',
104 'source_preference': preference_key(MOBILE
),
107 thumbnail
= coub
.get('picture')
108 duration
= float_or_none(coub
.get('duration'))
109 timestamp
= parse_iso8601(coub
.get('published_at') or coub
.get('created_at'))
110 uploader
= coub
.get('channel', {}).get('title')
111 uploader_id
= coub
.get('channel', {}).get('permalink')
113 view_count
= int_or_none(coub
.get('views_count') or coub
.get('views_increase_count'))
114 like_count
= int_or_none(coub
.get('likes_count'))
115 repost_count
= int_or_none(coub
.get('recoubs_count'))
117 age_restricted
= coub
.get('age_restricted', coub
.get('age_restricted_by_admin'))
118 if age_restricted
is not None:
119 age_limit
= 18 if age_restricted
is True else 0
126 'thumbnail': thumbnail
,
127 'duration': duration
,
128 'timestamp': timestamp
,
129 'uploader': uploader
,
130 'uploader_id': uploader_id
,
131 'view_count': view_count
,
132 'like_count': like_count
,
133 'repost_count': repost_count
,
134 'age_limit': age_limit
,