]>
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',
25 'url': 'https://instagram.com/p/-Cmh1cukG2/',
26 'only_matching': True,
29 def _real_extract(self
, url
):
30 video_id
= self
._match
_id
(url
)
32 webpage
= self
._download
_webpage
(url
, video_id
)
33 uploader_id
= self
._search
_regex
(r
'"owner":{"username":"(.+?)"',
34 webpage
, 'uploader id', fatal
=False)
35 desc
= self
._search
_regex
(r
'"caption":"(.*?)"', webpage
, 'description',
40 'url': self
._og
_search
_video
_url
(webpage
, secure
=False),
42 'title': 'Video by %s' % uploader_id
,
43 'thumbnail': self
._og
_search
_thumbnail
(webpage
),
44 'uploader_id': uploader_id
,
49 class InstagramUserIE(InfoExtractor
):
50 _VALID_URL
= r
'https://instagram\.com/(?P<username>[^/]{2,})/?(?:$|[?#])'
51 IE_DESC
= 'Instagram user profile'
52 IE_NAME
= 'instagram:user'
54 'url': 'https://instagram.com/porsche',
59 'playlist_mincount': 2,
62 'id': '614605558512799803_462752227',
64 'title': '#Porsche Intelligent Performance.',
65 'thumbnail': 're:^https?://.*\.jpg',
66 'uploader': 'Porsche',
67 'uploader_id': 'porsche',
68 'timestamp': 1387486713,
69 'upload_date': '20131219',
74 'skip_download': True,
78 def _real_extract(self
, url
):
79 mobj
= re
.match(self
._VALID
_URL
, url
)
80 uploader_id
= mobj
.group('username')
84 media_url
= 'http://instagram.com/%s/media' % uploader_id
86 page
= self
._download
_json
(
87 media_url
, uploader_id
,
88 note
='Downloading page %d ' % (page_count
+ 1),
92 for it
in page
['items']:
93 if it
.get('type') != 'video':
95 like_count
= int_or_none(it
.get('likes', {}).get('count'))
96 user
= it
.get('user', {})
100 'height': v
.get('height'),
101 'width': v
.get('width'),
103 } for k
, v
in it
['videos'].items()]
104 self
._sort
_formats
(formats
)
106 thumbnails_el
= it
.get('images', {})
107 thumbnail
= thumbnails_el
.get('thumbnail', {}).get('url')
109 # In some cases caption is null, which corresponds to None
110 # in python. As a result, it.get('caption', {}) gives None
111 title
= (it
.get('caption') or {}).get('text', it
['id'])
115 'title': limit_length(title
, 80),
117 'thumbnail': thumbnail
,
118 'webpage_url': it
.get('link'),
119 'uploader': user
.get('full_name'),
120 'uploader_id': user
.get('username'),
121 'like_count': like_count
,
122 'timestamp': int_or_none(it
.get('created_time')),
125 if not page
['items']:
127 max_id
= page
['items'][-1]['id']
129 'http://instagram.com/%s/media?max_id=%s' % (
130 uploader_id
, max_id
))
136 'title': uploader_id
,