rendered paste bodyrequire "vstruct"print("FLAC reader")file = "/media/sdc1/Random Downloaded/07 - spirit in the sky.flac"print(file)fd = io.open ( file , r )s = fd:read ( 4 )--fileinfo = { }if s == "fLaC" then filetyp = "flac" t = vstruct.unpack ( fd , ">b1u3" ) lastmetadatablock = t [ 1 ] blocktype = t [ 2 ] blocklength = t [ 3 ] -- Is in bytes if blocktype == 0 then -- Stream info t = vstruct.unpack ( fd , ">u2u2u3u3" ) minblocksize = t [ 1 ] maxblocksize = t [ 2 ] minframesize = t [ 3 ] maxframesize = t [ 4 ] samplerate = t [ 5 ] channels = t [ 6 ] + 1 bitspersample = t [ 7 ] totalsamples = t [ 8 ] md5rawaudio = t [ 9 ] elseif blocktype == 1 then -- Padding t = vstruct.unpack ( fd , ">x" .. blocklength ) elseif blocktype == 2 then -- Application t = vstruct.unpack ( fd , ">u4s" .. ( blocklength - 4 ) ) appID = t [ 1 ] appdata = t [ 2 ] elseif blocktype == 3 then -- Seektable t = vstruct.unpack ( fd , ">x" .. blocklength ) -- We don't deal with seektables, skip over it elseif blocktype == 4 then -- Vorbis_Comment http://www.xiph.org/vorbis/doc/v-comment.html t = vstruct.unpack ( fd , "<u4" ) vendor_length = t [ 1 ] t = vstruct.unpack ( fd , "<s" .. vendor_length .. "u4" ) vendor_string = t [ 1 ] user_comment_list_length = t [ 2 ] comment = { } tags = { } for i = 1 , ( user_comment_list_length + 1 ) do t = vstruct.unpack ( fd , "<u4" ) local length = t [ 1 ] t = vstruct.unpack ( fd , "<s" .. length ) comment [ i ] = t [ 1 ] local fieldname , value = string.match ( comment [ i ] , "([^=]+)=(.+)") tags [ fieldname ] = tags [ fieldname ] or { } table.insert ( tags [ fieldname ] , value ) end elseif blocktype == 5 then -- Cuesheet t = vstruct.unpack ( fd , ">s128u8x259x1x" .. ( blocklength - ( 128 + 8 + 259 + 1 ) ) ) -- cbf, TODO: cuesheet reading elseif blocktype == 6 then -- Picture t = vstruct.unpack ( fd , ">u4u4" ) picturetype = t [ 1 ] mimelength = t [ 2 ] t = vstruct.unpack ( fd , ">s" .. mimelength .. "u4" ) mimetype = t [ 1 ] descriptionlength = t [ 2 ] t = vstruct.unpack ( fd , ">s" .. descriptionlength .. "u4u4u4u4u4" ) width = t [ 1 ] height = t [ 2 ] colourdepth = t [ 3 ] numberofcolours = t [ 4 ] picturelength = t [ 5 ] t = vstruct.unpack ( fd , ">s" .. picturelength ) picturedata = t [ 1 ] end for i,v in pairs ( t ) do print (i,v) endendfd:close ( )