]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/instagram.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from ..utils
import int_or_none
9 class InstagramIE(InfoExtractor
):
10 _VALID_URL
= r
'https?://instagram\.com/p/(?P<id>[\da-zA-Z]+)'
12 'url': 'http://instagram.com/p/aye83DjauH/?foo=bar#abc',
13 'md5': '0d2da106a9d2631273e192b372806516',
17 'uploader_id': 'naomipq',
18 'title': 'Video by naomipq',
19 'description': 'md5:1f17f0ab29bd6fe2bfad705f58de3cb8',
23 def _real_extract(self
, url
):
24 video_id
= self
._match
_id
(url
)
26 webpage
= self
._download
_webpage
(url
, video_id
)
27 uploader_id
= self
._search
_regex
(r
'"owner":{"username":"(.+?)"',
28 webpage
, 'uploader id', fatal
=False)
29 desc
= self
._search
_regex
(r
'"caption":"(.*?)"', webpage
, 'description',
34 'url': self
._og
_search
_video
_url
(webpage
, secure
=False),
36 'title': 'Video by %s' % uploader_id
,
37 'thumbnail': self
._og
_search
_thumbnail
(webpage
),
38 'uploader_id': uploader_id
,
43 class InstagramUserIE(InfoExtractor
):
44 _VALID_URL
= r
'http://instagram\.com/(?P<username>[^/]{2,})/?(?:$|[?#])'
45 IE_DESC
= 'Instagram user profile'
46 IE_NAME
= 'instagram:user'
48 'url': 'http://instagram.com/porsche',
53 'playlist_mincount': 2,
56 'id': '614605558512799803_462752227',
58 'title': '#Porsche Intelligent Performance.',
59 'thumbnail': 're:^https?://.*\.jpg',
60 'uploader': 'Porsche',
61 'uploader_id': 'porsche',
62 'timestamp': 1387486713,
63 'upload_date': '20131219',
68 'skip_download': True,
72 def _real_extract(self
, url
):
73 mobj
= re
.match(self
._VALID
_URL
, url
)
74 uploader_id
= mobj
.group('username')
78 media_url
= 'http://instagram.com/%s/media' % uploader_id
80 page
= self
._download
_json
(
81 media_url
, uploader_id
,
82 note
='Downloading page %d ' % (page_count
+ 1),
86 for it
in page
['items']:
87 if it
.get('type') != 'video':
89 like_count
= int_or_none(it
.get('likes', {}).get('count'))
90 user
= it
.get('user', {})
94 'height': v
.get('height'),
95 'width': v
.get('width'),
97 } for k
, v
in it
['videos'].items()]
98 self
._sort
_formats
(formats
)
100 thumbnails_el
= it
.get('images', {})
101 thumbnail
= thumbnails_el
.get('thumbnail', {}).get('url')
103 title
= it
.get('caption', {}).get('text', it
['id'])
109 'thumbnail': thumbnail
,
110 'webpage_url': it
.get('link'),
111 'uploader': user
.get('full_name'),
112 'uploader_id': user
.get('username'),
113 'like_count': like_count
,
114 'timestamp': int_or_none(it
.get('created_time')),
117 if not page
['items']:
119 max_id
= page
['items'][-1]['id']
121 'http://instagram.com/%s/media?max_id=%s' % (
122 uploader_id
, max_id
))
128 'title': uploader_id
,