Add file size in mediainfo popup

This commit is contained in:
Zoe Roux 2024-01-24 01:24:28 +01:00
parent ac846ad351
commit c3e8f87562
6 changed files with 35 additions and 18 deletions

View File

@ -141,10 +141,6 @@ export const WatchInfoP = z
* The sha1 of the video file. * The sha1 of the video file.
*/ */
sha: z.string(), sha: z.string(),
/**
* The duration of the video (in seconds).
*/
length: z.number(),
/** /**
* The internal path of the video file. * The internal path of the video file.
*/ */
@ -153,6 +149,14 @@ export const WatchInfoP = z
* The extension used to store this video file. * The extension used to store this video file.
*/ */
extension: z.string(), extension: z.string(),
/**
* The file size of the video file.
*/
size: z.number(),
/**
* The duration of the video (in seconds).
*/
duration: z.number(),
/** /**
* The container of the video file of this episode. Common containers are mp4, mkv, avi and so on. * The container of the video file of this episode. Common containers are mp4, mkv, avi and so on.
*/ */
@ -179,15 +183,23 @@ export const WatchInfoP = z
chapters: z.array(ChapterP), chapters: z.array(ChapterP),
}) })
.transform((x) => { .transform((x) => {
const hour = Math.floor(x.length / 3600); const hour = Math.floor(x.duration / 3600);
const minutes = Math.ceil((x.length % 3600) / 60); const minutes = Math.ceil((x.duration % 3600) / 60);
const duration = `${hour ? `${hour}h` : ""}${minutes}m`;
return { return {
...x, ...x,
duration, duration: `${hour ? `${hour}h` : ""}${minutes}m`,
durationSeconds: x.duration,
size: humanFileSize(x.size),
}; };
}); });
// from https://stackoverflow.com/questions/10420352/converting-file-size-in-bytes-to-human-readable-string
const humanFileSize = (size: number): string => {
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
return (size / Math.pow(1024, i)).toFixed(2) * 1 + " " + ["B", "kB", "MB", "GB", "TB"][i];
};
/** /**
* A watch info for a video * A watch info for a video
*/ */

View File

@ -19,15 +19,15 @@
*/ */
import { Audio, QueryIdentifier, Subtitle, WatchInfo, WatchInfoP } from "@kyoo/models"; import { Audio, QueryIdentifier, Subtitle, WatchInfo, WatchInfoP } from "@kyoo/models";
import { Button, HR, P, Popup, Skeleton, ts } from "@kyoo/primitives"; import { Button, HR, P, Popup, Skeleton } from "@kyoo/primitives";
import { Fetch } from "../fetch"; import { Fetch } from "../fetch";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { ScrollView, View } from "react-native"; import { View } from "react-native";
import { percent, px, useYoshiki, vh } from "yoshiki/native"; import { useYoshiki } from "yoshiki/native";
import { Fragment } from "react"; import { Fragment } from "react";
const MediaInfoTable = ({ const MediaInfoTable = ({
mediaInfo: { path, video, container, audios, subtitles, duration }, mediaInfo: { path, video, container, audios, subtitles, duration, size },
}: { }: {
mediaInfo: Partial<WatchInfo>; mediaInfo: Partial<WatchInfo>;
}) => { }) => {
@ -62,6 +62,7 @@ const MediaInfoTable = ({
[t("mediainfo.file")]: path?.replace(/^\/video\//, ""), [t("mediainfo.file")]: path?.replace(/^\/video\//, ""),
[t("mediainfo.container")]: container, [t("mediainfo.container")]: container,
[t("mediainfo.duration")]: duration, [t("mediainfo.duration")]: duration,
[t("mediainfo.size")]: size,
}, },
{ {
[t("mediainfo.video")]: video [t("mediainfo.video")]: video

View File

@ -127,7 +127,9 @@ export const Player = ({ slug, type }: { slug: string; type: "episode" | "movie"
next={next} next={next}
previous={previous} previous={previous}
/> />
{data && info && <WatchStatusObserver type={type} slug={data.slug} duration={info.length} />} {data && info && (
<WatchStatusObserver type={type} slug={data.slug} duration={info.durationSeconds} />
)}
<View <View
{...css({ {...css({
flexGrow: 1, flexGrow: 1,

View File

@ -184,6 +184,7 @@
"subtitles": "Subtitles", "subtitles": "Subtitles",
"forced": "Forced", "forced": "Forced",
"default": "Default", "default": "Default",
"duration": "Duration" "duration": "Duration",
"size": "Size"
} }
} }

View File

@ -184,6 +184,7 @@
"subtitles": "Sous titres", "subtitles": "Sous titres",
"forced": "Forcé", "forced": "Forcé",
"default": "Par Défaut", "default": "Par Défaut",
"duration": "Duration" "duration": "Duration",
"size": "Taille"
} }
} }

View File

@ -22,7 +22,7 @@ type MediaInfo struct {
/// The file size of the video file. /// The file size of the video file.
Size uint64 `json:"size"` Size uint64 `json:"size"`
/// The length of the media in seconds. /// The length of the media in seconds.
Length float32 `json:"length"` Duration float32 `json:"duration"`
/// The container of the video file of this episode. /// The container of the video file of this episode.
Container string `json:"container"` Container string `json:"container"`
/// The video codec and infromations. /// The video codec and infromations.
@ -201,8 +201,8 @@ func GetInfo(path string) (*MediaInfo, error) {
// Remove leading . // Remove leading .
Extension: filepath.Ext(path)[1:], Extension: filepath.Ext(path)[1:],
Size: ParseUint64(mi.Parameter(mediainfo.StreamGeneral, 0, "FileSize")), Size: ParseUint64(mi.Parameter(mediainfo.StreamGeneral, 0, "FileSize")),
// convert seconds to ms // convert ms to seconds
Length: ParseFloat(mi.Parameter(mediainfo.StreamGeneral, 0, "Duration")) / 1000, Duration: ParseFloat(mi.Parameter(mediainfo.StreamGeneral, 0, "Duration")) / 1000,
Container: mi.Parameter(mediainfo.StreamGeneral, 0, "Format"), Container: mi.Parameter(mediainfo.StreamGeneral, 0, "Format"),
Video: Video{ Video: Video{
// This codec is not in the right format (does not include bitdepth...). // This codec is not in the right format (does not include bitdepth...).