58 lines
1.4 KiB
JavaScript
58 lines
1.4 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 prettyEpisodeNameWithoutShow = (season, episode) =>
|
|
`S${pad(season)}E${pad(episode)}`;
|
|
|
|
export const prettyEpisodeName = (showName, season, episode) =>
|
|
`${showName} S${pad(season)}E${pad(episode)}`;
|
|
|
|
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];
|
|
};
|
|
|
|
export const formatTorrents = (input) => {
|
|
if (!input.torrents || input.torrents.length == 0) {
|
|
return undefined;
|
|
}
|
|
|
|
let torrentMap = new Map();
|
|
input.torrents.forEach((torrent) => {
|
|
if (!torrent.result || !torrent.result.source) {
|
|
return;
|
|
}
|
|
|
|
if (!torrentMap.has(torrent.result.source)) {
|
|
torrentMap.set(torrent.result.source, new Map());
|
|
}
|
|
|
|
torrentMap.get(torrent.result.source).set(torrent.quality, torrent);
|
|
});
|
|
|
|
return torrentMap;
|
|
};
|