You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.9 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. int_or_none,
  5. get_element_by_id,
  6. remove_end,
  7. )
  8. class IconosquareIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?(?:iconosquare\.com|statigr\.am)/p/(?P<id>[^/]+)'
  10. _TEST = {
  11. 'url': 'http://statigr.am/p/522207370455279102_24101272',
  12. 'md5': '6eb93b882a3ded7c378ee1d6884b1814',
  13. 'info_dict': {
  14. 'id': '522207370455279102_24101272',
  15. 'ext': 'mp4',
  16. 'title': 'Instagram photo by @aguynamedpatrick (Patrick Janelle)',
  17. 'description': 'md5:644406a9ec27457ed7aa7a9ebcd4ce3d',
  18. 'timestamp': 1376471991,
  19. 'upload_date': '20130814',
  20. 'uploader': 'aguynamedpatrick',
  21. 'uploader_id': '24101272',
  22. 'comment_count': int,
  23. 'like_count': int,
  24. },
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(url, video_id)
  29. media = self._parse_json(
  30. get_element_by_id('mediaJson', webpage),
  31. video_id)
  32. formats = [{
  33. 'url': f['url'],
  34. 'format_id': format_id,
  35. 'width': int_or_none(f.get('width')),
  36. 'height': int_or_none(f.get('height'))
  37. } for format_id, f in media['videos'].items()]
  38. self._sort_formats(formats)
  39. title = remove_end(self._og_search_title(webpage), ' - via Iconosquare')
  40. timestamp = int_or_none(media.get('created_time') or media.get('caption', {}).get('created_time'))
  41. description = media.get('caption', {}).get('text')
  42. uploader = media.get('user', {}).get('username')
  43. uploader_id = media.get('user', {}).get('id')
  44. comment_count = int_or_none(media.get('comments', {}).get('count'))
  45. like_count = int_or_none(media.get('likes', {}).get('count'))
  46. thumbnails = [{
  47. 'url': t['url'],
  48. 'id': thumbnail_id,
  49. 'width': int_or_none(t.get('width')),
  50. 'height': int_or_none(t.get('height'))
  51. } for thumbnail_id, t in media.get('images', {}).items()]
  52. comments = [{
  53. 'id': comment.get('id'),
  54. 'text': comment['text'],
  55. 'timestamp': int_or_none(comment.get('created_time')),
  56. 'author': comment.get('from', {}).get('full_name'),
  57. 'author_id': comment.get('from', {}).get('username'),
  58. } for comment in media.get('comments', {}).get('data', []) if 'text' in comment]
  59. return {
  60. 'id': video_id,
  61. 'title': title,
  62. 'description': description,
  63. 'thumbnails': thumbnails,
  64. 'timestamp': timestamp,
  65. 'uploader': uploader,
  66. 'uploader_id': uploader_id,
  67. 'comment_count': comment_count,
  68. 'like_count': like_count,
  69. 'formats': formats,
  70. 'comments': comments,
  71. }