forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Read and write id3 (mp3) tags...

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 5 Units
View previous topic :: View next topic  
Author Message
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Tue Jan 20, 2004 7:00 pm    Post subject: Read and write id3 (mp3) tags... Reply with quote

Here is a little function which can read and write id3 tags in mp3 files. It's just a remake of some old examples I found and has been optimised to VDS 5... Smile

Code:
#define function,id3
#define command,id3

# @id3(read,<filename>,{<TITLE|ARTIST|ALBUM|YEAR|COMMENT|GENRE>})
# id3 write,<filename>,<title>,<artist>,<album>,<year>,<comment>,<genre>

:id3

if @equal(@trim(%1),READ)
  %%File = @trim(%2)
  binfile open,1,%%File,read
  binfile seek,1,@diff(@binfile(size,1),128)
  %%BinFileData = @trim(@binfile(read,1,text,128))
  while @greater(@pos(".",%%BinFileData),0)
    %%BinFileData = @substr(%%BinFileData,1,@pred(@pos(".",%%BinFileData)))" "@substr(%%BinFileData,@succ(@pos(".",%%BinFileData)),@len(%%BinFileData))
  wend
  %%BinFileTag     = @trim(@substr(%%BinFileData,1,3))
  %%BinFileTitle   = @trim(@substr(%%BinFileData,4,33))
  %%BinFileArtist  = @trim(@substr(%%BinFileData,34,63))
  %%BinFileAlbum   = @trim(@substr(%%BinFileData,64,93))
  %%BinFileYear    = @trim(@substr(%%BinFileData,94,97))
  %%BinFileComment = @trim(@substr(%%BinFileData,98,127))
  %%BinFileGenre   = @trim(@substr(%%BinFileData,128,128))
  binfile close,1
  if @equal(@trim(%3),TAG)
    exit %%BinFileTag
  elsif @equal(@trim(%3),TITLE)
    exit %%BinFileTitle
  elsif @equal(@trim(%3),ARTIST)
    exit %%BinFileArtist
  elsif @equal(@trim(%3),ALBUM)
    exit %%BinFileAlbum
  elsif @equal(@trim(%3),YEAR)
    exit %%BinFileYear
  elsif @equal(@trim(%3),COMMENT)
    exit %%BinFileComment
  elsif @equal(@trim(%3),GENRE)
    exit %%BinFileGenre
    else
    exit %%BinFileData
    end
  end

if @equal(@trim(%1),WRITE)
  %%File = @trim(%2)
  %%BinFileTag     = TAG
  %%BinFileTitle   = @trim(%3)
  %%BinFileArtist  = @trim(%4)
  %%BinFileAlbum   = @trim(%5)
  %%BinFileYear    = @trim(%6)
  %%BinFileComment = @trim(%7)
  %%BinFileGenre   = @trim(%8 )
 
  binfile open,1,%%File,write
  binfile seek,1,@diff(@binfile(size,1),128)
   
  binfile write,1,text,TAG

  %%BinFileItemLength = 30
  if @greater(@len(%%BinFileTitle),0)
    binfile write,1,text,@substr(%%BinFileTitle,1,%%BinFileItemLength)
    end
  %%BinFileItemLength = @diff(%%BinFileItemLength,@len(%%BinFileTitle))
  while @greater(%%BinFileItemLength,0)
    binfile write,1,binary,0|
    %%BinFileItemLength = @pred(%%BinFileItemLength)
  wend

  %%BinFileItemLength = 30
  if @greater(@len(%%BinFileArtist),0)
    binfile write,1,text,@substr(%%BinFileArtist,1,%%BinFileItemLength)
    end
  %%BinFileItemLength = @diff(%%BinFileItemLength,@len(%%BinFileArtist))
  while @greater(%%BinFileItemLength,0)
    binfile write,1,binary,0|
    %%BinFileItemLength = @pred(%%BinFileItemLength)
  wend

  %%BinFileItemLength = 30
  if @greater(@len(%%BinFileAlbum),0)
    binfile write,1,text,@substr(%%BinFileAlbum,1,%%BinFileItemLength)
    end
  %%BinFileItemLength = @diff(%%BinFileItemLength,@len(%%BinFileAlbum))
  while @greater(%%BinFileItemLength,0)
    binfile write,1,binary,0|
    %%BinFileItemLength = @pred(%%BinFileItemLength)
  wend

  %%BinFileItemLength = 4
  if @greater(@len(%%BinFileYear),0)
    binfile write,1,text,@substr(%%BinFileYear,1,%%BinFileItemLength)
    end
  %%BinFileItemLength = @diff(%%BinFileItemLength,@len(%%BinFileYear))
  while @greater(%%BinFileItemLength,0)
    binfile write,1,binary,0|
    %%BinFileItemLength = @pred(%%BinFileItemLength)
  wend

  %%BinFileItemLength = 30
  if @greater(@len(%%BinFileComment),0)
    binfile write,1,text,@substr(%%BinFileComment,1,%%BinFileItemLength)
    end
  %%BinFileItemLength = @diff(%%BinFileItemLength,@len(%%BinFileComment))
  while @greater(%%BinFileItemLength,0)
    binfile write,1,binary,0|
    %%BinFileItemLength = @pred(%%BinFileItemLength)
  wend

  if @not(%%BinFileGenre)
    %%BinFileGenre = 255
    end
  binfile write,1,binary,%%BinFileGenre|

  binfile close,1
  end

