]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/instagram.py
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
  12 class InstagramIE(InfoExtractor
): 
  13     _VALID_URL 
= r
'https?://(?:www\.)?instagram\.com/p/(?P<id>[^/?#&]+)' 
  15         'url': 'https://instagram.com/p/aye83DjauH/?foo=bar#abc', 
  16         'md5': '0d2da106a9d2631273e192b372806516', 
  20             'uploader_id': 'naomipq', 
  21             'title': 'Video by naomipq', 
  22             'description': 'md5:1f17f0ab29bd6fe2bfad705f58de3cb8', 
  26         'url': 'https://www.instagram.com/p/BA-pQFBG8HZ/?taken-by=britneyspears', 
  30             'uploader_id': 'britneyspears', 
  31             'title': 'Video by britneyspears', 
  34             'skip_download': True, 
  37         'url': 'https://instagram.com/p/-Cmh1cukG2/', 
  38         'only_matching': True, 
  41     def _real_extract(self
, url
): 
  42         video_id 
= self
._match
_id
(url
) 
  44         webpage 
= self
._download
_webpage
(url
, video_id
) 
  45         uploader_id 
= self
._search
_regex
(r
'"owner":{"username":"(.+?)"', 
  46                                          webpage
, 'uploader id', fatal
=False) 
  47         desc 
= self
._search
_regex
( 
  48             r
'"caption":"(.+?)"', webpage
, 'description', default
=None) 
  52             'url': self
._og
_search
_video
_url
(webpage
, secure
=False), 
  54             'title': 'Video by %s' % uploader_id
, 
  55             'thumbnail': self
._og
_search
_thumbnail
(webpage
), 
  56             'uploader_id': uploader_id
, 
  61 class InstagramUserIE(InfoExtractor
): 
  62     _VALID_URL 
= r
'https?://(?:www\.)?instagram\.com/(?P<username>[^/]{2,})/?(?:$|[?#])' 
  63     IE_DESC 
= 'Instagram user profile' 
  64     IE_NAME 
= 'instagram:user' 
  66         'url': 'https://instagram.com/porsche', 
  71         'playlist_mincount': 2, 
  74                 'id': '614605558512799803_462752227', 
  76                 'title': '#Porsche Intelligent Performance.', 
  77                 'thumbnail': 're:^https?://.*\.jpg', 
  78                 'uploader': 'Porsche', 
  79                 'uploader_id': 'porsche', 
  80                 'timestamp': 1387486713, 
  81                 'upload_date': '20131219', 
  86             'skip_download': True, 
  90     def _real_extract(self
, url
): 
  91         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  92         uploader_id 
= mobj
.group('username') 
  96         media_url 
= 'http://instagram.com/%s/media' % uploader_id
 
  98             page 
= self
._download
_json
( 
  99                 media_url
, uploader_id
, 
 100                 note
='Downloading page %d ' % (page_count 
+ 1), 
 104             for it 
in page
['items']: 
 105                 if it
.get('type') != 'video': 
 107                 like_count 
= int_or_none(it
.get('likes', {}).get('count')) 
 108                 user 
= it
.get('user', {}) 
 112                     'height': v
.get('height'), 
 113                     'width': v
.get('width'), 
 115                 } for k
, v 
in it
['videos'].items()] 
 116                 self
._sort
_formats
(formats
) 
 118                 thumbnails_el 
= it
.get('images', {}) 
 119                 thumbnail 
= thumbnails_el
.get('thumbnail', {}).get('url') 
 121                 # In some cases caption is null, which corresponds to None 
 122                 # in python. As a result, it.get('caption', {}) gives None 
 123                 title 
= (it
.get('caption') or {}).get('text', it
['id']) 
 127                     'title': limit_length(title
, 80), 
 129                     'thumbnail': thumbnail
, 
 130                     'webpage_url': it
.get('link'), 
 131                     'uploader': user
.get('full_name'), 
 132                     'uploader_id': user
.get('username'), 
 133                     'like_count': like_count
, 
 134                     'timestamp': int_or_none(it
.get('created_time')), 
 137             if not page
['items']: 
 139             max_id 
= page
['items'][-1]['id'] 
 141                 'http://instagram.com/%s/media?max_id=%s' % ( 
 142                     uploader_id
, max_id
)) 
 148             'title': uploader_id
,