🎥 Make videos programmatically with React
metadata
Jonny Burger9d33d917e5fb
diff --git a/packages/convert/app/components/MetadataTable.tsx b/packages/convert/app/components/MetadataTable.tsxindex 179a77c8b9..597cc6abf9 100644--- a/packages/convert/app/components/MetadataTable.tsx+++ b/packages/convert/app/components/MetadataTable.tsx@@ -1,6 +1,10 @@import {MetadataEntry} from '@remotion/media-parser';import React, {useMemo} from 'react';-import {renderMetadataLabel} from '~/lib/render-metadata-label';+import {+ renderMetadataLabel,+ renderMetadataValue,+ sortMetadataByRelevance,+} from '~/lib/render-metadata-label';import {TableCell, TableRow} from './ui/table';const LimitedWidthLabel: React.FC<{@@ -19,7 +23,7 @@ export const MetadataDisplay: React.FC<{readonly trackId: number | null;}> = ({metadata, trackId}) => {const filtered = useMemo(() => {- return metadata.filter((entry) => {+ return sortMetadataByRelevance(metadata).filter((entry) => {return entry.trackId === trackId;});}, [metadata, trackId]);@@ -34,7 +38,9 @@ export const MetadataDisplay: React.FC<{</LimitedWidthLabel></TableCell><TableCell className="text-right">- <LimitedWidthLabel alt={entry.key}>{entry.value}</LimitedWidthLabel>+ <LimitedWidthLabel alt={entry.key}>+ {renderMetadataValue(entry.key, entry.value)}+ </LimitedWidthLabel></TableCell></TableRow>))}diff --git a/packages/convert/app/lib/render-metadata-label.ts b/packages/convert/app/lib/render-metadata-label.tsindex e435fa412b..a17bd3e362 100644--- a/packages/convert/app/lib/render-metadata-label.ts+++ b/packages/convert/app/lib/render-metadata-label.ts@@ -1,3 +1,5 @@+import {MetadataEntry} from '@remotion/media-parser';+/* eslint-disable complexity */export const renderMetadataLabel = (key: string) => {if (key === 'com.apple.quicktime.location.accuracy.horizontal') {@@ -126,3 +128,116 @@ export const renderMetadataLabel = (key: string) => {return key;};++export const sortMetadataByRelevance = (metadata: MetadataEntry[]) => {+ const metadataKeys = [+ // General metadata sorted by relevance+ 'title',+ 'artist',+ 'album',+ 'releaseDate',+ 'genre',+ 'composer',+ 'writer',+ 'director',+ 'producer',+ 'description',+ 'duration',+ 'comment',+ 'encoder',+ 'copyright',++ // Apple-specific metadata sorted by relevance+ 'com.apple.quicktime.creationdate', // Relevant: useful for sorting by creation date+ 'com.apple.quicktime.make', // Relevant: manufacturer information+ 'com.apple.quicktime.model', // Relevant: device information can be interesting+ 'com.apple.quicktime.camera.lens_model', // Relevant: for photography enthusiasts+ 'com.apple.quicktime.camera.focal_length.35mm_equivalent', // Relevant: for photography enthusiasts+ 'com.apple.quicktime.software', // Less relevant: technical detail+ 'com.apple.quicktime.location.ISO6709', // Relevant: location information can be useful+ 'com.apple.quicktime.location.accuracy.horizontal', // Relevant: complements location data+ 'com.apple.quicktime.content.identifier', // Less relevant: unique identifier+ 'com.apple.quicktime.live-photo.vitality-score', // Less relevant: specific to live photos+ 'com.apple.quicktime.live-photo.vitality-scoring-version', // Less relevant: specific to live photos+ 'com.apple.quicktime.live-photo.auto', // Less relevant: specific to live photos+ 'com.apple.quicktime.full-frame-rate-playback-intent', // Less relevant: playback detail+ 'major_brand',+ 'minor_version',+ 'compatible_brands',+ 'handler_name',+ ];++ return metadata.slice().sort((a, b) => {+ const aIndex = metadataKeys.indexOf(a.key);+ const bIndex = metadataKeys.indexOf(b.key);++ if (aIndex === -1 && bIndex === -1) {+ return a.key.localeCompare(b.key);+ }++ if (aIndex === -1) {+ return 1;+ }++ if (bIndex === -1) {+ return -1;+ }++ return aIndex - bIndex;+ });+};++function displayLocationData(locationString: string): string {+ // Regular expression to match the pattern of the location string+ const locationPattern = /^([+-]\d+\.\d+)([+-]\d+\.\d+)([+-]\d+\.\d+)\/$/;+ const match = locationString.match(locationPattern);++ if (!match) {+ throw new Error('Invalid location format');+ }++ // Extract latitude, longitude, and altitude+ const latitude = parseFloat(match[1]);+ const longitude = parseFloat(match[2]);+ const altitude = parseFloat(match[3]);++ // Format the output+ return `${latitude.toFixed(4)}°, ${longitude.toFixed(4)}°\nAltitude ${altitude.toFixed(2)}m`;+}++function formatDateString(dateString: string): string {+ // Parse the date string into a Date object+ const date = new Date(dateString);++ // Define the options for formatting the date+ const options: Intl.DateTimeFormatOptions = {+ year: 'numeric',+ month: '2-digit',+ day: '2-digit',+ hour: '2-digit',+ minute: '2-digit',+ second: '2-digit',+ timeZoneName: 'short', // This includes the timezone+ hour12: false, // Use 24-hour format+ };++ // Create a DateTimeFormat object for the user's locale+ const formatter = new Intl.DateTimeFormat('en-CH', options);++ // Format the date+ return formatter.format(date);+}++export const renderMetadataValue = (key: string, value: string | number) => {+ if (key === 'com.apple.quicktime.location.ISO6709') {+ return displayLocationData(String(value));+ }+ if (key === 'com.apple.quicktime.creationdate') {+ return formatDateString(String(value));+ }+ if (key === 'com.apple.quicktime.camera.focal_length.35mm_equivalent') {+ return String(value) + 'mm';+ }++ return value;+};