mirror of
https://github.com/SrIzan10/lofi.git
synced 2026-06-06 00:56:53 +00:00
feat: api reworks
This commit is contained in:
@@ -218,7 +218,7 @@
|
||||
{#if !appState.isLoading}
|
||||
<audio
|
||||
bind:this={audioElement}
|
||||
src={appState.currentSong!.endpoint || `https://stream.chillhop.com/mp3/${appState.currentSong!.fileId}`}
|
||||
src={appState.currentSong!.endpoint}
|
||||
autoplay
|
||||
volume={appState.volume}
|
||||
ontimeupdate={checkTimeAndPrepareNextSong}
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
import type { Song } from "@/types";
|
||||
import type { CHSong, Song } from "@/types";
|
||||
|
||||
export async function getChillhopStation(id: number): Promise<Song[]> {
|
||||
const res = await fetch(`https://stream.chillhop.com/live/${id}`);
|
||||
const data = await res.json() as Song[];
|
||||
return data;
|
||||
const data = await res.json() as CHSong[];
|
||||
|
||||
const finalData = data.map(song => ({
|
||||
artists: song.artists,
|
||||
title: song.title,
|
||||
endpoint: `https://stream.chillhop.com/mp3/${song.fileId}`,
|
||||
image: song.image,
|
||||
label: 'Chillhop Music',
|
||||
spotifyId: song.spotifyId,
|
||||
duration: song.duration,
|
||||
})) as Song[];
|
||||
|
||||
return finalData;
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ export async function getSleepStationSongs(): Promise<Song[]> {
|
||||
const mapped = files.map(file => {
|
||||
const [artist, title] = file.replace('.opus', '').split(' - ');
|
||||
return {
|
||||
id: 727,
|
||||
fileId: file.replace('.opus', ''),
|
||||
endpoint: `https://lofi-cdn.srizan.dev/sleep/${file}`,
|
||||
artists: artist,
|
||||
title: title,
|
||||
image: `https://lofi-cdn.srizan.dev/sleep/thumbs/${file.replace('.opus', '')}.webp`,
|
||||
label: 'Chilled Cat',
|
||||
};
|
||||
}) as Song[];
|
||||
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
export interface Song {
|
||||
artists: string;
|
||||
title: string;
|
||||
endpoint: string;
|
||||
image: string;
|
||||
label?: string; // optional record label
|
||||
spotifyId?: string; // TODO: enforce in the future for all spotify scraped stations
|
||||
duration?: number; // TODO: enforce in all stations
|
||||
}
|
||||
|
||||
export interface CHSong {
|
||||
id: number;
|
||||
fileId: number | string;
|
||||
endpoint?: string;
|
||||
|
||||
@@ -25,19 +25,3 @@ export async function getStationSongs(stationId: number) {
|
||||
return data;
|
||||
}
|
||||
|
||||
export function setSongTime() {
|
||||
if (!state.currentSong!.startTime) {
|
||||
state.currentTime = 0;
|
||||
return;
|
||||
}
|
||||
const currentTime = new Date().getTime() / 1000;
|
||||
const startTime = new Date(state.currentSong!.startTime).getTime() / 1000;
|
||||
const endTime = new Date(state.currentSong!.endTime!).getTime() / 1000;
|
||||
const duration = endTime - startTime;
|
||||
const elapsed = currentTime - startTime;
|
||||
if (elapsed > 0 && elapsed < duration) {
|
||||
state.currentTime = elapsed;
|
||||
} else {
|
||||
state.currentTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user