]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/instagram.py
b5372bf7a24e48a347127a1dc76c9dc672b32b64
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
11 class InstagramIE(InfoExtractor
):
12 _VALID_URL
= r
'http://instagram\.com/p/(?P<id>.*?)/'
14 'url': 'http://instagram.com/p/aye83DjauH/?foo=bar#abc',
15 'md5': '0d2da106a9d2631273e192b372806516',
19 'uploader_id': 'naomipq',
20 'title': 'Video by naomipq',
21 'description': 'md5:1f17f0ab29bd6fe2bfad705f58de3cb8',
25 def _real_extract(self
, url
):
26 mobj
= re
.match(self
._VALID
_URL
, url
)
27 video_id
= mobj
.group('id')
28 webpage
= self
._download
_webpage
(url
, video_id
)
29 uploader_id
= self
._search
_regex
(r
'"owner":{"username":"(.+?)"',
30 webpage
, 'uploader id', fatal
=False)
31 desc
= self
._search
_regex
(r
'"caption":"(.*?)"', webpage
, 'description',
36 'url': self
._og
_search
_video
_url
(webpage
, secure
=False),
38 'title': 'Video by %s' % uploader_id
,
39 'thumbnail': self
._og
_search
_thumbnail
(webpage
),
40 'uploader_id': uploader_id
,
45 class InstagramUserIE(InfoExtractor
):
46 _VALID_URL
= r
'http://instagram\.com/(?P<username>[^/]{2,})/?(?:$|[?#])'
47 IE_DESC
= 'Instagram user profile'
48 IE_NAME
= 'instagram:user'
50 def _real_extract(self
, url
):
51 mobj
= re
.match(self
._VALID
_URL
, url
)
52 uploader_id
= mobj
.group('username')
56 media_url
= 'http://instagram.com/%s/media' % uploader_id
58 page
= self
._download
_json
(
59 media_url
, uploader_id
,
60 note
='Downloading page %d ' % (page_count
+ 1),
64 for it
in page
['items']:
65 if it
.get('type') != 'video':
67 like_count
= int_or_none(it
.get('likes', {}).get('count'))
68 user
= it
.get('user', {})
72 'height': v
.get('height'),
73 'width': v
.get('width'),
75 } for k
, v
in it
['videos'].items()]
76 self
._sort
_formats
(formats
)
78 thumbnails_el
= it
.get('images', {})
79 thumbnail
= thumbnails_el
.get('thumbnail', {}).get('url')
81 title
= it
.get('caption', {}).get('text', it
['id'])
87 'thumbnail': thumbnail
,
88 'webpage_url': it
.get('link'),
89 'uploader': user
.get('full_name'),
90 'uploader_id': user
.get('username'),
91 'like_count': like_count
,
92 'timestamp': int_or_none(it
.get('created_time')),
97 max_id
= page
['items'][-1]['id']
99 'http://instagram.com/%s/media?max_id=%s' % (
100 uploader_id
, max_id
))
106 'title': uploader_id
,