검색해서 재생기능 제작

검색하고 재생 누르면 재생됨
플레이리스트 재생 기능(주소 전달해서 재생하는 방식)
This commit is contained in:
tkrmagid-desktop
2026-04-09 01:53:27 +09:00
parent cefe37e2a8
commit 2e014e9b34
11 changed files with 238 additions and 21 deletions

View File

@@ -109,10 +109,11 @@ export const Spotify = {
return data.tracks.items.map((track) => ({
videoId: track.id,
url: `https://open.spotify.com/track/${track.id}`,
title: track.name,
artist: track.artists.map(artist => artist.name).join(", "),
duration: track.duration_ms,
thumbnail: track.album.images[2]?.url,
thumbnail: track.album.images[0]?.url,
}));
} catch (err) {
Logger.error(`스포티파이 검색 실패: ${err}`);
@@ -123,8 +124,7 @@ export const Spotify = {
const lowerQuery = query.toLocaleLowerCase().trim();
if (searchCache.has(lowerQuery)) return searchCache.get(lowerQuery) ?? null;
const track = (await this.getSearchFull(query) ?? [])?.[0];
const url = track?.videoId ? `https://open.spotify.com/track/${track.videoId}` : null;
if (url) searchCache.set(lowerQuery, url);
return url;
if (track.url) searchCache.set(lowerQuery, track.url);
return track.url;
}
}

View File

@@ -146,9 +146,10 @@ export const YoutubeMusic = {
if (videoId && title) {
results.push({
videoId,
url: `https://music.youtube.com/watch?v=${videoId}`,
title,
artist,
videoId,
thumbnail,
duration: parseDurationToMs(durationStr)
});
@@ -187,9 +188,10 @@ export const YoutubeMusic = {
if (videoId && title) {
results.push({
videoId,
url: `https://music.youtube.com/watch?v=${videoId}`,
title,
artist,
videoId,
thumbnail,
duration: parseDurationToMs(durationStr || "")
});
@@ -209,8 +211,7 @@ export const YoutubeMusic = {
const lowerQuery = query.toLocaleLowerCase().trim();
if (searchCache.has(lowerQuery)) return searchCache.get(lowerQuery) ?? null;
const video = (await this.getSearchFull(query) ?? [])?.[0];
const url = video?.videoId ? `https://music.youtube.com/watch?v=${video.videoId}` : null;
if (url) searchCache.set(lowerQuery, url);
return url;
if (video.url) searchCache.set(lowerQuery, video.url);
return video.url;
}
};

View File

@@ -3,6 +3,19 @@ import { DB } from "../Database";
import { Config } from "../Config";
import { Logger } from "../Logger";
import { clearAllMsg } from "./Utils";
import { client } from "../../index";
export const getGuildById = async (guildId: string): Promise<Guild | null> => {
const guild = client.guilds.cache.get(guildId)?.fetch();
if (!guild) return null;
return guild;
}
export const getMemberById = async (guild: Guild, userId: string): Promise<GuildMember | null> => {
const member = await guild.members.cache.get(userId)?.fetch(true);
if (!member) return null;
return member;
}
export const getVoiceChannel = (member: GuildMember): VoiceChannel | null => {
if (member.voice.channel?.type === ChannelType.GuildVoice) return member.voice.channel;
@@ -10,7 +23,7 @@ export const getVoiceChannel = (member: GuildMember): VoiceChannel | null => {
return null;
}
export const getVoiceChannelById = async(guild: Guild, userId: string): Promise<VoiceChannel | null> => {
export const getVoiceChannelById = async (guild: Guild, userId: string): Promise<VoiceChannel | null> => {
if (!guild) return null;
const member = await guild.members.cache.get(userId)?.fetch(true);
if (!member) return null;