mirror of
https://github.com/SrIzan10/lofi.git
synced 2026-06-06 00:56:53 +00:00
feat: better station list
This commit is contained in:
@@ -14,7 +14,7 @@ export const state = $state({
|
||||
isLoading: true,
|
||||
error: null as string | null,
|
||||
currentTime: 0,
|
||||
duration: 0,
|
||||
duration: 0 as number | undefined,
|
||||
|
||||
presets: [] as Preset[],
|
||||
stations: [] as Station[],
|
||||
|
||||
7
src/lib/stations/chillhop.ts
Normal file
7
src/lib/stations/chillhop.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { 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;
|
||||
}
|
||||
17
src/lib/stations/index.ts
Normal file
17
src/lib/stations/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { getChillhopStation } from './chillhop';
|
||||
import { getSleepStationSongs } from './sleep';
|
||||
|
||||
const customStations = {
|
||||
50000: getSleepStationSongs,
|
||||
};
|
||||
const chillhopStations = Object.fromEntries(
|
||||
Array.from({ length: 100 }, (_, i) => {
|
||||
const stationId = 10000 + i;
|
||||
return [stationId, getChillhopStation.bind(null, stationId)];
|
||||
})
|
||||
);
|
||||
|
||||
export const stations = {
|
||||
...customStations,
|
||||
...chillhopStations,
|
||||
};
|
||||
@@ -1,28 +1,23 @@
|
||||
import type { Song, StationClass } from "@/types";
|
||||
import type { Song } from "@/types";
|
||||
|
||||
export class SleepStation implements StationClass {
|
||||
stationId = 50000;
|
||||
private m = new MersenneTwister();
|
||||
async getFiles(): Promise<string[]> {
|
||||
const res = await fetch('https://lofi-cdn.srizan.dev/sleep/list.json');
|
||||
const data = await res.json();
|
||||
return data;
|
||||
}
|
||||
|
||||
async finalData(): Promise<Song[]> {
|
||||
const files = await this.getFiles();
|
||||
const mapped = files.map(file => {
|
||||
const [artist, title] = file.replace('.opus', '').split(' - ');
|
||||
return {
|
||||
id: parseInt((this.m.random() * 1000000).toFixed(0)),
|
||||
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`,
|
||||
};
|
||||
}) as Song[];
|
||||
const shuffled = mapped.sort(() => 0.5 - this.m.random()).slice(0, 5);
|
||||
return shuffled;
|
||||
}
|
||||
}
|
||||
export async function getSleepStationSongs(): Promise<Song[]> {
|
||||
const m = new MersenneTwister();
|
||||
|
||||
const res = await fetch('https://lofi-cdn.srizan.dev/sleep/list.json');
|
||||
const files = await res.json() as string[];
|
||||
|
||||
const mapped = files.map(file => {
|
||||
const [artist, title] = file.replace('.opus', '').split(' - ');
|
||||
return {
|
||||
id: parseInt((m.random() * 1000000).toFixed(0)),
|
||||
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`,
|
||||
};
|
||||
}) as Song[];
|
||||
|
||||
const shuffled = mapped.sort(() => 0.5 - m.random()).slice(0, 5);
|
||||
return shuffled;
|
||||
}
|
||||
|
||||
@@ -85,9 +85,3 @@ export interface BRStation {
|
||||
Name: string;
|
||||
Source: string;
|
||||
}
|
||||
|
||||
export interface StationClass {
|
||||
stationId: number;
|
||||
getFiles(): Promise<string[]>;
|
||||
finalData(): Promise<Song[]>;
|
||||
}
|
||||
Reference in New Issue
Block a user