[ie/soundcloud] Various fixes (#11820)
[yt-dlp.git] / yt_dlp / extractor / vine.py
blobeed4bfeeb9fcbe7bf9fba5f34964989dace966ed
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 format_field,
5 int_or_none,
6 unified_timestamp,
10 class VineIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?vine\.co/(?:v|oembed)/(?P<id>\w+)'
12 _EMBED_REGEX = [r'<iframe[^>]+src=[\'"](?P<url>(?:https?:)?//(?:www\.)?vine\.co/v/[^/]+/embed/(?:simple|postcard))']
13 _TESTS = [{
14 'url': 'https://vine.co/v/b9KOOWX7HUx',
15 'md5': '2f36fed6235b16da96ce9b4dc890940d',
16 'info_dict': {
17 'id': 'b9KOOWX7HUx',
18 'ext': 'mp4',
19 'title': 'Chicken.',
20 'alt_title': 'Vine by Jack',
21 'timestamp': 1368997951,
22 'upload_date': '20130519',
23 'uploader': 'Jack',
24 'uploader_id': '76',
25 'view_count': int,
26 'like_count': int,
27 'comment_count': int,
28 'repost_count': int,
30 }, {
31 'url': 'https://vine.co/v/e192BnZnZ9V',
32 'info_dict': {
33 'id': 'e192BnZnZ9V',
34 'ext': 'mp4',
35 'title': 'ยิ้ม~ เขิน~ อาย~ น่าร้ากอ้ะ >//< @n_whitewo @orlameena #lovesicktheseries #lovesickseason2',
36 'alt_title': 'Vine by Pimry_zaa',
37 'timestamp': 1436057405,
38 'upload_date': '20150705',
39 'uploader': 'Pimry_zaa',
40 'uploader_id': '1135760698325307392',
41 'view_count': int,
42 'like_count': int,
43 'comment_count': int,
44 'repost_count': int,
46 'params': {
47 'skip_download': True,
49 }, {
50 'url': 'https://vine.co/v/MYxVapFvz2z',
51 'only_matching': True,
52 }, {
53 'url': 'https://vine.co/v/bxVjBbZlPUH',
54 'only_matching': True,
55 }, {
56 'url': 'https://vine.co/oembed/MYxVapFvz2z.json',
57 'only_matching': True,
60 def _real_extract(self, url):
61 video_id = self._match_id(url)
63 data = self._download_json(
64 f'https://archive.vine.co/posts/{video_id}.json', video_id)
66 def video_url(kind):
67 for url_suffix in ('Url', 'URL'):
68 format_url = data.get(f'video{kind}{url_suffix}')
69 if format_url:
70 return format_url
72 formats = []
73 for quality, format_id in enumerate(('low', '', 'dash')):
74 format_url = video_url(format_id.capitalize())
75 if not format_url:
76 continue
77 # DASH link returns plain mp4
78 if format_id == 'dash' and determine_ext(format_url) == 'mpd':
79 formats.extend(self._extract_mpd_formats(
80 format_url, video_id, mpd_id='dash', fatal=False))
81 else:
82 formats.append({
83 'url': format_url,
84 'format_id': format_id or 'standard',
85 'quality': quality,
87 self._check_formats(formats, video_id)
89 username = data.get('username')
91 alt_title = format_field(username, None, 'Vine by %s')
93 return {
94 'id': video_id,
95 'title': data.get('description') or alt_title or 'Vine video',
96 'alt_title': alt_title,
97 'thumbnail': data.get('thumbnailUrl'),
98 'timestamp': unified_timestamp(data.get('created')),
99 'uploader': username,
100 'uploader_id': data.get('userIdStr'),
101 'view_count': int_or_none(data.get('loops')),
102 'like_count': int_or_none(data.get('likes')),
103 'comment_count': int_or_none(data.get('comments')),
104 'repost_count': int_or_none(data.get('reposts')),
105 'formats': formats,
109 class VineUserIE(InfoExtractor):
110 IE_NAME = 'vine:user'
111 _VALID_URL = r'https?://vine\.co/(?P<u>u/)?(?P<user>[^/]+)'
112 _VINE_BASE_URL = 'https://vine.co/'
113 _TESTS = [{
114 'url': 'https://vine.co/itsruthb',
115 'info_dict': {
116 'id': 'itsruthb',
117 'title': 'Ruth B',
118 'description': '| Instagram/Twitter: itsruthb | still a lost boy from neverland',
120 'playlist_mincount': 611,
121 }, {
122 'url': 'https://vine.co/u/942914934646415360',
123 'only_matching': True,
126 @classmethod
127 def suitable(cls, url):
128 return False if VineIE.suitable(url) else super().suitable(url)
130 def _real_extract(self, url):
131 mobj = self._match_valid_url(url)
132 user = mobj.group('user')
133 u = mobj.group('u')
135 profile_url = '{}api/users/profiles/{}{}'.format(
136 self._VINE_BASE_URL, 'vanity/' if not u else '', user)
137 profile_data = self._download_json(
138 profile_url, user, note='Downloading user profile data')
140 data = profile_data['data']
141 user_id = data.get('userId') or data['userIdStr']
142 profile = self._download_json(
143 f'https://archive.vine.co/profiles/{user_id}.json', user_id)
144 entries = [
145 self.url_result(
146 f'https://vine.co/v/{post_id}', ie='Vine', video_id=post_id)
147 for post_id in profile['posts']
148 if post_id and isinstance(post_id, str)]
149 return self.playlist_result(
150 entries, user, profile.get('username'), profile.get('description'))