-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(engines): add
isResponsible
method
BREAKING CHANGE: remove exported function `detectTrackSource` BREAKING CHANGE: require method `isResponsible` for engines
- Loading branch information
1 parent
bf8def3
commit dc58e90
Showing
7 changed files
with
56 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,10 @@ | ||
import { stat } from "fs/promises"; | ||
import { PlayerEngine, TrackSource } from "../types/engines"; | ||
import { isSubPath } from "../utils/fs"; | ||
import { fileEngine } from "./file"; | ||
import { spotifyEngine } from "./spotify"; | ||
import { youtubeEngine } from "./youtube"; | ||
|
||
export const playerEngines: Record<TrackSource, PlayerEngine> = { | ||
youtube: youtubeEngine, | ||
file: fileEngine, | ||
spotify: spotifyEngine, | ||
file: fileEngine, | ||
}; | ||
|
||
/** | ||
* Automatically detect the query type | ||
*/ | ||
export async function detectTrackSource( | ||
query: string, | ||
fileRoot?: string | ||
): Promise<TrackSource> { | ||
if (query.startsWith("https://open.spotify.com/")) return "spotify"; | ||
if (query.startsWith("https://www.youtube.com/")) return "youtube"; | ||
|
||
if (!fileRoot || isSubPath(fileRoot, query)) { | ||
// check if query is file path | ||
try { | ||
const stats = await stat(query); | ||
if (stats.isFile()) return "file"; | ||
} catch (e) { | ||
// noop | ||
} | ||
} | ||
|
||
return "youtube"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters