@@ -4,10 +4,12 @@ import {
44 redirect
55} from '@remix-run/node'
66import { useLoaderData , useNavigate } from '@remix-run/react'
7+ import { parseFile } from 'music-metadata'
8+ import path from 'path'
79
810import { getPrisma } from '~/lib/prisma.server'
911import { checkSession } from '~/lib/session'
10- import { pageTitle } from '~/lib/utils'
12+ import { pageTitle , getSecondsAsTime } from '~/lib/utils'
1113import { Page , Actions } from '~/lib/ui'
1214
1315export const meta : MetaFunction < typeof loader > = ( { data} ) => {
@@ -27,6 +29,24 @@ export const loader = async ({request, params}: LoaderFunctionArgs) => {
2729 where : { id : params . sound }
2830 } )
2931
32+ if ( sound . audioContainer === '' || sound . duration === 0 ) {
33+ console . log ( 'updating meta data' )
34+ const meta = await parseFile (
35+ path . join ( process . cwd ( ) , 'public' , 'sounds' , sound . fileName )
36+ )
37+
38+ await prisma . audio . update ( {
39+ where : { id : sound . id } ,
40+ data : {
41+ duration : meta . format . duration ,
42+ audioContainer : meta . format . container
43+ }
44+ } )
45+
46+ sound . audioContainer = meta . format . container ? meta . format . container : ''
47+ sound . duration = meta . format . duration ? meta . format . duration : 0
48+ }
49+
3050 return { sound}
3151}
3252
@@ -41,6 +61,8 @@ const Sound = () => {
4161 < source src = { `/sounds/${ sound . fileName } ` } type = "audio/mp3" />
4262 </ audio >
4363 < p > Ringer Wire: { sound . ringerWire } </ p >
64+ < p > Duration: { getSecondsAsTime ( sound . duration ) } </ p >
65+ < p > Audio Type: { sound . audioContainer } </ p >
4466 </ div >
4567 < Actions
4668 actions = { [
0 commit comments