Displaying text files in Creative MuVo mp3 player

Creative MuVo is an old mp3 player that has a small monochromatic display, but normally is unable to display any files on it. I forced it to display them by expoiting its ability to show lyric of currently played song.

Displaying text files in old mp3 player Displaying text files in old mp3 player Displaying text files in old mp3 player

Following simple script in Haskell takes as input path to the text file that should be displayed and path to mp3 file stored on mp3 player. As an output it produces lyric file that can be read by player.

Lyric file generated by script needs to be copied to LRC directory on player, this may be simplified by putting script in mentioned directory (player doesn't complain about it).

import System.Environment
import System.IO
import Control.Exception
import System.FilePath.Posix

main = do
    args <- getArgs
    let sourceFile : mp3File: _ = args
    let lrcFile = (takeBaseName (takeFileName mp3File)) ++ ".lrc"
    bracket (openFile sourceFile ReadMode) hClose 
        (\hIn -> 
            bracket (openFile lrcFile WriteMode) hClose 
                (\hOut -> parseMe hIn hOut 0))

parseMe :: Handle -> Handle -> Integer -> IO()
parseMe hIn hOut time = do
    isEOF <- hIsEOF hIn
    if isEOF then return() else do
        line <- hGetLine hIn
        let secs' = mod time 60
            mins' = div time 60
            -- we neeed time in form [mm:ss] that's why we add zeros
            secs = (if secs' < 10 then "0" else "") ++ show(secs')
            mins = (if mins' < 10 then "0" else "") ++ show(mins') 
            in hPutStrLn hOut ("[" ++ mins ++ ":" ++ secs ++ "]" ++ line)
        parseMe hIn hOut (time + 4)

example of output file:
[00:08] * Copyright (C) Igor Sysoev
[00:12] */
[00:24]#ifndef _NGX_OS_H_INCLUDED_
[00:28]#define _NGX_OS_H_INCLUDED_

0 commentaires:

Post a Comment