WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Sound and Media

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

MP3 Tagger Sample Code

Keywords:   mp3 tagger

From: Guido sedar@yahoo.com

And now... the ultimate tagger utility! :), now displays all the tag in a askfiletext and supports the 80 genres that are in the link, to delete a part of the tag select it and donīt type a nything, put the file genre.txt in the same directory of the script.


MP3TAGGER.WBT

;del buffers
del30=binaryalloc(30)
for x=0 to 29
BinaryPoke(del30, x, 0)
next x
del4=binaryalloc(4)
for y=0 to 3
BinaryPoke(del4, y, 0)
next y

;
fs1 = FileSize("genre.txt")
binbuf1 = binaryalloc( fs1)
BinaryRead(binbuf1, "genre.txt")
;
dir=ShortCutDir("Desktop")
origdir=dirget()

:sel
types="MP3|*.*|"
mp3=AskFileName(" Select MP3 :", dir, types, "", 1)

FileAttrSet (mp3, "r")
size=filesize(mp3)

;search for TAGv1
tag=binaryalloc(3)
binaryreadex(tag,0,mp3,size-128,3)
id3=binarypeekstr(tag,0,3)
binaryfree(tag)
if id3<>"TAG"
q=askyesno(" MP3Tagger", "TAGv1 not present, create it?") 
if q==@yes then gosub create
else goto sel
endif
;

;edit tag
;read old tag
oldtag=binaryalloc(125)
BinaryReadEx(oldtag, 0, mp3, size-125, 125)
otitle=BinaryPeekStr(oldtag, 0, 30)
oartist=BinaryPeekStr(oldtag, 30, 30)
oalbum=BinaryPeekStr(oldtag, 60, 30)
oyear=BinaryPeekStr(oldtag, 90, 4)
ocomment=BinaryPeekStr(oldtag, 94, 30)

;read genre
;genre value
genre=BinaryPeek(oldtag, 124)
if genre>79
ogenre=""
goto text
endif

;genre name (ogenre)
z=0
n=-1
while genre<>n
a = BinaryIndex(binbuf1, z, @CRLF, @FWDSCAN)
a=a+2
n=n+1
z=a
if n==genre  
b=BinaryIndex(binbuf1, a, @CRLF, @FWDSCAN)
ogenre=BinaryPeekStr(binbuf1, a, b-a)
endif
endwhile

;Write txt file
:text
handle=fileopen("%origdir%\tag.txt","WRITE")
filewrite(handle,"Title: %otitle% %@crlf%Artist: %oartist% %@crlf%Album: %oalbum% %@crlf%Year: %oyear% %@crlf%Genre: %ogenre% %@crlf%Comment: %ocomment%")
fileclose(handle)


:ask
ask=askfiletext(" Select : ","%origdir%\tag.txt", @unsorted, @single)
if ask=="" then goto write
pos=StrIndex (ask, ":", 1, @FWDSCAN)
askx=StrFixChars(ask, "", pos-1)


if askx=="Title" 
ntitle=AskLine("Title : %otitle%", "Enter title (max 30 char.)", "")
if ntitle=="" 
BinaryCopy(oldtag, 0, del30, 0, 30)
otitle=""
goto text
else
BinaryCopy(oldtag, 0, del30, 0, 30)
binarypokestr(oldtag,0,ntitle)
otitle=ntitle
goto text
endif
endif

if askx=="Artist" 
nartist=AskLine("Artist : %oartist%", "Enter artist (max 30 char.)", "")
if nartist==""
BinaryCopy(oldtag, 30, del30, 0, 30)
oartist=""
goto text
else
BinaryCopy(oldtag, 30, del30, 0, 30)
binarypokestr(oldtag,30,nartist)
oartist=nartist
goto text
endif
endif

if askx=="Album" 
nalbum=AskLine("Album : %oalbum%", "Enter album (max 30 char.)", "")
if nalbum==""
BinaryCopy(oldtag, 60, del30, 0, 30)
oalbum=""
goto text
else
BinaryCopy(oldtag, 60, del30, 0, 30)
binarypokestr(oldtag,60,nalbum)
oalbum=nalbum
goto text
endif
endif

if askx=="Year" 
nyear=AskLine("Year : %oyear%", "Enter year (max 4 char.)", "")
if nyear==""
BinaryCopy(oldtag, 90, del4, 0, 4)
oyear=""
goto text
else
BinaryCopy(oldtag, 90, del4, 0, 4)
binarypokestr(oldtag,90,nyear)
oyear=nyear
goto text
endif
endif

if askx=="Comment" 
ncomment=AskLine("Comment : %ocomment%", "Enter comment (max 30 char.)", "")
if ncomment==""
BinaryCopy(oldtag, 94, del30, 0, 30)
ocomment=""
goto text
else
BinaryCopy(oldtag, 94, del30, 0, 30)
binarypokestr(oldtag,94,ncomment)
ocomment=ncomment
goto text
endif
endif


;genre
if askx=="Genre" 
ngenre=AskFileText("Genre : %ogenre%", "genre.txt", @sorted, @single)
if ngenre==""
binarypoke(oldtag,124,255)
ogenre=""
goto text
endif


;get genre value (n)
z=0
n=-1
xx=""
while ngenre<>xx
a = BinaryIndex(binbuf1, z, @CRLF, @FWDSCAN)
a=a+2
n=n+1
z=a
b=BinaryIndex(binbuf1, a, @CRLF, @FWDSCAN)
xx=BinaryPeekStr(binbuf1, a, b-a)
endwhile
if ngenre<>"" 
binarypoke(oldtag,124,n)
ogenre=ngenre
goto text
else 
goto ask
endif


:write
;write new tag
binarywriteex(oldtag,0,mp3,size-125,125)
;
message("","Done")
;
binaryfree(oldtag)
goto sel

;create  null tag
:create
null=binaryalloc(128)
for z=0 to 126
binarypoke(null,z,0)
next z
binarypokestr(null,0,"TAG")
binarypoke(null,127,255)
binarywriteex(null,0,mp3,size,128)
binaryfree(null)
;
size=size+128
return

GENRE.TXT

Note that the 1st line of the genre.txt must be a blank line.

Blues
Classic Rock
Country
Dance
Disco
Funk
Grunge
Hip-Hop
Jazz
Metal
New Age
Oldies
Other
Pop
R&B
Rap
Reggae
Rock
Techno
Industrial
Alternative
Ska
Death Metal
Pranks
Soundtrack
Euro-Techno
Ambient
Trip-Hop
Vocal
Jazz+Funk
Fusion
Trance
Classical
Instrumental
Acid
House
Game
Sound Clip
Gospel
Noise
AlternRock
Bass
Soul
Punk
Space
Meditative
Instrumental Pop
Instrumental Rock
Ethnic
Gothic
Darkwave
Techno-Industrial
Electronic
Pop-Folk
Eurodance
Dream
Southern Rock
Comedy
Cult
Gangsta
Top 40
Christian Rap
Pop/Funk
Jungle
Native American
Cabaret
New Wave
Psychadelic
Rave
Showtunes
Trailer
Lo-Fi
Tribal
Acid Punk
Acid Jazz
Polka
Retro
Musical
Rock & Roll
Hard Rock

Article ID:   W14970
File Created: 2001:11:08:12:41:14
Last Updated: 2001:11:08:12:41:14