Skip to content

Commit

Permalink
Custom Lyric Providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheathed committed Jan 30, 2025
1 parent e40fae3 commit ee13500
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 9 deletions.
23 changes: 20 additions & 3 deletions app/client/src/components/Lyrics.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
<template>
<div :style='"max-height: " + height' class='overflow-y-auto' ref='content'>

<v-list-item>
<v-list-item-action>
<v-select
class='mr-4'
v-model='p'
label="Provider"
:items="['Deezer', 'LRCLib', 'Genius', 'MusixMatch']"
@change="load"
></v-select>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>{{$t("Custom Lyric Provider")}}</v-list-item-title>
</v-list-item-content>
</v-list-item>

<div class='text-center my-4'>
<v-progress-circular indeterminate v-if='loading'></v-progress-circular>
</div>

<div v-if='!loading && lyrics && lyrics.lyrics && lyrics.lyrics.length > 0' class='text-center'>
<div
v-for='(lyric, index) in lyrics.lyrics'
Expand Down Expand Up @@ -37,7 +53,7 @@
{{$t("Error loading lyrics or lyrics not found!")}}
</span>
</div>

</div>
</template>

Expand All @@ -53,6 +69,7 @@
cSongId: this.songId,
loading: true,
lyrics: null,
p: "Deezer",
currentLyricIndex: 0,
}
},
Expand All @@ -62,7 +79,7 @@
this.loading = true;
this.lyrics = null;
try {
let res = await this.$axios.get(`/lyrics/${this.songId}`);
let res = await this.$axios.get(`/lyrics/${this.songId}/${this.p}`);
// Check for new Pipe API response structure
if (res.data && res.data.track && res.data.track.lyrics) {
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ new Vue({
if (this.queue.data.length - 1 == this.queue.index && this.queue.source.source == 'dynamic_page_flow_config' && this.queue.source.type && this.queue.source.type == 'flow') {
if (this.lastid == this.track.id) return;
this.lastid = this.track.id;
let data = await this.$axios.get('/smarttracklist/flow/' + this.queue.source.type);
let data = await this.$axios.get('/smarttracklist/flow/' + this.queue.source.data);
if (data.data) {
this.replaceQueue(this.queue.data.concat(data.data));
}
Expand Down
8 changes: 4 additions & 4 deletions app/client/src/views/About.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
<v-list-item-subtitle>Developer</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item>
<v-list-item @click='bw86Dialog = true'>
<v-list-item-content>
<v-list-item-title class='font-weight-bold'>bw86</v-list-item-title>
<v-list-item-subtitle>Logo Designer, Former Developer</v-list-item-subtitle>
<v-list-item-subtitle>Logo Designer, Developer</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item>
Expand All @@ -79,7 +79,7 @@
Visit my site!
</v-card-title>
<v-card-text>
www.semen.makeup
github.com/bw8686
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
Expand All @@ -96,7 +96,7 @@
hiya!! please star the repo
</v-card-title>
<v-card-text>
github.com/Ascensionist
github.com/Sheathed
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
Expand Down
15 changes: 15 additions & 0 deletions app/client/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,21 @@
v-model='$root.settings.lastfmsecret'
></v-text-field>
<!-- Discord -->

<!-- <v-list-item>
<v-list-item-action>
<v-select
class='mr-4'
v-model='$root.settings.lrcprovider'
label="Provider"
:items="['Deezer', 'lrclib', 'genius', 'mxm']"
></v-select>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>{{$t("Custom Lyric Provider")}}</v-list-item-title>
</v-list-item-content>
</v-list-item> -->

<v-list-item>
<v-list-item-action>
<v-checkbox class='pl-2' v-model='$root.settings.enableDiscord' @click='snackbarText = $t("Requires restart to apply!"); snackbar = true'></v-checkbox>
Expand Down
88 changes: 88 additions & 0 deletions app/src/deezer.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,95 @@ class DeezerAPI {
}
}

async s() {
try {

const crypto = require('crypto');

const currentDate = new Date();
const l = currentDate.getFullYear().toString();
const s = (currentDate.getMonth() + 1).toString().padStart(2, '0');
const r = currentDate.getDate().toString().padStart(2, '0');

const message = Buffer.from(l + s + r);

const key = Buffer.from(
l + (currentDate.getMonth() + 1) + currentDate.getDate()
);

const hashOutput = crypto.createHmac('sha256', key).update(message).digest();

const encodedHash = hashOutput.toString('base64');
const a = encodedHash.replace(/[^A-Za-z0-9]+/g, '');

return a;

} catch (error) {
logger.error(error)
console.error(error)
}
}

async l(a, b, c, d){

var res = await axios({
method: 'GET',
headers: "",
url: `https://lyrics.saturn.kim/${a}/${b}/${c}/${d}`,
responseType: 'json'
});

var r = res.data;
return r;
}

async con(inputJson) {
const { lyrics } = inputJson;
const synchronizedLines = await this.parseLyrics(lyrics);

return {
track: {
id: "777", // Placeholder ID, can be dynamic
isExplicit: false,
lyrics: {
copyright: "Unknown", // Placeholder copyright info
id: "777", // Placeholder lyrics ID
synchronizedLines,
text: lyrics.replace(/\[\d+:\d+\.\d+\] /g, ""), // Remove timestamps
writers: "Unknown" // Placeholder writers info
}
}
};
}

async parseLyrics(lyrics) {
const lines = lyrics.split('\n');
const synchronizedLines = [];

for (let i = 0; i < lines.length; i++) {
const match = lines[i].match(/\[(\d+):(\d+\.\d+)\] (.*)/);
if (match) {
const minutes = parseInt(match[1], 10);
const seconds = parseFloat(match[2]);
const milliseconds = (minutes * 60 + seconds) * 1000;
const line = match[3];

let duration = 3000; // placeholder
if (synchronizedLines.length > 0) {
duration = milliseconds - synchronizedLines[synchronizedLines.length - 1].milliseconds;
}

synchronizedLines.push({
line,
lrcTimestamp: match[0].substring(0, match[0].indexOf(']') + 1),
milliseconds,
duration
});
}
}

return synchronizedLines;
}

async fallback(info, quality = 3) {
let qualityInfo = Track.getUrlInfo(info);
Expand Down
21 changes: 20 additions & 1 deletion app/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,14 @@ app.get('/trackmix/:id', async(req, res) => {
});

// Load lyrics by song ID
app.get('/lyrics/:id', async(req, res) => {
app.get('/lyrics/:id/:p', async(req, res) => {
var provider;
if (req.params.p == "Deezer") provider = "Deezer"
if (req.params.p == "LRCLib") provider = "lrclib"
if (req.params.p == "MusixMatch") provider = "mxm"
if (req.params.p == "Genius") provider = "genius"
try {
if (provider == "Deezer") {
// Create the GraphQL query string
const queryStringGraphQL = `
query SynchronizedTrackLyrics($trackId: String!) {
Expand Down Expand Up @@ -486,7 +492,20 @@ app.get('/lyrics/:id', async(req, res) => {

// No lyrics found in either API
res.status(502).send('Lyrics not found!');

} else { // provider is not deezer

try {
var trackData = await deezer.callApi('song.getData', { sng_id: req.params.id });
var a = await deezer.s();
var b = await deezer.l(provider, `${trackData.results.SNG_TITLE} ${trackData.results.ART_NAME}`, 1, a)
var c = await deezer.con(b)
return res.json(c);
} catch (error) {logger.error(error); console.error(error);}

}
} catch (error) {
logger.error(error);
console.error(error);
res.status(500).send('Internal Server Error');
}
Expand Down
1 change: 1 addition & 0 deletions app/src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Settings {

this.logListen = false;
this.lastFM = null;
this.lrcprovider = "Deezer";
this.enableDiscord = false;
this.discordJoin = false;

Expand Down

0 comments on commit ee13500

Please sign in to comment.