mirror of
https://github.com/captbaritone/webamp
synced 2024-11-23 16:49:41 +00:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { PlaylistTrack } from "./types";
|
|
import * as Utils from "./utils";
|
|
import * as FileUtils from "./fileUtils";
|
|
|
|
export const trackName = Utils.weakMapMemoize(
|
|
(track: PlaylistTrack): string => {
|
|
const { artist, title, defaultName, url } = track;
|
|
if (artist && title) {
|
|
return `${artist} - ${title}`;
|
|
} else if (title) {
|
|
return title;
|
|
} else if (defaultName) {
|
|
return defaultName;
|
|
} else if (url) {
|
|
const filename = FileUtils.filenameFromUrl(url);
|
|
if (filename) {
|
|
return filename;
|
|
}
|
|
}
|
|
return "???";
|
|
}
|
|
);
|
|
|
|
export const trackFilename = Utils.weakMapMemoize(
|
|
(track: PlaylistTrack): string => {
|
|
if (track.url) {
|
|
const urlFilename = FileUtils.filenameFromUrl(track.url);
|
|
if (urlFilename != null) {
|
|
return urlFilename;
|
|
}
|
|
}
|
|
if (track.defaultName) {
|
|
return track.defaultName;
|
|
}
|
|
return "???";
|
|
}
|
|
);
|
|
|
|
export const trackFilterContents = Utils.weakMapMemoize(
|
|
(track: PlaylistTrack): string => {
|
|
return [track.artist, track.title, track.defaultName]
|
|
.filter(Boolean)
|
|
.join("|")
|
|
.toLowerCase();
|
|
}
|
|
);
|