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