]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vine.py
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   7 from ..compat 
import compat_str
 
  15 class VineIE(InfoExtractor
): 
  16     _VALID_URL 
= r
'https?://(?:www\.)?vine\.co/(?:v|oembed)/(?P<id>\w+)' 
  18         'url': 'https://vine.co/v/b9KOOWX7HUx', 
  19         'md5': '2f36fed6235b16da96ce9b4dc890940d', 
  24             'alt_title': 'Vine by Jack', 
  25             'timestamp': 1368997951, 
  26             'upload_date': '20130519', 
  35         'url': 'https://vine.co/v/e192BnZnZ9V', 
  39             'title': 'ยิ้ม~ เขิน~ อาย~ น่าร้ากอ้ะ >//< @n_whitewo @orlameena #lovesicktheseries  #lovesickseason2', 
  40             'alt_title': 'Vine by Pimry_zaa', 
  41             'timestamp': 1436057405, 
  42             'upload_date': '20150705', 
  43             'uploader': 'Pimry_zaa', 
  44             'uploader_id': '1135760698325307392', 
  51             'skip_download': True, 
  54         'url': 'https://vine.co/v/MYxVapFvz2z', 
  55         'only_matching': True, 
  57         'url': 'https://vine.co/v/bxVjBbZlPUH', 
  58         'only_matching': True, 
  60         'url': 'https://vine.co/oembed/MYxVapFvz2z.json', 
  61         'only_matching': True, 
  64     def _real_extract(self
, url
): 
  65         video_id 
= self
._match
_id
(url
) 
  67         data 
= self
._download
_json
( 
  68             'https://archive.vine.co/posts/%s.json' % video_id
, video_id
) 
  71             for url_suffix 
in ('Url', 'URL'): 
  72                 format_url 
= data
.get('video%s%s' % (kind
, url_suffix
)) 
  77         for quality
, format_id 
in enumerate(('low', '', 'dash')): 
  78             format_url 
= video_url(format_id
.capitalize()) 
  81             # DASH link returns plain mp4 
  82             if format_id 
== 'dash' and determine_ext(format_url
) == 'mpd': 
  83                 formats
.extend(self
._extract
_mpd
_formats
( 
  84                     format_url
, video_id
, mpd_id
='dash', fatal
=False)) 
  88                     'format_id': format_id 
or 'standard', 
  91         self
._sort
_formats
(formats
) 
  93         username 
= data
.get('username') 
  95         alt_title 
= 'Vine by %s' % username 
if username 
else None 
  99             'title': data
.get('description') or alt_title 
or 'Vine video', 
 100             'alt_title': alt_title
, 
 101             'thumbnail': data
.get('thumbnailUrl'), 
 102             'timestamp': unified_timestamp(data
.get('created')), 
 103             'uploader': username
, 
 104             'uploader_id': data
.get('userIdStr'), 
 105             'view_count': int_or_none(data
.get('loops')), 
 106             'like_count': int_or_none(data
.get('likes')), 
 107             'comment_count': int_or_none(data
.get('comments')), 
 108             'repost_count': int_or_none(data
.get('reposts')), 
 113 class VineUserIE(InfoExtractor
): 
 114     IE_NAME 
= 'vine:user' 
 115     _VALID_URL 
= r
'https?://vine\.co/(?P<u>u/)?(?P<user>[^/]+)' 
 116     _VINE_BASE_URL 
= 'https://vine.co/' 
 118         'url': 'https://vine.co/itsruthb', 
 122             'description': '| Instagram/Twitter: itsruthb | still a lost boy from neverland', 
 124         'playlist_mincount': 611, 
 126         'url': 'https://vine.co/u/942914934646415360', 
 127         'only_matching': True, 
 131     def suitable(cls
, url
): 
 132         return False if VineIE
.suitable(url
) else super(VineUserIE
, cls
).suitable(url
) 
 134     def _real_extract(self
, url
): 
 135         mobj 
= re
.match(self
._VALID
_URL
, url
) 
 136         user 
= mobj
.group('user') 
 139         profile_url 
= '%sapi/users/profiles/%s%s' % ( 
 140             self
._VINE
_BASE
_URL
, 'vanity/' if not u 
else '', user
) 
 141         profile_data 
= self
._download
_json
( 
 142             profile_url
, user
, note
='Downloading user profile data') 
 144         data 
= profile_data
['data'] 
 145         user_id 
= data
.get('userId') or data
['userIdStr'] 
 146         profile 
= self
._download
_json
( 
 147             'https://archive.vine.co/profiles/%s.json' % user_id
, user_id
) 
 150                 'https://vine.co/v/%s' % post_id
, ie
='Vine', video_id
=post_id
) 
 151             for post_id 
in profile
['posts'] 
 152             if post_id 
and isinstance(post_id
, compat_str
)] 
 153         return self
.playlist_result( 
 154             entries
, user
, profile
.get('username'), profile
.get('description'))