]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/vine.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / vine.py
CommitLineData
eb1634cb 1from .common import InfoExtractor
91816e8f 2from ..utils import (
f962790e 3 determine_ext,
e0ddbd02 4 format_field,
91816e8f 5 int_or_none,
f962790e 6 unified_timestamp,
91816e8f 7)
eb1634cb
PH
8
9
10class VineIE(InfoExtractor):
64f1aba8 11 _VALID_URL = r'https?://(?:www\.)?vine\.co/(?:v|oembed)/(?P<id>\w+)'
bfd973ec 12 _EMBED_REGEX = [r'<iframe[^>]+src=[\'"](?P<url>(?:https?:)?//(?:www\.)?vine\.co/v/[^/]+/embed/(?:simple|postcard))']
3359fb66 13 _TESTS = [{
5dc733f0
JMF
14 'url': 'https://vine.co/v/b9KOOWX7HUx',
15 'md5': '2f36fed6235b16da96ce9b4dc890940d',
16 'info_dict': {
17 'id': 'b9KOOWX7HUx',
18 'ext': 'mp4',
5dc733f0 19 'title': 'Chicken.',
f962790e
S
20 'alt_title': 'Vine by Jack',
21 'timestamp': 1368997951,
f919201e 22 'upload_date': '20130519',
f962790e 23 'uploader': 'Jack',
f919201e 24 'uploader_id': '76',
6ae938b2 25 'view_count': int,
2e022397
S
26 'like_count': int,
27 'comment_count': int,
28 'repost_count': int,
5dc733f0 29 },
94a773fe
LL
30 }, {
31 'url': 'https://vine.co/v/e192BnZnZ9V',
32 'info_dict': {
33 'id': 'e192BnZnZ9V',
34 'ext': 'mp4',
91816e8f 35 'title': 'ยิ้ม~ เขิน~ อาย~ น่าร้ากอ้ะ >//< @n_whitewo @orlameena #lovesicktheseries #lovesickseason2',
94a773fe 36 'alt_title': 'Vine by Pimry_zaa',
f962790e 37 'timestamp': 1436057405,
94a773fe
LL
38 'upload_date': '20150705',
39 'uploader': 'Pimry_zaa',
40 'uploader_id': '1135760698325307392',
6ae938b2 41 'view_count': int,
2e022397
S
42 'like_count': int,
43 'comment_count': int,
44 'repost_count': int,
94a773fe
LL
45 },
46 'params': {
47 'skip_download': True,
48 },
f962790e
S
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,
3359fb66 58 }]
eb1634cb
PH
59
60 def _real_extract(self, url):
63e0f295 61 video_id = self._match_id(url)
ac2d8f54 62
f962790e 63 data = self._download_json(
add96eb9 64 f'https://archive.vine.co/posts/{video_id}.json', video_id)
0049594e 65
f962790e
S
66 def video_url(kind):
67 for url_suffix in ('Url', 'URL'):
add96eb9 68 format_url = data.get(f'video{kind}{url_suffix}')
f962790e
S
69 if format_url:
70 return format_url
2684871b 71
f962790e
S
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,
86 })
8e6cc12c 87 self._check_formats(formats, video_id)
eb1634cb 88
91816e8f
S
89 username = data.get('username')
90
a70635b8 91 alt_title = format_field(username, None, 'Vine by %s')
e8f20ffa 92
5dc733f0
JMF
93 return {
94 'id': video_id,
e8f20ffa
YCH
95 'title': data.get('description') or alt_title or 'Vine video',
96 'alt_title': alt_title,
91816e8f 97 'thumbnail': data.get('thumbnailUrl'),
f962790e 98 'timestamp': unified_timestamp(data.get('created')),
91816e8f
S
99 'uploader': username,
100 'uploader_id': data.get('userIdStr'),
f962790e
S
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')),
f919201e 105 'formats': formats,
acd69589 106 }
ea783d01 107
a172b258 108
ea783d01
JN
109class VineUserIE(InfoExtractor):
110 IE_NAME = 'vine:user'
8e41c9ad 111 _VALID_URL = r'https?://vine\.co/(?P<u>u/)?(?P<user>[^/]+)'
611c1dd9 112 _VINE_BASE_URL = 'https://vine.co/'
8e41c9ad
S
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',
b128c9ed 119 },
8e41c9ad
S
120 'playlist_mincount': 611,
121 }, {
122 'url': 'https://vine.co/u/942914934646415360',
123 'only_matching': True,
124 }]
125
126 @classmethod
127 def suitable(cls, url):
add96eb9 128 return False if VineIE.suitable(url) else super().suitable(url)
ea783d01 129
a172b258 130 def _real_extract(self, url):
5ad28e7f 131 mobj = self._match_valid_url(url)
a172b258 132 user = mobj.group('user')
b128c9ed 133 u = mobj.group('u')
ea783d01 134
add96eb9 135 profile_url = '{}api/users/profiles/{}{}'.format(
b128c9ed 136 self._VINE_BASE_URL, 'vanity/' if not u else '', user)
a172b258
PH
137 profile_data = self._download_json(
138 profile_url, user, note='Downloading user profile data')
ea783d01 139
8e41c9ad
S
140 data = profile_data['data']
141 user_id = data.get('userId') or data['userIdStr']
142 profile = self._download_json(
add96eb9 143 f'https://archive.vine.co/profiles/{user_id}.json', user_id)
a172b258 144 entries = [
8e41c9ad 145 self.url_result(
add96eb9 146 f'https://vine.co/v/{post_id}', ie='Vine', video_id=post_id)
8e41c9ad 147 for post_id in profile['posts']
add96eb9 148 if post_id and isinstance(post_id, str)]
8e41c9ad
S
149 return self.playlist_result(
150 entries, user, profile.get('username'), profile.get('description'))