nowplaying: half-assed lastfm support #4
1 arquivos alterados com 8 adições e 4 exclusões
avoid fetching link if its not needed
commit
4bb4afe182
|
|
@ -15,7 +15,7 @@ import { getSongOnPreferredProvider, lobotomizedSongButton, musicCache, nowPlayi
|
||||||
import { type Config } from "../config.ts";
|
import { type Config } from "../config.ts";
|
||||||
import { hash } from "crypto"
|
import { hash } from "crypto"
|
||||||
|
|
||||||
async function getNowPlaying(username: string, lastFMApiKey?: string): Promise<{
|
async function getNowPlaying(username: string, lastFMApiKey?: string, lastFMFetchLink?: boolean): Promise<{
|
||||||
songName: string, artistName: string, link: string
|
songName: string, artistName: string, link: string
|
||||||
} | false | undefined> {
|
} | false | undefined> {
|
||||||
if (!lastFMApiKey) {
|
if (!lastFMApiKey) {
|
||||||
|
|
@ -40,8 +40,12 @@ async function getNowPlaying(username: string, lastFMApiKey?: string): Promise<{
|
||||||
// yes its a string, horror
|
// yes its a string, horror
|
||||||
if (track["@attr"]?.nowplaying !== "true") return false
|
if (track["@attr"]?.nowplaying !== "true") return false
|
||||||
// it also doesnt provide a streaming platform url, im sorry i have to do this
|
// it also doesnt provide a streaming platform url, im sorry i have to do this
|
||||||
const page = await (await fetch(track.url)).text()
|
let link = ""
|
||||||
const [, link] = page.match(/class="header-new-playlink"\s+href="(.+?)"/m) || []
|
if (lastFMFetchLink) {
|
||||||
|
const page = await (await fetch(track.url)).text()
|
||||||
|
const match = page.match(/class="header-new-playlink"\s+href="(.+?)"/m)
|
||||||
|
if (match) link = match[1]
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
songName: track.name,
|
songName: track.name,
|
||||||
artistName: track.artist["#text"],
|
artistName: track.artist["#text"],
|
||||||
|
|
@ -60,7 +64,7 @@ export default class PingCommand extends Command {
|
||||||
let useSonglink = interaction.options.getBoolean("usesonglink") ?? config.commandDefaults.nowplaying.useSonglink
|
let useSonglink = interaction.options.getBoolean("usesonglink") ?? config.commandDefaults.nowplaying.useSonglink
|
||||||
const useiTunes = interaction.options.getBoolean("useitunes") ?? config.commandDefaults.nowplaying.useItunes
|
const useiTunes = interaction.options.getBoolean("useitunes") ?? config.commandDefaults.nowplaying.useItunes
|
||||||
|
|
||||||
const nowPlaying = await getNowPlaying(user, useLastFM ? config.lastFMApiKey : undefined)
|
const nowPlaying = await getNowPlaying(user, useLastFM ? config.lastFMApiKey : undefined, !useiTunes)
|
||||||
if (typeof nowPlaying === "undefined") {
|
if (typeof nowPlaying === "undefined") {
|
||||||
await interaction.followUp("something shat itself!");
|
await interaction.followUp("something shat itself!");
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Carregando…
Adicionar tabela
Adicionar um link
Referência em uma nova issue