Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 40 additions & 0 deletions websites/N/Nintendo Music/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "https://schemas.premid.app/metadata/1.16",
"apiVersion": 1,
"author": {
"id": "135142639744843776",
"name": "espritorgue"
},
"service": "Nintendo Music",
"description": {
"en": "Nintendo Music is a streaming service by Nintendo that lets you listen to official video game soundtracks."
},
"url": "music.nintendo.com",
"regExp": "^https?[:][/][/]music[.]nintendo[.]com[/]",
"version": "1.0.0",
"logo": "https://i.imgur.com/eVpYUP0.png",
"thumbnail": "https://i.imgur.com/xc5urT9.png",
"color": "#FF0000",
"category": "music",
"tags": [
"music",
"nintendo",
"ost",
"soundtrack"
],
"settings": [
{
"id": "privacyMode",
"title": "Privacy Mode",
"icon": "fas fa-eye",
"value": false
},
{
"id": "displayOrder",
"title": "Display Order",
"icon": "fas fa-bars",
"value": 0,
"values": ["Title - Album", "Album - Title"]
}
]
}
84 changes: 84 additions & 0 deletions websites/N/Nintendo Music/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { ActivityType, Assets } from 'premid'

const presence = new Presence({
clientId: '1511302288138833950',
})
const browsingTimestamp = Math.floor(Date.now() / 1000)

enum ActivityAssets {
Logo = 'https://i.imgur.com/eVpYUP0.png',
}

presence.on('UpdateData', async () => {
// Retrieve Settings
const privacyModePromise = presence.getSetting<boolean>('privacyMode')
const displayOrderPromise = presence.getSetting<number>('displayOrder')
const [privacyMode, displayOrder] = await Promise.all([privacyModePromise, displayOrderPromise])

// Create the base presence data
const presenceData: PresenceData = {
largeImageKey: ActivityAssets.Logo,
details: 'Browsing',
state: 'Music Catalog',
startTimestamp: browsingTimestamp,
type: ActivityType.Listening,
}

// Retrieve Metadatas and audio source
const metadata = navigator.mediaSession.metadata
const audio = document.querySelector('audio')

if (metadata && audio) {
// Display the data or nor via privacyMode
if (privacyMode) {
presenceData.details = 'Nintendo Music'
presenceData.state = 'Listening to a music'
}
else {
presenceData.type = ActivityType.Listening
// Display Details and State depending on user choice
if (displayOrder === 0) {
presenceData.details = metadata.title
presenceData.state = metadata.album
}
else {
presenceData.details = metadata.album
presenceData.state = metadata.title
}
// Try to retrieve item and display it
const artwork = metadata.artwork[metadata.artwork.length - 1]
if (artwork) {
presenceData.largeImageKey = artwork.src
}

// Display Timestamp if playing otherwise display browsing time.
// Display a small icon when audio is paused
if (audio.paused) {
presenceData.smallImageKey = Assets.Pause
presenceData.smallImageText = 'Paused'

presenceData.startTimestamp = browsingTimestamp
delete presenceData.endTimestamp
}
else {
const startTimestamp = Math.floor(Date.now() / 1000) - Math.floor(audio.currentTime)
const endTimestamp = startTimestamp + Math.floor(audio.duration)

presenceData.startTimestamp = startTimestamp
presenceData.endTimestamp = endTimestamp
}
}
}
else {
// If no audio source or metadatas found, display a log
console.warn('[PreMid] No audio source or metadatas found')
}

// Set the activity
if (presenceData.state) {
presence.setActivity(presenceData)
}
else {
presence.clearActivity()
}
})
Loading