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.

75 lines
2.6 KiB

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