feat: update media input guidance
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
c954cc0406
commit
5abe5cc39f
@@ -1,8 +1,8 @@
|
||||
import { existsSync, statSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { AppError } from "../errors";
|
||||
import { createPlayDlResolver } from "./playDlResolver";
|
||||
import type { ResolvedMediaSource } from "./mediaTypes";
|
||||
import { createPlayDlResolver } from "./playDlResolver";
|
||||
import { createYtDlp, type YtDlpClient } from "./ytdlp";
|
||||
|
||||
type PlayDlResolver = ReturnType<typeof createPlayDlResolver>;
|
||||
@@ -21,7 +21,11 @@ export function createMediaResolver(
|
||||
return async function resolve(input: string): Promise<ResolvedMediaSource> {
|
||||
const source = input.trim();
|
||||
if (!source) {
|
||||
throw new AppError("Media source is required", "MISSING_MEDIA_SOURCE", 400);
|
||||
throw new AppError(
|
||||
"Media source is required",
|
||||
"MISSING_MEDIA_SOURCE",
|
||||
400,
|
||||
);
|
||||
}
|
||||
|
||||
const url = parseUrl(source);
|
||||
@@ -78,13 +82,18 @@ function looksLikeUrl(source: string): boolean {
|
||||
}
|
||||
|
||||
function isYouTubeUrl(url: URL): boolean {
|
||||
return ["youtube.com", "www.youtube.com", "m.youtube.com", "youtu.be"].includes(
|
||||
url.hostname,
|
||||
);
|
||||
return [
|
||||
"youtube.com",
|
||||
"www.youtube.com",
|
||||
"m.youtube.com",
|
||||
"youtu.be",
|
||||
].includes(url.hostname);
|
||||
}
|
||||
|
||||
function isSpotifyTrackUrl(url: URL): boolean {
|
||||
return url.hostname === "open.spotify.com" && url.pathname.startsWith("/track/");
|
||||
return (
|
||||
url.hostname === "open.spotify.com" && url.pathname.startsWith("/track/")
|
||||
);
|
||||
}
|
||||
|
||||
function resolveUrlSource(source: string): ResolvedMediaSource | null {
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import type { Readable } from "node:stream";
|
||||
|
||||
export type MediaMode = "music" | "screen";
|
||||
export type MediaSourceKind = "url" | "local" | "youtube" | "spotify" | "search";
|
||||
export type MediaSourceKind =
|
||||
| "url"
|
||||
| "local"
|
||||
| "youtube"
|
||||
| "spotify"
|
||||
| "search";
|
||||
export type MediaQueueItemStatus = "queued" | "playing" | "failed";
|
||||
|
||||
export interface ResolvedMediaSource {
|
||||
|
||||
@@ -30,7 +30,8 @@ export interface PlayDlDependencies {
|
||||
|
||||
export function createPlayDlResolver(dependencies: PlayDlDependencies = {}) {
|
||||
const search: SearchFunction = dependencies.search ?? play.search;
|
||||
const spotify: SpotifyFunction = dependencies.spotify ?? (play.spotify as SpotifyFunction);
|
||||
const spotify: SpotifyFunction =
|
||||
dependencies.spotify ?? (play.spotify as SpotifyFunction);
|
||||
|
||||
return {
|
||||
async searchYouTube(query: string): Promise<PlayDlResult> {
|
||||
|
||||
+4
-1
@@ -27,7 +27,10 @@ export function createYtDlp(dependencies: YtDlpDependencies = {}): YtDlpClient {
|
||||
"--no-warnings",
|
||||
"--quiet",
|
||||
]);
|
||||
const parsed = JSON.parse(data) as { title?: string; webpage_url?: string };
|
||||
const parsed = JSON.parse(data) as {
|
||||
title?: string;
|
||||
webpage_url?: string;
|
||||
};
|
||||
return {
|
||||
title: parsed.title || url,
|
||||
webpageUrl: parsed.webpage_url || url,
|
||||
|
||||
@@ -93,7 +93,12 @@ export interface AnalysisResult {
|
||||
}
|
||||
|
||||
export type MediaMode = "music" | "screen";
|
||||
export type MediaSourceKind = "url" | "local" | "youtube" | "spotify" | "search";
|
||||
export type MediaSourceKind =
|
||||
| "url"
|
||||
| "local"
|
||||
| "youtube"
|
||||
| "spotify"
|
||||
| "search";
|
||||
export type MediaQueueItemStatus = "queued" | "playing" | "failed";
|
||||
|
||||
export interface MediaQueueItem {
|
||||
|
||||
Reference in New Issue
Block a user