-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(Nintendo Music): add new settings options #10917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
petkovicdev
wants to merge
21
commits into
PreMiD:main
Choose a base branch
from
petkovicdev:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+81
−5
Open
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c09eba0
feat: add Nintendo Music presence
petkovicdev d71aed2
Merge branch 'main' into main
petkovicdev 3fb079e
fix: eslint errors
petkovicdev eabc91d
fix: removed sr language
petkovicdev 8494d0a
fix: removed unecessary comma
petkovicdev 016cd2e
fix: code formatted correctly, added at least 1 empty line at the end…
petkovicdev a5e3fa6
fix: final if-elseif-else code formatting
petkovicdev bcc5bfb
fix: removed one blank line at line 106
petkovicdev b0b663a
fix: changed the description to better describe the product.
petkovicdev ac6c1ba
Merge branch 'main' into main
petkovicdev 96bba2d
fix: address reviewer suggestions
petkovicdev 84fb4e9
Merge branch 'main' into main
petkovicdev 487f6e5
Added two new settings options
petkovicdev 04806cc
chore: resolved merge conflicts with main
petkovicdev c1e05bc
feat(Nintendo Music): resolved merge conflicts and updated settings l…
petkovicdev 4bbafa0
style: fix lint errors by changing strings to single quotes
petkovicdev 89a1102
fix: resolve undefined saveData reference typo
petkovicdev facbe1a
Merge branch 'main' into main
petkovicdev b6198ee
removed *.zip from .gitignore
petkovicdev 174ef25
bumped the version in metadata
petkovicdev 6f3a01d
bumped higher version
petkovicdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,3 +37,4 @@ pmd-results.sarif | |
|
|
||
| # Coverage files | ||
| coverage | ||
| *.zip | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| { | ||
| "$schema": "https://schemas.premid.app/metadata/1.16", | ||
| "apiVersion": 1, | ||
| "author": { | ||
| "name": "petkoslaw", | ||
| "id": "1465968325749117041" | ||
| }, | ||
| "service": "Nintendo Music", | ||
| "description": { | ||
| "de": "Mit Nintendo Music kannst du überall eine Vielzahl von Nintendo-Melodien hören.", | ||
| "en": "With Nintendo Music, you can listen to a variety of Nintendo tunes anywhere.", | ||
| "es": "Con Nintendo Music, puedes escuchar una gran variedad de melodías de Nintendo en cualquier lugar.", | ||
| "it": "Con Nintendo Music, puoi ascoltare una varietà di brani Nintendo ovunque.", | ||
| "nl": "Met Nintendo Music kun je overal naar een verscheidenheid aan Nintendo-melodieën luisteren.", | ||
| "ru": "С Nintendo Music ты можешь слушать разнообразные мелодии Nintendo где угодно." | ||
| }, | ||
| "url": "music.nintendo.com", | ||
| "regExp": "^https?[:][/][/]music[.]nintendo[.]com[/]", | ||
| "version": "1.1.0", | ||
| "logo": "https://i.imgur.com/thYBiff.png", | ||
| "thumbnail": "https://i.imgur.com/iZwfPeX.png", | ||
| "color": "#FC2C00", | ||
| "category": "music", | ||
| "tags": [ | ||
| "music", | ||
| "nintendo" | ||
| ], | ||
| "settings": [ | ||
| { | ||
| "id": "showTimestamps", | ||
| "title": "Show Timestamps", | ||
| "icon": "fas fa-clock", | ||
| "value": true, | ||
| "description": "Show the progress timestamps of a song." | ||
| }, | ||
| { | ||
| "id": "showSongArt", | ||
| "title": "Show Song Art", | ||
| "icon": "fas fa-image", | ||
| "value": true, | ||
| "description": "Show the song artwork as the large image." | ||
| }, | ||
| { | ||
| "id": "displayFormat", | ||
| "title": "Display Format", | ||
| "icon": "fas fa-paragraph", | ||
| "value": 0, | ||
| "values": ["Nintendo Music", "Song Name", "Soundtrack Name"] | ||
| }, | ||
| { | ||
| "id": "marioKartTrackOrigin", | ||
| "title": "Display Racetrack Console Origin", | ||
| "icon": "fas fa-font", | ||
| "value": false, | ||
| "description": "For Mario Kart soundtracks, show which console a racetrack originates from if they don't already." | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| import { ActivityType, StatusDisplayType } from 'premid' | ||
|
|
||
| const presence = new Presence({ | ||
| clientId: '1511505666664038460', | ||
| }) | ||
| const NintendoMusicLogo = 'https://i.imgur.com/thYBiff.png' | ||
|
|
||
| const TrackOriginList: Record<string, Record<string, string>> = { | ||
| "Mario Kart World": { | ||
| "Desert Hills": "DS Desert Hills", | ||
| "Shy Guy Bazaar": "3DS Shy Guy Bazaar", | ||
| "Wario Stadium": "N64 Wario Stadium", | ||
| "Airship Fortress": "DS Airship Fortress", | ||
| "DK Pass": "DS DK Pass", | ||
| "Sky-High Sundae": "SW Sky-High Sundae", | ||
| "Wario's Galleon": "3DS Wario's Galleon", | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| "Wario's Shipyard": "3DS Wario's Shipyard", | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| "Koopa Troopa Beach": "SNES Koopa Troopa Beach", | ||
| "Peach Beach": "GCN Peach Beach", | ||
| "Dino Dino Jungle": "GCN Dino Dino Jungle", | ||
| "Moo Moo Meadows": "Wii Moo Moo Meadows", | ||
| "Choco Mountain": "N64 Choco Mountain", | ||
| "Toad's Factory": "Wii Toad's Factory", | ||
| "Mario Circuit": "SNES Mario Circuit", | ||
| "Desert Hills (Intro)": "DS Desert Hills (Intro)", | ||
| "Shy Guy Bazaar (Intro)": "3DS Shy Guy Bazaar (Intro)", | ||
| "Wario Stadium (Intro)": "N64 Wario Stadium (Intro)", | ||
| "Airship Fortress (Intro)": "DS Airship Fortress (Intro)", | ||
| "DK Pass (Intro)": "DS DK Pass (Intro)", | ||
| "Sky-High Sundae (Intro)": "SW Sky-High Sundae (Intro)", | ||
| "Wario's Galleon (Intro)": "3DS Wario's Galleon (Intro)", | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| "Wario's Shipyard (Intro)": "3DS Wario's Shipyard (Intro)", | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| "Koopa Troopa Beach (Intro)": "SNES Koopa Troopa Beach (Intro)", | ||
| "Peach Beach (Intro)": "GCN Peach Beach (Intro)", | ||
| "Dino Dino Jungle (Intro)": "GCN Dino Dino Jungle (Intro)", | ||
| "Moo Moo Meadows (Intro)": "Wii Moo Moo Meadows (Intro)", | ||
| "Choco Mountain (Intro)": "N64 Choco Mountain (Intro)", | ||
| "Toad's Factory (Intro)": "Wii Toad's Factory (Intro)", | ||
| "Mario Circuit (Intro)": "SNES Mario Circuit (Intro)", | ||
| }, | ||
| } | ||
|
|
||
| presence.on('UpdateData', async () => { | ||
| const { pathname } = document.location | ||
| const title = document.title | ||
| const audio = document.querySelector('audio') | ||
| const isPlaying = !!document.querySelector('[aria-label="Pause"]') | ||
| const currentTime = audio?.currentTime || 0 | ||
| const duration = audio?.duration || 0 | ||
| const now = Math.floor(Date.now() / 1000) | ||
|
|
||
| const songArt = document.querySelector<HTMLImageElement>('[aria-label="Playback panel"] img')?.src || NintendoMusicLogo | ||
| const albumArt = document.querySelector<HTMLImageElement>('#main-column img')?.src || NintendoMusicLogo | ||
|
|
||
| const [showTimestamps, showSongArt, displayFormat, marioKartTrackOrigin] = await Promise.all([ | ||
| presence.getSetting<boolean>('showTimestamps'), | ||
| presence.getSetting<boolean>('showSongArt'), | ||
| presence.getSetting<number>('displayFormat'), | ||
| presence.getSetting<boolean>('marioKartTrackOrigin') | ||
| ]) | ||
|
|
||
| const presenceData: PresenceData = { | ||
| largeImageKey: NintendoMusicLogo, | ||
| type: ActivityType.Listening, | ||
| } | ||
|
|
||
| if (isPlaying && title.includes(' - Nintendo Music')) { | ||
| const parts = title.replace(' - Nintendo Music', '').trim().split(/[・·]/) | ||
| const songName = parts[0]?.trim() || 'Unknown' | ||
| const gameName = parts[1]?.trim() || 'Nintendo' | ||
|
|
||
| presenceData.details = songName | ||
| presenceData.state = gameName | ||
| presenceData.startTimestamp = now - Math.floor(currentTime) | ||
| presenceData.endTimestamp = now + Math.floor(duration - currentTime) | ||
|
|
||
| if (showSongArt) { | ||
| presenceData.largeImageKey = songArt | ||
| } | ||
| } | ||
| else if (pathname.includes('/search')) { | ||
| presenceData.details = 'Searching...' | ||
| presenceData.largeImageKey = NintendoMusicLogo | ||
| } | ||
| else if (pathname.includes('/game')) { | ||
| const parts = title.replace(' - Nintendo Music', '').trim().split(/[・·]/) | ||
| const gameName = parts[1]?.trim() || 'Nintendo' | ||
| const mainTitle = document.querySelector('#main-column h1')?.textContent | ||
|
|
||
| presenceData.details = `Browsing ${mainTitle}` | ||
| presenceData.state = gameName | ||
| presenceData.startTimestamp = now | ||
|
|
||
| if (showSongArt) { | ||
| presenceData.largeImageKey = albumArt | ||
| } | ||
| } | ||
| else if (pathname.includes('/user-playlist')) { | ||
| const parts = title.replace(' - Nintendo Music', '').trim().split(/[・·]/) | ||
| const songName = parts[0]?.trim() || 'Unknown' | ||
|
|
||
| presenceData.details = songName | ||
| presenceData.state = 'Personal Playlist' | ||
| presenceData.startTimestamp = now | ||
|
|
||
| if (showSongArt) { | ||
| presenceData.largeImageKey = albumArt | ||
| } | ||
| } | ||
| else if (pathname.includes('/playlist')) { | ||
| const parts = title.replace(' - Nintendo Music', '').trim().split(/[・·]/) | ||
| const songName = parts[0]?.trim() || 'Unknown' | ||
|
|
||
| presenceData.details = songName | ||
| presenceData.state = 'Official Playlist' | ||
| presenceData.startTimestamp = now | ||
|
|
||
| if (showSongArt) { | ||
| presenceData.largeImageKey = albumArt | ||
| } | ||
| } | ||
| else if (pathname.includes('/my-music')) { | ||
| const mainTitle = document.querySelector('#main-column h1')?.textContent | ||
|
|
||
| presenceData.details = mainTitle | ||
| presenceData.state = 'My Music' | ||
| presenceData.startTimestamp = now | ||
| } | ||
| else { | ||
| presenceData.details = 'Browsing Music...' | ||
| presenceData.startTimestamp = now | ||
| } | ||
|
|
||
| if (!showTimestamps) { | ||
| delete presenceData.startTimestamp | ||
| delete presenceData.endTimestamp | ||
| } | ||
|
|
||
| if (marioKartTrackOrigin) { | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| const soundtrackName = presenceData.state; | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| const songName = presenceData.details; | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| if (typeof soundtrackName == 'string' && typeof songName == 'string') { | ||
| const gameKey = soundtrackName as keyof typeof TrackOriginList; | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| const gameTrack = TrackOriginList[gameKey]; | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| if (gameTrack && (songName in gameTrack)) { | ||
| const mappedTrackValue = (gameTrack as Record<string, string>)[songName] | ||
| presenceData.details = mappedTrackValue; | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| } | ||
| } | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| } | ||
|
|
||
| switch(displayFormat) { | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| case 0: | ||
| presenceData.statusDisplayType = StatusDisplayType.Name | ||
| break; | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| case 1: | ||
| presenceData.statusDisplayType = StatusDisplayType.Details | ||
| break; | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| case 2: | ||
| presenceData.statusDisplayType = StatusDisplayType.State; | ||
| break; | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| } | ||
|
|
||
| if (presenceData.details) { | ||
| presence.setActivity(presenceData) | ||
| } | ||
| else { | ||
| presence.clearActivity() | ||
| } | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undo