[vine:user] Improve extraction (closes #16190)

This commit is contained in:
Sergey M․ 2018-04-15 22:43:25 +07:00
parent 9b5aead6aa
commit 8e41c9ad01
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D
1 changed files with 26 additions and 19 deletions

View File

@ -4,6 +4,7 @@ from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_str
from ..utils import ( from ..utils import (
determine_ext, determine_ext,
int_or_none, int_or_none,
@ -111,21 +112,24 @@ class VineIE(InfoExtractor):
class VineUserIE(InfoExtractor): class VineUserIE(InfoExtractor):
IE_NAME = 'vine:user' IE_NAME = 'vine:user'
_VALID_URL = r'(?:https?://)?vine\.co/(?P<u>u/)?(?P<user>[^/]+)/?(\?.*)?$' _VALID_URL = r'https?://vine\.co/(?P<u>u/)?(?P<user>[^/]+)'
_VINE_BASE_URL = 'https://vine.co/' _VINE_BASE_URL = 'https://vine.co/'
_TESTS = [ _TESTS = [{
{ 'url': 'https://vine.co/itsruthb',
'url': 'https://vine.co/itsruthb', 'info_dict': {
'info_dict': { 'id': 'itsruthb',
'id': 'itsruthb', 'title': 'Ruth B',
}, 'description': '| Instagram/Twitter: itsruthb | still a lost boy from neverland',
'playlist_mincount': 611,
}, },
{ 'playlist_mincount': 611,
'url': 'https://vine.co/u/942914934646415360', }, {
'only_matching': True, 'url': 'https://vine.co/u/942914934646415360',
}, 'only_matching': True,
] }]
@classmethod
def suitable(cls, url):
return False if VineIE.suitable(url) else super(VineUserIE, cls).suitable(url)
def _real_extract(self, url): def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
@ -137,11 +141,14 @@ class VineUserIE(InfoExtractor):
profile_data = self._download_json( profile_data = self._download_json(
profile_url, user, note='Downloading user profile data') profile_url, user, note='Downloading user profile data')
user_id = profile_data['data']['userId'] data = profile_data['data']
user_archive = self._download_json( user_id = data.get('userId') or data['userIdStr']
profile = self._download_json(
'https://archive.vine.co/profiles/%s.json' % user_id, user_id) 'https://archive.vine.co/profiles/%s.json' % user_id, user_id)
posts = user_archive['posts']
entries = [ entries = [
self.url_result('https://vine.co/v/%s' % post_id, 'Vine') self.url_result(
for post_id in posts] 'https://vine.co/v/%s' % post_id, ie='Vine', video_id=post_id)
return self.playlist_result(entries, user) for post_id in profile['posts']
if post_id and isinstance(post_id, compat_str)]
return self.playlist_result(
entries, user, profile.get('username'), profile.get('description'))