66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
export const prettyDurationFromMinutes = (runtime) => {
|
|
const hours = Math.floor(runtime / 60);
|
|
const minutes = (runtime % 60);
|
|
|
|
let duration = "";
|
|
if (hours > 0) { duration += hours + "h" }
|
|
if (minutes > 0) { duration += ("0" + minutes).slice(-2) }
|
|
if (hours === 0) { duration += " min" }
|
|
|
|
return duration;
|
|
}
|
|
|
|
const pad = (d) => (d < 10) ? "0" + d.toString() : d.toString();
|
|
|
|
export const prettyEpisodeName = (showName, season, episode) =>
|
|
`${showName} S${pad(season)}E${pad(episode)}`;
|
|
|
|
export const inLibrary = (element) =>
|
|
element.get("polochon_url", "") !== "";
|
|
|
|
export const isWishlisted = (element) => {
|
|
const wishlisted = element.get("wishlisted", undefined)
|
|
if (wishlisted !== undefined) {
|
|
return wishlisted;
|
|
}
|
|
|
|
const trackedSeason = element.get("tracked_season", null);
|
|
const trackedEpisode = element.get("tracked_episode", null);
|
|
if ((trackedSeason !== null) && (trackedEpisode !== null)) {
|
|
return true;
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
export const isEpisodeWishlisted = (element, trackedSeason, trackedEpisode) => {
|
|
if ((trackedSeason === null) && (trackedEpisode === null)) {
|
|
return false;
|
|
}
|
|
|
|
if ((trackedSeason === 0) && (trackedEpisode === 0)) {
|
|
return true
|
|
}
|
|
|
|
const season = element.get("season", 0);
|
|
const episode = element.get("episode", 0);
|
|
if (season < trackedSeason) {
|
|
return false
|
|
} else if (season > trackedSeason) {
|
|
return true
|
|
} else {
|
|
return (episode >= trackedEpisode)
|
|
}
|
|
}
|
|
|
|
export const prettySize = (fileSizeInBytes) => {
|
|
var i = -1;
|
|
var byteUnits = [" kB", " MB", " GB", " TB", "PB", "EB", "ZB", "YB"];
|
|
do {
|
|
fileSizeInBytes = fileSizeInBytes / 1024;
|
|
i++;
|
|
} while (fileSizeInBytes > 1024);
|
|
|
|
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
|
|
}
|