exit

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!


Last edited by Skit3000 on Sun Aug 17, 2008 12:48 pm; edited 1 time in total
Back to top
View user's profile Send private message
uvedese
Contributor
Contributor


Joined: 21 Jan 2006
Posts: 169
Location: Spain

PostPosted: Thu Jul 31, 2008 5:49 pm    Post subject: Reply with quote

Hi Skit3000 Very Happy

I am working on a multimedia application and I was looking for an id3 tag reader.

Your code works fine but I don't know why not read the music genre tag (code is OK!!! ) No clue

Why not read the musical genre (last byte)? Stupid

Thank in advance.
_______________

uVeDeSe
_______________
Back to top
View user's profile Send private message Visit poster's website
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Thu Jul 31, 2008 7:19 pm    Post subject: Reply with quote

Well add the code that you need then. Here's a brief of the id3 specs:

Code:
Strings are either space- or zero-padded. Unset string entries are filled using an empty string.
ID3v1: 128 bytes
 
Field   Length   Description      
header   3   "TAG"      
title   30   30 characters of the title      
artist   30   30 characters of the artist name      
album   30   30 characters of the album name      
year   4   A four-digit year      
comment   28[1] or 30   The comment.      
zero-byte[1]   1   If a track number is stored, this byte contains a binary 0.      
track[1]   1   The number of the track on the album, or 0. Invalid, if previous byte is not a binary 0.      
genre   1   Index in a list of genres, or 255   
Extended tag (placed before the ID3v1 tag): 227 bytes
 
Field   Length   Description      
header   4   "TAG+"      
title   60   Next 60 characters of the title (90 characters total)      
artist   60   Next 60 characters of the artist name      
album   60   Next 60 characters of the album name      
speed   1   0=unset, 1=slow, 2= medium, 3=fast, 4=hardcore      
genre   30   A free-text field for the genre      
start-time   6   the start of the music as mmm:ss      
end-time   6   the end of the music as mmm:ss   

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Thu Jul 31, 2008 8:49 pm    Post subject: Reply with quote

From what I can read Skit's code does read/write the genre?
_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Sun Aug 17, 2008 12:47 pm    Post subject: Reply with quote

It does, but it seems that the emoticons messed up the code a little. Changed it now for good displaying... Wink
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
uvedese
Contributor
Contributor


Joined: 21 Jan 2006
Posts: 169
Location: Spain

PostPosted: Sun Aug 17, 2008 1:04 pm    Post subject: Reply with quote

I changed the emoticons but still it does not work.

Question Question Question
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 5 Units All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group