2023-05-07 15:45:45 +02:00
|
|
|
import { MediaInfo } from "../models/mediaInfo";
|
2023-07-31 13:43:32 +02:00
|
|
|
import { MediaStatus } from "../models/mediaStatus";
|
2024-05-06 08:20:41 +02:00
|
|
|
import {RepeatState} from "../models/repeatState";
|
2023-05-07 15:45:45 +02:00
|
|
|
|
|
|
|
export const mediaInfo = {
|
|
|
|
title: "",
|
|
|
|
artists: "",
|
|
|
|
album: "",
|
|
|
|
icon: "",
|
2023-07-31 13:43:32 +02:00
|
|
|
status: MediaStatus.paused as string,
|
2023-05-07 15:45:45 +02:00
|
|
|
url: "",
|
|
|
|
current: "",
|
2024-05-05 20:12:10 +02:00
|
|
|
currentInSeconds: 0,
|
2023-05-07 15:45:45 +02:00
|
|
|
duration: "",
|
2024-05-05 20:12:10 +02:00
|
|
|
durationInSeconds: 0,
|
2023-05-07 15:45:45 +02:00
|
|
|
image: "tidal-hifi-icon",
|
2024-01-07 14:58:49 +01:00
|
|
|
favorite: false,
|
2024-05-06 08:20:41 +02:00
|
|
|
|
|
|
|
player: {
|
|
|
|
status: MediaStatus.paused as string,
|
|
|
|
shuffle: false,
|
|
|
|
repeat: RepeatState.off as string,
|
|
|
|
}
|
2023-05-07 15:45:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export const updateMediaInfo = (arg: MediaInfo) => {
|
|
|
|
mediaInfo.title = propOrDefault(arg.title);
|
|
|
|
mediaInfo.artists = propOrDefault(arg.artists);
|
|
|
|
mediaInfo.album = propOrDefault(arg.album);
|
|
|
|
mediaInfo.icon = propOrDefault(arg.icon);
|
2024-05-05 15:09:54 +02:00
|
|
|
mediaInfo.url = toUniversalUrl(propOrDefault(arg.url));
|
2023-05-07 15:45:45 +02:00
|
|
|
mediaInfo.status = propOrDefault(arg.status);
|
|
|
|
mediaInfo.current = propOrDefault(arg.current);
|
2024-05-05 20:12:10 +02:00
|
|
|
mediaInfo.currentInSeconds = arg.currentInSeconds ?? 0;
|
2023-05-07 15:45:45 +02:00
|
|
|
mediaInfo.duration = propOrDefault(arg.duration);
|
2024-05-05 20:12:10 +02:00
|
|
|
mediaInfo.durationInSeconds = arg.durationInSeconds ?? 0;
|
2023-05-07 15:45:45 +02:00
|
|
|
mediaInfo.image = propOrDefault(arg.image);
|
2024-01-07 14:58:49 +01:00
|
|
|
mediaInfo.favorite = arg.favorite;
|
2024-05-06 08:20:41 +02:00
|
|
|
|
|
|
|
mediaInfo.player.status = propOrDefault(arg.player?.status);
|
|
|
|
mediaInfo.player.shuffle = arg.player.shuffle;
|
|
|
|
mediaInfo.player.repeat = propOrDefault(arg.player?.repeat);
|
2023-05-07 15:45:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the property or a default value
|
|
|
|
* @param {*} prop property to check
|
|
|
|
* @param {*} defaultValue defaults to ""
|
|
|
|
*/
|
|
|
|
function propOrDefault(prop: string, defaultValue = "") {
|
2024-05-05 15:09:54 +02:00
|
|
|
return prop || defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append the universal link syntax (?u) to any url
|
|
|
|
* @param url url to append the universal link syntax to
|
|
|
|
* @returns url with `?u` appended, or the original value of url if falsy
|
|
|
|
*/
|
|
|
|
function toUniversalUrl(url: string) {
|
|
|
|
if (url) {
|
|
|
|
const queryParamsSet = url.indexOf("?");
|
|
|
|
return queryParamsSet > -1 ? `${url}&u` : `${url}?u`;
|
|
|
|
}
|
|
|
|
return url;
|
2023-05-07 15:45:45 +02:00
|
|
|
}
|