Haskell manipulates file contents

I am from Portugal, I have doubts about a project that I have to deal with.

My ultimate goal is to create a pdf directory with LaTeX that stores file information using exiftool.

So far, I have been able to separate the sound from the video files and save their exiftool information in a file, but it expands them.

eg:

======== Cartoon Battle.mp3 -ExifToolVersion=8.60 -FileName=Cartoon Battle.mp3 -Directory=. -FileSize=4.0 MB -FileModifyDate=2011:12:13 09:46:25+00:00 -FilePermissions=rw-rw-r-- -FileType=MP3 -MIMEType=audio/mpeg -MPEGAudioVersion=1 -AudioLayer=3 -AudioBitrate=320 kbps -SampleRate=48000 -ChannelMode=Stereo -MSStereo=Off -IntensityStereo=Off -CopyrightFlag=False -OriginalMedia=False -Emphasis=None -ID3Size=113441 -Title=Cartoon Battle -Artist=Kevin MacLeod -Year=2007 -BeatsPerMinute=130 -Genre=Unclassifiable -Comment=(iTunPGAP) 0 -EncodedBy=iTunes v7.0.2.16 -Comment=(iTunNORM) 000001F7 0000014B 00001DBD 00000B18 000154C8 00000780 00008169 00008180 00000780 00000780 -Comment=(iTunSMPB) 00000000 00000210 00000A84 00000000004A606C 00000000 003DE780 00000000 00000000 00000000 00000000 00000000 00000000 -Album=Far East -Composer=Kevin MacLeod -PictureFormat=JPG -PictureType=Other -PictureDescription= -Picture=(Binary data 91855 bytes, use -b option to extract) -DateTimeOriginal=2007 -Duration=0:01:41 (approx) ======== Comic Plodding.mp3 -ExifToolVersion=8.60 -FileName=Comic Plodding.mp3 -Directory=. -FileSize=3.8 MB -FileModifyDate=2011:12:13 09:46:24+00:00 -FilePermissions=rw-rw-r-- -FileType=MP3 -MIMEType=audio/mpeg -MPEGAudioVersion=1 -AudioLayer=3 -AudioBitrate=320 kbps -SampleRate=44100 -ChannelMode=Joint Stereo -MSStereo=Off -IntensityStereo=Off -CopyrightFlag=False -OriginalMedia=False -Emphasis=None -ID3Size=105099 -EncoderSettings=Logic Pro 8.0.1 -Comment=(iTunNORM) 000001AE 00000181 000026DF 0000365B 0001100A 00016CE5 00007D33 00007ECF 00010FF0 00016CE5 -Comment=(iTunSMPB) 00000000 00000210 000009D6 000000000040DA1A 00000000 003ABCBC 00000000 00000000 00000000 00000000 00000000 00000000 -Artist=Kevin MacLeod -Composer=Kevin MacLeod -Year=2008 -Genre=Silent Film Score -PictureFormat=JPG -PictureType=Other -PictureDescription= -Picture=(Binary data 84880 bytes, use -b option to extract) -Album=Scoring - Silent Film: Dark -DateTimeOriginal=2008 -Duration=0:01:36 (approx) 

What I want to do: first, try to split the two songs in this file in some list. then try to collect some information inside the file, such as FileName, Size and all that.

So far I have come up with this piece of code, but this is not true:

 mymain = do{ a <- readFile "audio.txt" ; -- file that has all the infos collected by exiftool ml <- splitRegex (mkRegex "========") a ; -- I expect this to separate each song and place their corresponding information on a single string 

Can someone tell me? I want to keep some information about the file structure that I created, but first I need to break it down into songs, and then choose what I want, right?

Thanks for the help and sorry for my bad french!

PS: I'm not used to haskell (just the beginning)

+4
source share
1 answer

Minimal fix:

 import Text.Regex main = do { a <- readFile "audio.txt" ; print $ splitRegex (mkRegex "========") a ; } 

The arrow extracts a value from a monadic value - from a value of type ma , where m is a monad and a is an arbitrary type. readFile returns a monadic value (of type IO String ), but splitRegex accepts a simple value of type String . Thus, the arrow can be used to retrieve a String from an IO String . But splitRegex returns a non-monodic value, so <- cannot extract anything from it.

I suggest breaking the code into I / O code and code without I / O and use the syntax without ; and {} :

 import Text.Regex processData text = x where x = splitRegex (mkRegex "========") y y = text ... main = do a <- readFile "audio.txt" print $ processData a 

Thus, the IO code will use do and <- , and non-IO code will use where and = .

+6
source

Source: https://habr.com/ru/post/1386335/


All Articles