mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add file size in mediainfo popup
This commit is contained in:
parent
ac846ad351
commit
c3e8f87562
@ -141,10 +141,6 @@ export const WatchInfoP = z
|
||||
* The sha1 of the video file.
|
||||
*/
|
||||
sha: z.string(),
|
||||
/**
|
||||
* The duration of the video (in seconds).
|
||||
*/
|
||||
length: z.number(),
|
||||
/**
|
||||
* The internal path of the video file.
|
||||
*/
|
||||
@ -153,6 +149,14 @@ export const WatchInfoP = z
|
||||
* The extension used to store this video file.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@ -179,15 +183,23 @@ export const WatchInfoP = z
|
||||
chapters: z.array(ChapterP),
|
||||
})
|
||||
.transform((x) => {
|
||||
const hour = Math.floor(x.length / 3600);
|
||||
const minutes = Math.ceil((x.length % 3600) / 60);
|
||||
const duration = `${hour ? `${hour}h` : ""}${minutes}m`;
|
||||
const hour = Math.floor(x.duration / 3600);
|
||||
const minutes = Math.ceil((x.duration % 3600) / 60);
|
||||
|
||||
return {
|
||||
...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
|
||||
*/
|
||||
|
@ -19,15 +19,15 @@
|
||||
*/
|
||||
|
||||
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 { useTranslation } from "react-i18next";
|
||||
import { ScrollView, View } from "react-native";
|
||||
import { percent, px, useYoshiki, vh } from "yoshiki/native";
|
||||
import { View } from "react-native";
|
||||
import { useYoshiki } from "yoshiki/native";
|
||||
import { Fragment } from "react";
|
||||
|
||||
const MediaInfoTable = ({
|
||||
mediaInfo: { path, video, container, audios, subtitles, duration },
|
||||
mediaInfo: { path, video, container, audios, subtitles, duration, size },
|
||||
}: {
|
||||
mediaInfo: Partial<WatchInfo>;
|
||||
}) => {
|
||||
@ -62,6 +62,7 @@ const MediaInfoTable = ({
|
||||
[t("mediainfo.file")]: path?.replace(/^\/video\//, ""),
|
||||
[t("mediainfo.container")]: container,
|
||||
[t("mediainfo.duration")]: duration,
|
||||
[t("mediainfo.size")]: size,
|
||||
},
|
||||
{
|
||||
[t("mediainfo.video")]: video
|
||||
|
@ -127,7 +127,9 @@ export const Player = ({ slug, type }: { slug: string; type: "episode" | "movie"
|
||||
next={next}
|
||||
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
|
||||
{...css({
|
||||
flexGrow: 1,
|
||||
|
@ -184,6 +184,7 @@
|
||||
"subtitles": "Subtitles",
|
||||
"forced": "Forced",
|
||||
"default": "Default",
|
||||
"duration": "Duration"
|
||||
"duration": "Duration",
|
||||
"size": "Size"
|
||||
}
|
||||
}
|
||||
|
@ -184,6 +184,7 @@
|
||||
"subtitles": "Sous titres",
|
||||
"forced": "Forcé",
|
||||
"default": "Par Défaut",
|
||||
"duration": "Duration"
|
||||
"duration": "Duration",
|
||||
"size": "Taille"
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ type MediaInfo struct {
|
||||
/// The file size of the video file.
|
||||
Size uint64 `json:"size"`
|
||||
/// The length of the media in seconds.
|
||||
Length float32 `json:"length"`
|
||||
Duration float32 `json:"duration"`
|
||||
/// The container of the video file of this episode.
|
||||
Container string `json:"container"`
|
||||
/// The video codec and infromations.
|
||||
@ -201,8 +201,8 @@ func GetInfo(path string) (*MediaInfo, error) {
|
||||
// Remove leading .
|
||||
Extension: filepath.Ext(path)[1:],
|
||||
Size: ParseUint64(mi.Parameter(mediainfo.StreamGeneral, 0, "FileSize")),
|
||||
// convert seconds to ms
|
||||
Length: ParseFloat(mi.Parameter(mediainfo.StreamGeneral, 0, "Duration")) / 1000,
|
||||
// convert ms to seconds
|
||||
Duration: ParseFloat(mi.Parameter(mediainfo.StreamGeneral, 0, "Duration")) / 1000,
|
||||
Container: mi.Parameter(mediainfo.StreamGeneral, 0, "Format"),
|
||||
Video: Video{
|
||||
// This codec is not in the right format (does not include bitdepth...).
|
||||
|
Loading…
x
Reference in New Issue
Block a user