| 
									
										
										
										
											2014-01-31 14:19:22 +01:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-23 20:07:51 +02:00
										 |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2015-09-24 21:55:44 +01:00
										 |  |  | from ..utils import ( | 
					
						
							|  |  |  |     int_or_none, | 
					
						
							|  |  |  |     get_element_by_id, | 
					
						
							| 
									
										
										
										
											2015-09-25 04:44:52 +06:00
										 |  |  |     remove_end, | 
					
						
							| 
									
										
										
										
											2015-09-24 21:55:44 +01:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2013-06-23 20:07:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 14:19:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-04 16:52:10 +07:00
										 |  |  | class IconosquareIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2015-05-02 07:18:22 +06:00
										 |  |  |     _VALID_URL = r'https?://(?:www\.)?(?:iconosquare\.com|statigr\.am)/p/(?P<id>[^/]+)' | 
					
						
							| 
									
										
										
										
											2013-06-27 20:46:46 +02:00
										 |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2014-01-31 14:19:22 +01:00
										 |  |  |         'url': 'http://statigr.am/p/522207370455279102_24101272', | 
					
						
							|  |  |  |         'md5': '6eb93b882a3ded7c378ee1d6884b1814', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '522207370455279102_24101272', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							| 
									
										
										
										
											2015-09-25 04:44:52 +06:00
										 |  |  |             'title': 'Instagram photo by @aguynamedpatrick (Patrick Janelle)', | 
					
						
							| 
									
										
										
										
											2014-05-04 16:52:10 +07:00
										 |  |  |             'description': 'md5:644406a9ec27457ed7aa7a9ebcd4ce3d', | 
					
						
							| 
									
										
										
										
											2015-05-02 07:18:22 +06:00
										 |  |  |             'timestamp': 1376471991, | 
					
						
							|  |  |  |             'upload_date': '20130814', | 
					
						
							|  |  |  |             'uploader': 'aguynamedpatrick', | 
					
						
							|  |  |  |             'uploader_id': '24101272', | 
					
						
							|  |  |  |             'comment_count': int, | 
					
						
							|  |  |  |             'like_count': int, | 
					
						
							| 
									
										
										
										
											2013-08-21 19:20:27 +02:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2013-06-27 20:46:46 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-06-23 20:07:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2014-10-28 09:12:28 +01:00
										 |  |  |         video_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2015-05-02 07:18:22 +06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-23 20:07:51 +02:00
										 |  |  |         webpage = self._download_webpage(url, video_id) | 
					
						
							| 
									
										
										
										
											2015-05-02 07:18:22 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         media = self._parse_json( | 
					
						
							| 
									
										
										
										
											2015-09-24 21:55:44 +01:00
										 |  |  |             get_element_by_id('mediaJson', webpage), | 
					
						
							| 
									
										
										
										
											2015-05-02 07:18:22 +06:00
										 |  |  |             video_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         formats = [{ | 
					
						
							|  |  |  |             'url': f['url'], | 
					
						
							|  |  |  |             'format_id': format_id, | 
					
						
							|  |  |  |             'width': int_or_none(f.get('width')), | 
					
						
							|  |  |  |             'height': int_or_none(f.get('height')) | 
					
						
							|  |  |  |         } for format_id, f in media['videos'].items()] | 
					
						
							|  |  |  |         self._sort_formats(formats) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-25 04:44:52 +06:00
										 |  |  |         title = remove_end(self._og_search_title(webpage), ' - via Iconosquare') | 
					
						
							| 
									
										
										
										
											2015-05-02 07:18:22 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         timestamp = int_or_none(media.get('created_time') or media.get('caption', {}).get('created_time')) | 
					
						
							|  |  |  |         description = media.get('caption', {}).get('text') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         uploader = media.get('user', {}).get('username') | 
					
						
							|  |  |  |         uploader_id = media.get('user', {}).get('id') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         comment_count = int_or_none(media.get('comments', {}).get('count')) | 
					
						
							|  |  |  |         like_count = int_or_none(media.get('likes', {}).get('count')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         thumbnails = [{ | 
					
						
							|  |  |  |             'url': t['url'], | 
					
						
							|  |  |  |             'id': thumbnail_id, | 
					
						
							|  |  |  |             'width': int_or_none(t.get('width')), | 
					
						
							|  |  |  |             'height': int_or_none(t.get('height')) | 
					
						
							|  |  |  |         } for thumbnail_id, t in media.get('images', {}).items()] | 
					
						
							| 
									
										
										
										
											2013-06-23 20:07:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-25 04:45:31 +06:00
										 |  |  |         comments = [{ | 
					
						
							|  |  |  |             'id': comment.get('id'), | 
					
						
							|  |  |  |             'text': comment['text'], | 
					
						
							|  |  |  |             'timestamp': int_or_none(comment.get('created_time')), | 
					
						
							|  |  |  |             'author': comment.get('from', {}).get('full_name'), | 
					
						
							|  |  |  |             'author_id': comment.get('from', {}).get('username'), | 
					
						
							|  |  |  |         } for comment in media.get('comments', {}).get('data', []) if 'text' in comment] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 14:19:22 +01:00
										 |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							| 
									
										
										
										
											2015-05-02 07:18:22 +06:00
										 |  |  |             'description': description, | 
					
						
							|  |  |  |             'thumbnails': thumbnails, | 
					
						
							|  |  |  |             'timestamp': timestamp, | 
					
						
							|  |  |  |             'uploader': uploader, | 
					
						
							|  |  |  |             'uploader_id': uploader_id, | 
					
						
							|  |  |  |             'comment_count': comment_count, | 
					
						
							|  |  |  |             'like_count': like_count, | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							| 
									
										
										
										
											2015-09-25 04:45:31 +06:00
										 |  |  |             'comments': comments, | 
					
						
							| 
									
										
										
										
											2014-01-31 14:19:22 +01:00
										 |  |  |         } |