|
|
Get and Set IDTag3 II of a mp3 file.
Added on 8/26/2002
|
Compatibilities:
|
This item has not yet been rated
|
For Lingo only support IDTag3 II, I have made tow funtions based on fileIO Xtra and a custom function copystr() to get and set IDTag3 II of a mp3 file. I am lazy and have little time,I didn't made it a perfect completed one.you can make further develop by yourself .~_~
--put AGGetID3tags(the moviepath&"music.mp3")
-- [#track: 1, #title: "情深深雨濛濛", #artist: "赵薇", #album: "情深深雨濛濛", #year: "2001", #genre: 34, #comment: "情深深雨濛濛", #mpeginfo: [#size: 4568293, #length: 286171, #layer: 3]]
on AGGetID3tags ffilename
tlist=[#Track: 0, #Title:"",#Artist:"",#Album:"",#Year:"",#Genre: 0, #Comment:"", #MpegInfo:[#Size: 0,#Length: 0,#Layer: 0]]
tfileio=new(xtra"fileio")
openfile(tfileio,ffilename,1)
tlength= getLength(tfileio)
----------------
tpos=tlength-128
setPosition(tfileio,tpos)
tstr=""
repeat with i=tpos to tpos+2
tchar= readchar(tfileio)
if tchar="" then exit repeat
put tchar after tstr
end repeat
if tstr<>"TAG" then return tlist
---------------
tpos=tpos+3
setPosition(tfileio,tpos)
tstr=""
repeat with i=tpos to tpos+29
tchar= readchar(tfileio)
if tchar="" then exit repeat
put tchar after tstr
end repeat
tlist.Title=copystr(tstr,1,30)
---------------
tpos=tpos+30
setPosition(tfileio,tpos)
tstr=""
repeat with i=tpos to tpos+29
tchar= readchar(tfileio)
if tchar="" then exit repeat
put tchar after tstr
end repeat
tlist.Artist=copystr(tstr,1,30)
---------------
tpos=tpos+30
setPosition(tfileio,tpos)
tstr=""
repeat with i=tpos to tpos+29
tchar= readchar(tfileio)
if tchar="" then exit repeat
put tchar after tstr
end repeat
tlist.Album=copystr(tstr,1,30)
---------------
tpos=tpos+30
setPosition(tfileio,tpos)
tstr=""
repeat with i=tpos to tpos+3
tchar= readchar(tfileio)
if tchar="" then exit repeat
put tchar after tstr
end repeat
tlist.Year=copystr(tstr,1,4)
---------------
tpos=tpos+4
setPosition(tfileio,tpos)
tstr=""
repeat with i=tpos to tpos+27
tchar= readchar(tfileio)
if tchar="" then exit repeat
put tchar after tstr
end repeat
tlist.Comment=copystr(tstr,1,28)
---------------
tpos=tpos+29
setPosition(tfileio,tpos)
tchar= readchar(tfileio)
tlist.Track=chartonum(tchar)
---------------
tpos=tpos+1
setPosition(tfileio,tpos)
tchar= readchar(tfileio)
tlist.Genre=chartonum(tchar)
---------------
--mpeginfo
tmember=new(#sound)
tmember.filename=ffilename
tlist.MpegInfo.Size=tlength
tlist.MpegInfo.Length=tmember.duration
tlist.MpegInfo.Layer=3
tmember.erase()
closefile(tfileio)
tfileio=0
return tlist
end
--taginfo=[#track: 1, #title: "情深深雨濛濛", #artist: "赵薇", #album: "情深深雨濛濛", #year: "2001", #genre: 34, #comment: "情深深雨濛濛"]
--AGWriteID3tags(the moviepath&"music.mp3",taginfo)
--put AGGetID3tags(the moviepath&"music.mp3")
-- [#track: 1, #title: "情深深雨濛濛", #artist: "赵薇", #album: "情深深雨濛濛", #year: "2001", #genre: 34, #comment: "情深深雨濛濛", #mpeginfo: [#size: 4568293, #length: 286171, #layer: 3]]
on AGWriteID3tags ffilename,flist
tfileio=new(xtra"fileio")
openfile(tfileio,ffilename,0)
tlength= getLength(tfileio)
----------------
tpos=tlength-128
setPosition(tfileio,tpos)
tstr=""
repeat with i=tpos to tpos+2
tchar= readchar(tfileio)
if tchar="" then exit repeat
put tchar after tstr
end repeat
if tstr<>"TAG" then
tpos=tlength
setPosition(tfileio,tpos)
writeString(tfileio,"TAG")
end if
---------------
tpos=tpos+3
ttpos=tpos
repeat with i=1 to 30
writeChar(tfileio,"")
ttpos=ttpos+1
setPosition(tfileio,ttpos)
end repeat
setPosition(tfileio,tpos)
writeString(tfileio,copystr(flist.Title,1,30))
---------------
tpos=tpos+30
ttpos=tpos
repeat with i=1 to 30
writeChar(tfileio,"")
ttpos=ttpos+1
setPosition(tfileio,ttpos)
end repeat
setPosition(tfileio,tpos)
writeString(tfileio,copystr(flist.artist,1,30))
---------------
tpos=tpos+30
ttpos=tpos
repeat with i=1 to 30
writeChar(tfileio,"")
ttpos=ttpos+1
setPosition(tfileio,ttpos)
end repeat
setPosition(tfileio,tpos)
writeString(tfileio,copystr(flist.album,1,30))
---------------
tpos=tpos+30
ttpos=tpos
repeat with i=1 to 4
writeChar(tfileio,"")
ttpos=ttpos+1
setPosition(tfileio,ttpos)
end repeat
setPosition(tfileio,tpos)
writeString(tfileio,copystr(flist.year,1,4))
---------------
tpos=tpos+4
ttpos=tpos
repeat with i=1 to 28
writeChar(tfileio,"")
ttpos=ttpos+1
setPosition(tfileio,ttpos)
end repeat
setPosition(tfileio,tpos)
writeString(tfileio,copystr(flist.comment,1,28))
---------------
tpos=tpos+29
setPosition(tfileio,tpos)
writeString(tfileio,numtochar(flist.Track))
---------------
tpos=tpos+1
setPosition(tfileio,tpos)
writeString(tfileio,numtochar(flist.Genre))
---------------
closefile(tfileio)
tfileio=0
end
--function needed
on copystr fstr,fstart,fend
if fstart>fend then return ""
a=fstr.char.count
tpos=0
tstr=""
repeat with i=1 to a
t=fstr.char[i]
if chartonum(t)>=10000 then
tpos=tpos+2
else if chartonum(t)<999 then
tpos=tpos+1
end if
if tpos>=fstart and tpos<=fend then
put t after tstr
end if
end repeat
return tstr
end
|
|