]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/instagram.py
3d78f78c46d1ad004339bc33ebcb09d1286e5092
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
12 class InstagramIE(InfoExtractor
):
13 _VALID_URL
= r
'https://instagram\.com/p/(?P<id>[\da-zA-Z]+)'
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 def _real_extract(self
, url
):
27 video_id
= self
._match
_id
(url
)
29 webpage
= self
._download
_webpage
(url
, video_id
)
30 uploader_id
= self
._search
_regex
(r
'"owner":{"username":"(.+?)"',
31 webpage
, 'uploader id', fatal
=False)
32 desc
= self
._search
_regex
(r
'"caption":"(.*?)"', webpage
, 'description',
37 'url': self
._og
_search
_video
_url
(webpage
, secure
=False),
39 'title': 'Video by %s' % uploader_id
,
40 'thumbnail': self
._og
_search
_thumbnail
(webpage
),
41 'uploader_id': uploader_id
,
46 class InstagramUserIE(InfoExtractor
):
47 _VALID_URL
= r
'https://instagram\.com/(?P<username>[^/]{2,})/?(?:$|[?#])'
48 IE_DESC
= 'Instagram user profile'
49 IE_NAME
= 'instagram:user'
51 'url': 'https://instagram.com/porsche',
56 'playlist_mincount': 2,
59 'id': '614605558512799803_462752227',
61 'title': '#Porsche Intelligent Performance.',
62 'thumbnail': 're:^https?://.*\.jpg',
63 'uploader': 'Porsche',
64 'uploader_id': 'porsche',
65 'timestamp': 1387486713,
66 'upload_date': '20131219',
71 'skip_download': True,
75 def _real_extract(self
, url
):
76 mobj
= re
.match(self
._VALID
_URL
, url
)
77 uploader_id
= mobj
.group('username')
81 media_url
= 'http://instagram.com/%s/media' % uploader_id
83 page
= self
._download
_json
(
84 media_url
, uploader_id
,
85 note
='Downloading page %d ' % (page_count
+ 1),
89 for it
in page
['items']:
90 if it
.get('type') != 'video':
92 like_count
= int_or_none(it
.get('likes', {}).get('count'))
93 user
= it
.get('user', {})
97 'height': v
.get('height'),
98 'width': v
.get('width'),
100 } for k
, v
in it
['videos'].items()]
101 self
._sort
_formats
(formats
)
103 thumbnails_el
= it
.get('images', {})
104 thumbnail
= thumbnails_el
.get('thumbnail', {}).get('url')
106 # In some cases caption is null, which corresponds to None
107 # in python. As a result, it.get('caption', {}) gives None
108 title
= (it
.get('caption') or {}).get('text', it
['id'])
112 'title': limit_length(title
, 80),
114 'thumbnail': thumbnail
,
115 'webpage_url': it
.get('link'),
116 'uploader': user
.get('full_name'),
117 'uploader_id': user
.get('username'),
118 'like_count': like_count
,
119 'timestamp': int_or_none(it
.get('created_time')),
122 if not page
['items']:
124 max_id
= page
['items'][-1]['id']
126 'http://instagram.com/%s/media?max_id=%s' % (
127 uploader_id
, max_id
))
133 'title': uploader_id
,