Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ pmd-results.sarif

# Coverage files
coverage
*.zip

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo

58 changes: 58 additions & 0 deletions websites/N/Nintendo Music/metadata.json
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."
}
]
}
170 changes: 170 additions & 0 deletions websites/N/Nintendo Music/presence.ts
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",
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
"Wario's Shipyard": "3DS Wario's Shipyard",
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
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)",
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
"Wario's Shipyard (Intro)": "3DS Wario's Shipyard (Intro)",
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
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) {
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
const soundtrackName = presenceData.state;
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
const songName = presenceData.details;
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
if (typeof soundtrackName == 'string' && typeof songName == 'string') {
const gameKey = soundtrackName as keyof typeof TrackOriginList;
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
const gameTrack = TrackOriginList[gameKey];
Comment thread
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;
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
}
}
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
}

switch(displayFormat) {
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
case 0:
presenceData.statusDisplayType = StatusDisplayType.Name
break;
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
case 1:
presenceData.statusDisplayType = StatusDisplayType.Details
break;
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
case 2:
presenceData.statusDisplayType = StatusDisplayType.State;
break;
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
}

if (presenceData.details) {
presence.setActivity(presenceData)
}
else {
presence.clearActivity()
}
})
Loading