Skip to content

Commit cf7226c

Browse files
authored
feat(Nintendo Music): add activity (#10852)
1 parent e7c3763 commit cf7226c

2 files changed

Lines changed: 152 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"$schema": "https://schemas.premid.app/metadata/1.16",
3+
"apiVersion": 1,
4+
"author": {
5+
"name": "petkoslaw",
6+
"id": "1465968325749117041"
7+
},
8+
"service": "Nintendo Music",
9+
"description": {
10+
"de": "Mit Nintendo Music kannst du überall eine Vielzahl von Nintendo-Melodien hören.",
11+
"en": "With Nintendo Music, you can listen to a variety of Nintendo tunes anywhere.",
12+
"es": "Con Nintendo Music, puedes escuchar una gran variedad de melodías de Nintendo en cualquier lugar.",
13+
"it": "Con Nintendo Music, puoi ascoltare una varietà di brani Nintendo ovunque.",
14+
"nl": "Met Nintendo Music kun je overal naar een verscheidenheid aan Nintendo-melodieën luisteren.",
15+
"ru": "С Nintendo Music ты можешь слушать разнообразные мелодии Nintendo где угодно."
16+
},
17+
"url": "music.nintendo.com",
18+
"regExp": "^https?[:][/][/]music[.]nintendo[.]com[/]",
19+
"version": "1.0.0",
20+
"logo": "https://i.imgur.com/thYBiff.png",
21+
"thumbnail": "https://i.imgur.com/iZwfPeX.png",
22+
"color": "#FC2C00",
23+
"category": "music",
24+
"tags": [
25+
"music",
26+
"nintendo"
27+
],
28+
"settings": [
29+
{
30+
"id": "showTimestamps",
31+
"title": "Show Timestamps",
32+
"icon": "fas fa-clock",
33+
"value": true,
34+
"description": "Show the progress timestamps of a song."
35+
},
36+
{
37+
"id": "showSongArt",
38+
"title": "Show Song Art",
39+
"icon": "fas fa-image",
40+
"value": true,
41+
"description": "Show the song artwork as the large image."
42+
}
43+
]
44+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { ActivityType } from 'premid'
2+
3+
const presence = new Presence({
4+
clientId: '1511505666664038460',
5+
})
6+
const NintendoMusicLogo = 'https://i.imgur.com/thYBiff.png'
7+
8+
presence.on('UpdateData', async () => {
9+
const { pathname } = document.location
10+
const title = document.title
11+
const audio = document.querySelector('audio')
12+
const isPlaying = !!document.querySelector('[aria-label="Pause"]')
13+
const currentTime = audio?.currentTime || 0
14+
const duration = audio?.duration || 0
15+
const now = Math.floor(Date.now() / 1000)
16+
17+
const songArt = document.querySelector<HTMLImageElement>('[aria-label="Playback panel"] img')?.src || NintendoMusicLogo
18+
const albumArt = document.querySelector<HTMLImageElement>('#main-column img')?.src || NintendoMusicLogo
19+
20+
const [showTimestamps, showSongArt] = await Promise.all([
21+
presence.getSetting<boolean>('showTimestamps'),
22+
presence.getSetting<boolean>('showSongArt'),
23+
])
24+
25+
const presenceData: PresenceData = {
26+
largeImageKey: NintendoMusicLogo,
27+
type: ActivityType.Listening,
28+
}
29+
30+
if (isPlaying && title.includes(' - Nintendo Music')) {
31+
const parts = title.replace(' - Nintendo Music', '').trim().split(/[·]/)
32+
const songName = parts[0]?.trim() || 'Unknown'
33+
const gameName = parts[1]?.trim() || 'Nintendo'
34+
35+
presenceData.details = songName
36+
presenceData.state = gameName
37+
presenceData.startTimestamp = now - Math.floor(currentTime)
38+
presenceData.endTimestamp = now + Math.floor(duration - currentTime)
39+
40+
if (showSongArt) {
41+
presenceData.largeImageKey = songArt
42+
}
43+
}
44+
else if (pathname.includes('/search')) {
45+
presenceData.details = 'Searching...'
46+
presenceData.largeImageKey = NintendoMusicLogo
47+
}
48+
else if (pathname.includes('/game')) {
49+
const parts = title.replace(' - Nintendo Music', '').trim().split(/[·]/)
50+
const gameName = parts[1]?.trim() || 'Nintendo'
51+
const mainTitle = document.querySelector('#main-column h1')?.textContent
52+
53+
presenceData.details = `Browsing ${mainTitle}`
54+
presenceData.state = gameName
55+
presenceData.startTimestamp = now
56+
57+
if (showSongArt) {
58+
presenceData.largeImageKey = albumArt
59+
}
60+
}
61+
else if (pathname.includes('/user-playlist')) {
62+
const parts = title.replace(' - Nintendo Music', '').trim().split(/[·]/)
63+
const songName = parts[0]?.trim() || 'Unknown'
64+
65+
presenceData.details = songName
66+
presenceData.state = 'Personal Playlist'
67+
presenceData.startTimestamp = now
68+
69+
if (showSongArt) {
70+
presenceData.largeImageKey = albumArt
71+
}
72+
}
73+
else if (pathname.includes('/playlist')) {
74+
const parts = title.replace(' - Nintendo Music', '').trim().split(/[·]/)
75+
const songName = parts[0]?.trim() || 'Unknown'
76+
77+
presenceData.details = songName
78+
presenceData.state = 'Official Playlist'
79+
presenceData.startTimestamp = now
80+
81+
if (showSongArt) {
82+
presenceData.largeImageKey = albumArt
83+
}
84+
}
85+
else if (pathname.includes('/my-music')) {
86+
const mainTitle = document.querySelector('#main-column h1')?.textContent
87+
88+
presenceData.details = mainTitle
89+
presenceData.state = 'My Music'
90+
presenceData.startTimestamp = now
91+
}
92+
else {
93+
presenceData.details = 'Browsing Music...'
94+
presenceData.startTimestamp = now
95+
}
96+
97+
if (!showTimestamps) {
98+
delete presenceData.startTimestamp
99+
delete presenceData.endTimestamp
100+
}
101+
102+
if (presenceData.details) {
103+
presence.setActivity(presenceData)
104+
}
105+
else {
106+
presence.clearActivity()
107+
}
108+
})

0 commit comments

Comments
 (0)