Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Show

Manav Rathi9424d26f559b
diff --git a/web/apps/photos/src/components/FileList.tsx b/web/apps/photos/src/components/FileList.tsx
index dfba4ab60c..9039b933ce 100644
--- a/web/apps/photos/src/components/FileList.tsx
+++ b/web/apps/photos/src/components/FileList.tsx
@@ -9,6 +9,7 @@ import { isSameDay } from "ente-base/date";
import { formattedDateRelative } from "ente-base/i18n-date";
import { downloadManager } from "ente-gallery/services/download";
import { EnteFile, enteFileDeletionDate } from "ente-media/file";
+import { fileDurationString } from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
import {
GAP_BTW_TILES,
@@ -1198,15 +1199,13 @@ const FileThumbnail: React.FC<FileThumbnailProps> = ({
) : (
<LoadingThumbnail />
)}
- {file.metadata.fileType === FileType.livePhoto ? (
+ {file.metadata.fileType == FileType.livePhoto ? (
<FileTypeIndicatorOverlay>
- <AlbumOutlinedIcon />
+ <AlbumOutlinedIcon fontSize="small" />
</FileTypeIndicatorOverlay>
) : (
- file.metadata.fileType === FileType.video && (
- <FileTypeIndicatorOverlay>
- <PlayCircleOutlineOutlinedIcon />
- </FileTypeIndicatorOverlay>
+ file.metadata.fileType == FileType.video && (
+ <VideoDurationOverlay duration={fileDurationString(file)} />
)
)}
{selected && <SelectedOverlay />}
@@ -1400,3 +1399,19 @@ const SelectedOverlay = styled(Overlay)(
border-radius: 4px;
`,
);
+
+interface VideoDurationOverlayProps {
+ duration: string | undefined;
+}
+
+const VideoDurationOverlay: React.FC<VideoDurationOverlayProps> = ({
+ duration,
+}) => (
+ <FileTypeIndicatorOverlay>
+ {duration ? (
+ <Typography variant="mini">{duration}</Typography>
+ ) : (
+ <PlayCircleOutlineOutlinedIcon fontSize="small" />
+ )}
+ </FileTypeIndicatorOverlay>
+);
diff --git a/web/packages/media/file-metadata.ts b/web/packages/media/file-metadata.ts
index 900dd89f4a..0056e4928f 100644
--- a/web/packages/media/file-metadata.ts
+++ b/web/packages/media/file-metadata.ts
@@ -767,6 +767,44 @@ export const fileLocation = (file: EnteFile): Location | undefined => {
return { latitude, longitude };
};
+/**
+ * Return the duration of the video as a formatted "HH:mm:ss" string (when
+ * present) for the given {@link EnteFile}.
+ *
+ * Only files with type `FileType.video` are expected to have a duration.
+ *
+ * @returns The duration of the video as a string of the form "HH:mm:ss". The
+ * underlying duration present in the file's metadata is guaranteed to be
+ * integral, so there will never be a subsecond component.
+ *
+ * - If the hour component is all zeroes, it will be omitted.
+ *
+ * - Leading zeros in the minutes component will be trimmed off if an hour
+ * component is not present. If minutes is all zeros, then "0" will be used.
+ *
+ * - For example, an underlying duration of 595 seconds will result in a
+ * formatted string of the form "9:55". While an underlying duration of 9
+ * seconds will be returned as a string "0:09".
+ *
+ * - A zero duration will be treated as undefined.
+ */
+export const fileDurationString = (file: EnteFile): string | undefined => {
+ const d = file.metadata.duration;
+ if (!d) return undefined;
+
+ const s = d % 60;
+ const m = Math.floor(d / 60) % 60;
+ const h = Math.floor(d / 3600);
+
+ const ss = s > 9 ? `${s}` : `0${s}`;
+ if (h) {
+ const mm = m > 9 ? `${m}` : `0${m}`;
+ return `${h}:${mm}:${ss}`;
+ } else {
+ return `${m}:${ss}`;
+ }
+};
+
/**
* Return the caption, aka "description", (if any) attached to the given
* {@link EnteFile}.