4

I'm a student from Portugal having some doubts about a project I have to handle.

My final objective is to create a pdf catalog with LaTeX that stores information about files using exiftool.

So far, i've managed to separate audio from video files and store their exiftool'ed information on a file, but it bulks them up.

for example:

======== 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'd like to do is : first, try to split the two songs on that file in some kind of list of some sort. then, try and pick up some of the information inside a file, like the FileName, Size and all that.

So far, i've come up with this piece of code, but it isnt correct:

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 anyone give me a hint? I want to store some information on a File structure i've created, but first, i need to split it up by songs, then pick up what I want, right?

THanks for the help and excuse me for my bad french!

PS: I'm not that used to haskell (just starting)

1 Answers1

6

A minimal fix is:

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 m a where m is a monad and a is an arbitrary type. readFile returns a monadic value (of type IO String) but splitRegex accepts a plain value of type String. So arrow can be used to extract a String from IO String. But splitRegex returns a non-monadic value so <- cannot extract anything from it.

I suggest to split your code into IO code and non-IO code 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

So IO code will use do and <- and non-IO code will use where and =.

nponeccop
  • 13,527
  • 1
  • 44
  • 106