add: pull track duration
This commit is contained in:
parent
f10384ff39
commit
498884291e
4 changed files with 53 additions and 11 deletions
|
@ -860,6 +860,7 @@ if state and state.data %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card secondary flex gap-2">
|
<div class="card secondary flex gap-2">
|
||||||
|
<a href="{{ state.external_urls.track }}">
|
||||||
<img
|
<img
|
||||||
src="{{ state.external_urls.track_img }}"
|
src="{{ state.external_urls.track_img }}"
|
||||||
alt="Track cover"
|
alt="Track cover"
|
||||||
|
@ -867,6 +868,7 @@ if state and state.data %}
|
||||||
class="avatar"
|
class="avatar"
|
||||||
style="--size: {{ size }}"
|
style="--size: {{ size }}"
|
||||||
/>
|
/>
|
||||||
|
</a>
|
||||||
|
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<h5 class="w-full">
|
<h5 class="w-full">
|
||||||
|
@ -880,6 +882,16 @@ if state and state.data %}
|
||||||
>{{ state.data.artist }}</a
|
>{{ state.data.artist }}</a
|
||||||
></span
|
></span
|
||||||
>
|
>
|
||||||
|
|
||||||
|
{% if state.data.duration_ms and state.data.duration_ms != "0" %}
|
||||||
|
<span
|
||||||
|
hook="spotify_time_text"
|
||||||
|
hook-arg:updated="{{ state.data.timestamp }}"
|
||||||
|
hook-arg:progress="25000"
|
||||||
|
hook-arg:duration="{{ state.data.duration_ms }}"
|
||||||
|
hook-arg:display="full"
|
||||||
|
></span>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -9,7 +9,7 @@ macros -%}
|
||||||
|
|
||||||
<meta
|
<meta
|
||||||
http-equiv="content-security-policy"
|
http-equiv="content-security-policy"
|
||||||
content="default-src 'self' blob: *.spotify.com; img-src * data:; media-src *; font-src *; style-src 'unsafe-inline' 'self' blob: *; script-src 'self' 'unsafe-inline' blob: *; object-src 'self' blob: *; upgrade-insecure-requests; connect-src * localhost; frame-src 'self' blob: data: *"
|
content="default-src 'self' blob: *.spotify.com musicbrainz.org; img-src * data:; media-src *; font-src *; style-src 'unsafe-inline' 'self' blob: *; script-src 'self' 'unsafe-inline' blob: *; object-src 'self' blob: *; upgrade-insecure-requests; connect-src * localhost; frame-src 'self' blob: data: *"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<link rel="icon" href="/public/favicon.svg" />
|
<link rel="icon" href="/public/favicon.svg" />
|
||||||
|
|
|
@ -548,6 +548,10 @@
|
||||||
self.define(
|
self.define(
|
||||||
"timestamp",
|
"timestamp",
|
||||||
({ $ }, updated_, progress_ms_, duration_ms_, display = "full") => {
|
({ $ }, updated_, progress_ms_, duration_ms_, display = "full") => {
|
||||||
|
if (duration_ms_ === "0") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
const updated = Number.parseInt(updated_) + 8000;
|
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) => {
|
self.define("get_session", async ({ $ }, token) => {
|
||||||
return await $.api("auth.getSession", {
|
return await $.api("auth.getSession", {
|
||||||
token,
|
token,
|
||||||
|
@ -641,7 +660,7 @@
|
||||||
).recenttracks.track[0];
|
).recenttracks.track[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
self.define("publish_playing", async (_, playing) => {
|
self.define("publish_playing", async ({ $ }, playing) => {
|
||||||
if (!playing || !playing["@attr"] || !playing["@attr"].nowplaying) {
|
if (!playing || !playing["@attr"] || !playing["@attr"].nowplaying) {
|
||||||
return await trigger("connections::push_con_state", [
|
return await trigger("connections::push_con_state", [
|
||||||
"LastFm",
|
"LastFm",
|
||||||
|
@ -660,6 +679,11 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mb_info = await $.pull_track_info(
|
||||||
|
playing.artist.name,
|
||||||
|
playing.name,
|
||||||
|
);
|
||||||
|
|
||||||
window.localStorage.setItem(
|
window.localStorage.setItem(
|
||||||
"atto:connections.last_fm/name",
|
"atto:connections.last_fm/name",
|
||||||
playing.name,
|
playing.name,
|
||||||
|
@ -675,11 +699,13 @@
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
id: playing.mbid,
|
id: playing.mbid,
|
||||||
timestamp: new Date().getTime().toString(),
|
|
||||||
// track
|
// track
|
||||||
track: playing.name,
|
track: playing.name,
|
||||||
artist: playing.artist.name,
|
artist: playing.artist.name,
|
||||||
album: playing.album["#text"],
|
album: playing.album["#text"],
|
||||||
|
// times
|
||||||
|
timestamp: new Date().getTime().toString(),
|
||||||
|
duration_ms: (mb_info.length || 0).toString(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub fn render_markdown(input: &str) -> String {
|
||||||
options.extension.strikethrough = true;
|
options.extension.strikethrough = true;
|
||||||
options.extension.autolink = true;
|
options.extension.autolink = true;
|
||||||
options.extension.header_ids = Option::Some(String::new());
|
options.extension.header_ids = Option::Some(String::new());
|
||||||
options.extension.tagfilter = true;
|
// options.extension.tagfilter = true;
|
||||||
options.render.unsafe_ = true;
|
options.render.unsafe_ = true;
|
||||||
// options.render.escape = true;
|
// options.render.escape = true;
|
||||||
options.parse.smart = false;
|
options.parse.smart = false;
|
||||||
|
@ -32,6 +32,10 @@ pub fn render_markdown(input: &str) -> String {
|
||||||
|
|
||||||
Builder::default()
|
Builder::default()
|
||||||
.generic_attributes(allowed_attributes)
|
.generic_attributes(allowed_attributes)
|
||||||
|
.add_tags(&[
|
||||||
|
"video", "source", "img", "b", "span", "p", "i", "strong", "em",
|
||||||
|
])
|
||||||
|
.rm_tags(&["script", "style", "link", "canvas"])
|
||||||
.clean(&html)
|
.clean(&html)
|
||||||
.to_string()
|
.to_string()
|
||||||
.replace("src=\"", "loading=\"lazy\" src=\"/api/v1/util/proxy?url=")
|
.replace("src=\"", "loading=\"lazy\" src=\"/api/v1/util/proxy?url=")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue