]>
Commit | Line | Data |
---|---|---|
1d24da6c SS |
1 | import json |
2 | import urllib.parse | |
49bc16b9 | 3 | |
a2f9ca1e | 4 | from .common import InfoExtractor |
1d24da6c SS |
5 | from ..utils import ( |
6 | ExtractorError, | |
7 | make_archive_id, | |
8 | unified_timestamp, | |
9 | urljoin, | |
10 | ) | |
11 | from ..utils.traversal import traverse_obj | |
a2f9ca1e T |
12 | |
13 | ||
14 | class NintendoIE(InfoExtractor): | |
1d24da6c | 15 | _VALID_URL = r'https?://(?:www\.)?nintendo\.com/(?:(?P<locale>\w{2}(?:-\w{2})?)/)?nintendo-direct/(?P<slug>[^/?#]+)' |
a2f9ca1e | 16 | _TESTS = [{ |
1d24da6c | 17 | 'url': 'https://www.nintendo.com/nintendo-direct/09-04-2019/', |
a2f9ca1e | 18 | 'info_dict': { |
1d24da6c SS |
19 | 'ext': 'mp4', |
20 | 'id': '2oPmiviVePUA1IqAZzjuVh', | |
21 | 'display_id': '09-04-2019', | |
22 | 'title': 'Nintendo Direct 9.4.2019', | |
23 | 'timestamp': 1567580400, | |
24 | 'description': 'md5:8aac2780361d8cb772b6d1de66d7d6f4', | |
25 | 'upload_date': '20190904', | |
26 | 'age_limit': 17, | |
27 | '_old_archive_ids': ['nintendo J2bXdmaTE6fe3dWJTPcc7m23FNbc_A1V'], | |
a2f9ca1e | 28 | }, |
a2f9ca1e | 29 | }, { |
1d24da6c | 30 | 'url': 'https://www.nintendo.com/en-ca/nintendo-direct/08-31-2023/', |
a2f9ca1e | 31 | 'info_dict': { |
1d24da6c SS |
32 | 'ext': 'mp4', |
33 | 'id': '2TB2w2rJhNYF84qQ9E57hU', | |
34 | 'display_id': '08-31-2023', | |
35 | 'title': 'Super Mario Bros. Wonder Direct 8.31.2023', | |
36 | 'timestamp': 1693465200, | |
37 | 'description': 'md5:3067c5b824bcfdae9090a7f38ab2d200', | |
38 | 'tags': ['Mild Fantasy Violence', 'In-Game Purchases'], | |
39 | 'upload_date': '20230831', | |
40 | 'age_limit': 6, | |
a2f9ca1e | 41 | }, |
ddfe5019 | 42 | }, { |
1d24da6c | 43 | 'url': 'https://www.nintendo.com/us/nintendo-direct/50-fact-extravaganza/', |
ddfe5019 | 44 | 'info_dict': { |
ddfe5019 | 45 | 'ext': 'mp4', |
1d24da6c SS |
46 | 'id': 'j0BBGzfw0pQ', |
47 | 'channel_follower_count': int, | |
48 | 'view_count': int, | |
49 | 'description': 'Learn new details about Super Smash Bros. for Wii U, which launches on November 21.', | |
50 | 'duration': 2123, | |
51 | 'availability': 'public', | |
52 | 'thumbnail': 'https://i.ytimg.com/vi_webp/j0BBGzfw0pQ/maxresdefault.webp', | |
53 | 'timestamp': 1414047600, | |
54 | 'channel_id': 'UCGIY_O-8vW4rfX98KlMkvRg', | |
55 | 'chapters': 'count:53', | |
56 | 'heatmap': 'count:100', | |
57 | 'upload_date': '20141023', | |
58 | 'uploader_id': '@NintendoAmerica', | |
59 | 'playable_in_embed': True, | |
60 | 'categories': ['Gaming'], | |
61 | 'display_id': '50-fact-extravaganza', | |
62 | 'channel': 'Nintendo of America', | |
63 | 'tags': ['Comic Mischief', 'Cartoon Violence', 'Mild Suggestive Themes'], | |
64 | 'like_count': int, | |
65 | 'channel_url': 'https://www.youtube.com/channel/UCGIY_O-8vW4rfX98KlMkvRg', | |
66 | 'age_limit': 10, | |
67 | 'uploader_url': 'https://www.youtube.com/@NintendoAmerica', | |
68 | 'comment_count': int, | |
69 | 'live_status': 'not_live', | |
70 | 'uploader': 'Nintendo of America', | |
71 | 'title': '50-FACT Extravaganza', | |
ddfe5019 | 72 | }, |
a2f9ca1e T |
73 | }] |
74 | ||
1d24da6c SS |
75 | def _create_asset_url(self, path): |
76 | return urljoin('https://assets.nintendo.com/', urllib.parse.quote(path)) | |
77 | ||
a2f9ca1e | 78 | def _real_extract(self, url): |
1d24da6c SS |
79 | locale, slug = self._match_valid_url(url).group('locale', 'slug') |
80 | ||
81 | language, _, country = (locale or 'US').rpartition('-') | |
82 | parsed_locale = f'{language.lower() or "en"}_{country.upper()}' | |
83 | self.write_debug(f'Using locale {parsed_locale} (from {locale})', only_once=True) | |
84 | ||
85 | response = self._download_json('https://graph.nintendo.com/', slug, query={ | |
86 | 'operationName': 'NintendoDirect', | |
87 | 'variables': json.dumps({ | |
88 | 'locale': parsed_locale, | |
89 | 'slug': slug, | |
90 | }, separators=(',', ':')), | |
91 | 'extensions': json.dumps({ | |
92 | 'persistedQuery': { | |
93 | 'version': 1, | |
94 | 'sha256Hash': '969b16fe9f08b686fa37bc44d1fd913b6188e65794bb5e341c54fa683a8004cb' | |
95 | }, | |
96 | }, separators=(',', ':')), | |
97 | }) | |
98 | # API returns `{"data": {"direct": null}}` if no matching id | |
99 | direct_info = traverse_obj(response, ('data', 'direct', {dict})) | |
100 | if not direct_info: | |
101 | raise ExtractorError(f'No Nintendo Direct with id {slug} exists', expected=True) | |
102 | ||
103 | errors = ', '.join(traverse_obj(response, ('errors', ..., 'message'))) | |
104 | if errors: | |
105 | raise ExtractorError(f'GraphQL API error: {errors or "Unknown error"}') | |
106 | ||
107 | result = traverse_obj(direct_info, { | |
108 | 'id': ('id', {str}), | |
109 | 'title': ('name', {str}), | |
110 | 'timestamp': ('startDate', {unified_timestamp}), | |
111 | 'description': ('description', 'text', {str}), | |
112 | 'age_limit': ('contentRating', 'order', {int}), | |
113 | 'tags': ('contentDescriptors', ..., 'label', {str}), | |
114 | 'thumbnail': ('thumbnail', {self._create_asset_url}), | |
115 | }) | |
116 | result['display_id'] = slug | |
a2f9ca1e | 117 | |
1d24da6c SS |
118 | asset_id = traverse_obj(direct_info, ('video', 'publicId', {str})) |
119 | if not asset_id: | |
120 | youtube_id = traverse_obj(direct_info, ('liveStream', {str})) | |
121 | if not youtube_id: | |
122 | self.raise_no_formats('Could not find any video formats', video_id=slug) | |
a2f9ca1e | 123 | |
1d24da6c | 124 | return self.url_result(youtube_id, **result, url_transparent=True) |
ddfe5019 | 125 | |
1d24da6c SS |
126 | if asset_id.startswith('Legacy Videos/'): |
127 | result['_old_archive_ids'] = [make_archive_id(self, asset_id[14:])] | |
128 | result['formats'] = self._extract_m3u8_formats( | |
129 | self._create_asset_url(f'/video/upload/sp_full_hd/v1/{asset_id}.m3u8'), slug) | |
a2f9ca1e | 130 | |
1d24da6c | 131 | return result |