[instagram] fix uploader_id detection (Fixes #1038)
[youtube-dl] / youtube_dl / extractor / instagram.py
1 import re
2
3 from .common import InfoExtractor
4
5 class InstagramIE(InfoExtractor):
6     _VALID_URL = r'(?:http://)?instagram.com/p/(.*?)/'
7     _TEST = {
8         u'url': u'http://instagram.com/p/aye83DjauH/?foo=bar#abc',
9         u'file': u'aye83DjauH.mp4',
10         u'md5': u'0d2da106a9d2631273e192b372806516',
11         u'info_dict': {
12             u"uploader_id": u"naomipq", 
13             u"title": u"Video by naomipq"
14         }
15     }
16
17     def _real_extract(self, url):
18         mobj = re.match(self._VALID_URL, url)
19         video_id = mobj.group(1)
20         webpage = self._download_webpage(url, video_id)
21         html_title = self._html_search_regex(
22             r'<title>(.+?)</title>',
23             webpage, u'title', flags=re.DOTALL)
24         title = re.sub(u'(?: *\(Videos?\))? \u2022 Instagram$', '', html_title).strip()
25         uploader_id = self._html_search_regex(r'<div class="media-user" id="media_user"><h2><a href="[^"]*">([^<]*)</a></h2>',
26             webpage, u'uploader name', fatal=False)
27         ext = 'mp4'
28
29         return [{
30             'id':        video_id,
31             'url':       self._og_search_video_url(webpage),
32             'ext':       ext,
33             'title':     title,
34             'thumbnail': self._og_search_thumbnail(webpage),
35             'uploader_id' : uploader_id
36         }]