logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

snapchat.py (3639B)


  1. from .common import InfoExtractor
  2. from ..utils import float_or_none, int_or_none, url_or_none
  3. from ..utils.traversal import traverse_obj
  4. class SnapchatSpotlightIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?snapchat\.com/spotlight/(?P<id>\w+)'
  6. _TESTS = [{
  7. 'url': 'https://www.snapchat.com/spotlight/W7_EDlXWTBiXAEEniNoMPwAAYYWtidGhudGZpAX1TKn0JAX1TKnXJAAAAAA',
  8. 'md5': '46c580f63592d0cbb76e974d2f9f0fcc',
  9. 'info_dict': {
  10. 'id': 'W7_EDlXWTBiXAEEniNoMPwAAYYWtidGhudGZpAX1TKn0JAX1TKnXJAAAAAA',
  11. 'ext': 'mp4',
  12. 'title': 'Views 💕',
  13. 'description': '',
  14. 'thumbnail': r're:https://cf-st\.sc-cdn\.net/d/kKJHIR1QAznRKK9jgYYDq\.256\.IRZXSOY',
  15. 'duration': 4.665,
  16. 'timestamp': 1637777831.369,
  17. 'upload_date': '20211124',
  18. 'repost_count': int,
  19. 'uploader': 'shreypatel57',
  20. 'uploader_url': 'https://www.snapchat.com/add/shreypatel57',
  21. },
  22. }, {
  23. 'url': 'https://www.snapchat.com/spotlight/W7_EDlXWTBiXAEEniNoMPwAAYcnVjYWdwcGV1AZEaIYn5AZEaIYnrAAAAAQ',
  24. 'md5': '4cd9626458c1a0e3e6dbe72c544a9ec2',
  25. 'info_dict': {
  26. 'id': 'W7_EDlXWTBiXAEEniNoMPwAAYcnVjYWdwcGV1AZEaIYn5AZEaIYnrAAAAAQ',
  27. 'ext': 'mp4',
  28. 'title': 'Spotlight Snap',
  29. 'description': 'How he flirt her teacher🤭🤭🤩😍 #kdrama#cdrama #dramaclips #dramaspotlight',
  30. 'thumbnail': r're:https://cf-st\.sc-cdn\.net/i/ztfr6xFs0FOcFhwVczWfj\.256\.IRZXSOY',
  31. 'duration': 10.91,
  32. 'timestamp': 1722720291.307,
  33. 'upload_date': '20240803',
  34. 'view_count': int,
  35. 'repost_count': int,
  36. 'uploader': 'ganda0535',
  37. 'uploader_url': 'https://www.snapchat.com/add/ganda0535',
  38. 'tags': ['#dramaspotlight', '#dramaclips', '#cdrama', '#kdrama'],
  39. },
  40. }]
  41. def _real_extract(self, url):
  42. video_id = self._match_id(url)
  43. webpage = self._download_webpage(url, video_id)
  44. page_props = self._search_nextjs_data(webpage, video_id)['props']['pageProps']
  45. video_data = traverse_obj(page_props, (
  46. 'spotlightFeed', 'spotlightStories',
  47. lambda _, v: v['story']['storyId']['value'] == video_id, 'metadata', any), None)
  48. return {
  49. 'id': video_id,
  50. 'ext': 'mp4',
  51. **traverse_obj(video_data, ('videoMetadata', {
  52. 'title': ('name', {str}),
  53. 'description': ('description', {str}),
  54. 'timestamp': ('uploadDateMs', {float_or_none(scale=1000)}),
  55. 'view_count': ('viewCount', {int_or_none}, {lambda x: None if x == -1 else x}),
  56. 'repost_count': ('shareCount', {int_or_none}),
  57. 'url': ('contentUrl', {url_or_none}),
  58. 'width': ('width', {int_or_none}),
  59. 'height': ('height', {int_or_none}),
  60. 'duration': ('durationMs', {float_or_none(scale=1000)}),
  61. 'thumbnail': ('thumbnailUrl', {url_or_none}),
  62. 'uploader': ('creator', 'personCreator', 'username', {str}),
  63. 'uploader_url': ('creator', 'personCreator', 'url', {url_or_none}),
  64. })),
  65. **traverse_obj(video_data, {
  66. 'description': ('description', {str}),
  67. 'tags': ('hashtags', ..., {str}),
  68. 'view_count': ('engagementStats', 'viewCount', {int_or_none}, {lambda x: None if x == -1 else x}),
  69. 'repost_count': ('engagementStats', 'shareCount', {int_or_none}),
  70. }),
  71. }