add: pull track duration
This commit is contained in:
parent
f10384ff39
commit
498884291e
4 changed files with 53 additions and 11 deletions
|
@ -548,6 +548,10 @@
|
|||
self.define(
|
||||
"timestamp",
|
||||
({ $ }, updated_, progress_ms_, duration_ms_, display = "full") => {
|
||||
if (duration_ms_ === "0") {
|
||||
return;
|
||||
}
|
||||
|
||||
const now = new Date().getTime();
|
||||
const updated = Number.parseInt(updated_) + 8000;
|
||||
|
||||
|
@ -623,6 +627,21 @@
|
|||
});
|
||||
});
|
||||
|
||||
self.define("pull_track_info", async (_, artist, name) => {
|
||||
const params = new URLSearchParams();
|
||||
params.append("query", `query=artist:"${artist}" and track:"${name}"`);
|
||||
params.append("limit", "1");
|
||||
params.append("fmt", "json");
|
||||
|
||||
return (
|
||||
await (
|
||||
await fetch(
|
||||
`https://musicbrainz.org/ws/2/recording?${params.toString()}`,
|
||||
)
|
||||
).json()
|
||||
).recordings[0];
|
||||
});
|
||||
|
||||
self.define("get_session", async ({ $ }, token) => {
|
||||
return await $.api("auth.getSession", {
|
||||
token,
|
||||
|
@ -641,7 +660,7 @@
|
|||
).recenttracks.track[0];
|
||||
});
|
||||
|
||||
self.define("publish_playing", async (_, playing) => {
|
||||
self.define("publish_playing", async ({ $ }, playing) => {
|
||||
if (!playing || !playing["@attr"] || !playing["@attr"].nowplaying) {
|
||||
return await trigger("connections::push_con_state", [
|
||||
"LastFm",
|
||||
|
@ -660,6 +679,11 @@
|
|||
return;
|
||||
}
|
||||
|
||||
const mb_info = await $.pull_track_info(
|
||||
playing.artist.name,
|
||||
playing.name,
|
||||
);
|
||||
|
||||
window.localStorage.setItem(
|
||||
"atto:connections.last_fm/name",
|
||||
playing.name,
|
||||
|
@ -675,11 +699,13 @@
|
|||
},
|
||||
data: {
|
||||
id: playing.mbid,
|
||||
timestamp: new Date().getTime().toString(),
|
||||
// track
|
||||
track: playing.name,
|
||||
artist: playing.artist.name,
|
||||
album: playing.album["#text"],
|
||||
// times
|
||||
timestamp: new Date().getTime().toString(),
|
||||
duration_ms: (mb_info.length || 0).toString(),
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue