Haskell 操作文件内容
我是一名来自葡萄牙的学生,对我必须处理的项目有一些疑问。
我的最终目标是使用 LaTeX 创建一个 pdf 目录,使用 exiftool 存储有关文件的信息。
到目前为止,我已经设法将音频从视频文件中分离出来,并将其经过 exiftool 处理的信息存储在一个文件中,但它会使它们变大。
例如:
======== 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)
我想做的是: 首先,尝试将该文件中的两首歌曲拆分为某种列表。 然后,尝试获取文件内的一些信息,例如文件名、大小等等。
到目前为止,我已经想出了这段代码,但它不正确:
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
任何人都可以给我提示吗?我想在我创建的文件结构上存储一些信息,但首先,我需要按歌曲将其拆分,然后选择我想要的,对吧?
感谢您的帮助,请原谅我的法语不好!
PS:我不太习惯haskell(刚刚开始)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最小的修复是:
箭头从单子值中提取值 - 从
m a
类型的值,其中m
是单子,a
是任意类型。readFile
返回一个单子值(IO String
类型),但splitRegex
接受String
类型的纯值。因此箭头可用于从IO String
中提取String
。但是 splitRegex 返回一个非单值值,因此<-
无法从中提取任何内容。我建议将您的代码拆分为 IO 代码和非 IO 代码,并使用不带
;
和{}
的语法:因此 IO 代码将使用
do
和<-
以及非 IO 代码将使用where
和=
。A minimal fix is:
The arrow extracts a value from a monadic value - from a value of type
m a
wherem
is a monad anda
is an arbitrary type.readFile
returns a monadic value (of typeIO String
) butsplitRegex
accepts a plain value of typeString
. So arrow can be used to extract aString
fromIO String
. ButsplitRegex
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{}
:So IO code will use
do
and<-
and non-IO code will usewhere
and=
.