Below you'll find the source for the Visual Basic 6 function id3v1_get_tag.
Attribute VB_Name = "modId3v1GetTag"
' These functions are downloaded from:
' http://www.stefanthoolen.nl/archive/vb6-functions/
'
' You may freely distribute this file but please leave all comments, including this one, in it.
'
' @Author Stefan Thoolen <mail@stefanthoolen.nl>
Option Explicit
' Used to send back the ID3 tag to the application
' This is different from id3v1_file_footer since this type does not have string lengths defined
' Also some reformatting has been done so usage will be more user friendly
Public Type id3v1_tag
has_tag As Boolean
artist As String
title As String
album As String
year As String
has_trackno As Boolean
trackno As Byte
comment As String
genre_id As Byte
genre_text As String
speed As Byte
End Type
' Used to read the ID3 tag from the file
Private Type id3v1_file_footer
Ext_Header As String * 4
Ext_Title As String * 60
Ext_Artist As String * 60
Ext_Album As String * 60
Ext_Speed As Byte
Ext_Genre As String * 30
Ext_StartTime As String * 6
Ext_EndTime As String * 6
header As String * 3
SongTitle As String * 30
artist As String * 30
album As String * 30
year As String * 4
comment As String * 28
ZeroByte As Byte
trackno As Byte
genre As Byte
End Type
''
' Returns the name of a genre number
' @param Byte id The number of the genre
' @return String The name of the genre
' @author Stefan Thoolen <mail@stefanthoolen.nl>
Public Function id3_genre_name(id As Byte) As String
Dim genre As String
Select Case id
Case 0: genre = "Blues"
Case 1: genre = "Classic Rock"
Case 2: genre = "Country"
Case 3: genre = "Dance"
Case 4: genre = "Disco"
Case 5: genre = "Funk"
Case 6: genre = "Grunge"
Case 7: genre = "Hip-Hop"
Case 8: genre = "Jazz"
Case 9: genre = "Metal"
Case 10: genre = "New Age"
Case 11: genre = "Oldies"
Case 12: genre = "Other"
Case 13: genre = "Pop"
Case 14: genre = "R&B"
Case 15: genre = "Rap"
Case 16: genre = "Reggae"
Case 17: genre = "Rock"
Case 18: genre = "Techno"
Case 19: genre = "Industrial"
Case 20: genre = "Alternative"
Case 21: genre = "Ska"
Case 22: genre = "Death Metal"
Case 23: genre = "Pranks"
Case 24: genre = "Soundtrack"
Case 25: genre = "Euro-Techno"
Case 26: genre = "Ambient"
Case 27: genre = "Trip-Hop"
Case 28: genre = "Vocal"
Case 29: genre = "Jazz+Funk"
Case 30: genre = "Fusion"
Case 31: genre = "Trance"
Case 32: genre = "Classical"
Case 33: genre = "Instrumental"
Case 34: genre = "Acid"
Case 35: genre = "House"
Case 36: genre = "Game"
Case 37: genre = "Sound Clip"
Case 38: genre = "Gospel"
Case 39: genre = "Noise"
Case 40: genre = "AlternRock"
Case 41: genre = "Bass"
Case 42: genre = "Soul"
Case 43: genre = "Punk"
Case 44: genre = "Space"
Case 45: genre = "Meditative"
Case 46: genre = "Instrumental Pop"
Case 47: genre = "Instrumental Rock"
Case 48: genre = "Ethnic"
Case 49: genre = "Gothic"
Case 50: genre = "Darkwave"
Case 51: genre = "Techno-Industrial"
Case 52: genre = "Electronic"
Case 53: genre = "Pop-Folk"
Case 54: genre = "Eurodance"
Case 55: genre = "Dream"
Case 56: genre = "Southern Rock"
Case 57: genre = "Comedy"
Case 58: genre = "Cult"
Case 59: genre = "Gangsta"
Case 60: genre = "Top 40"
Case 61: genre = "Christian Rap"
Case 62: genre = "Pop/Funk"
Case 63: genre = "Jungle"
Case 64: genre = "Native American"
Case 65: genre = "Cabaret"
Case 66: genre = "New Wave"
Case 67: genre = "Psychadelic"
Case 68: genre = "Rave"
Case 69: genre = "Showtunes"
Case 70: genre = "Trailer"
Case 71: genre = "Lo-Fi"
Case 72: genre = "Tribal"
Case 73: genre = "Acid Punk"
Case 74: genre = "Acid Jazz"
Case 75: genre = "Polka"
Case 76: genre = "Retro"
Case 77: genre = "Musical"
Case 78: genre = "Rock & Roll"
Case 79: genre = "Hard Rock"
Case 80: genre = "Folk"
Case 81: genre = "Folk-Rock"
Case 82: genre = "National Folk"
Case 83: genre = "Swing"
Case 84: genre = "Fast Fusion"
Case 85: genre = "Bebob"
Case 86: genre = "Latin"
Case 87: genre = "Revival"
Case 88: genre = "Celtic"
Case 89: genre = "Bluegrass"
Case 90: genre = "Avantgarde"
Case 91: genre = "Gothic Rock"
Case 92: genre = "Progressive Rock"
Case 93: genre = "Psychedelic Rock"
Case 94: genre = "Symphonic Rock"
Case 95: genre = "Slow Rock"
Case 96: genre = "Big Band"
Case 97: genre = "Chorus"
Case 98: genre = "Easy Listening"
Case 99: genre = "Acoustic"
Case 100: genre = "Humour"
Case 101: genre = "Speech"
Case 102: genre = "Chanson"
Case 103: genre = "Opera"
Case 104: genre = "Chamber Music"
Case 105: genre = "Sonata"
Case 106: genre = "Symphony"
Case 107: genre = "Booty Bass"
Case 108: genre = "Primus"
Case 109: genre = "Porn Groove"
Case 110: genre = "Satire"
Case 111: genre = "Slow Jam"
Case 112: genre = "Club"
Case 113: genre = "Tango"
Case 114: genre = "Samba"
Case 115: genre = "Folklore"
Case 116: genre = "Ballad"
Case 117: genre = "Power Ballad"
Case 118: genre = "Rhythmic Soul"
Case 119: genre = "Freestyle"
Case 120: genre = "Duet"
Case 121: genre = "Punk Rock"
Case 122: genre = "Drum Solo"
Case 123: genre = "A capella"
Case 124: genre = "Euro-House"
Case 125: genre = "Dance Hall"
Case Else: genre = "Unknown"
End Select
id3_genre_name = genre
End Function
''
' Reads an ID3v1-tag from a file and returns it
' Supports ID3 version 1 with TAG+
' @param String FileName The filename of which we need the tags
' @return id3v1_tag The tag elements
' @author Stefan Thoolen <mail@stefanthoolen.nl>
Public Function id3v1_get_tag(ByVal filename As String) As id3v1_tag
On Error GoTo id3v1_get_tag_error
' At default we don't have a tag
id3v1_get_tag.has_tag = False
Dim file_footer As id3v1_file_footer
Dim ff As Long
ff = FreeFile
Open filename For Binary Access Read As #ff
Get #ff, LOF(ff) - (Len(file_footer) - 1), file_footer
Close #ff
' Not a valid ID3v1-tag
If file_footer.header <> "TAG" Then Exit Function
With id3v1_get_tag
.has_tag = True
.artist = Trim(Replace(file_footer.artist, Chr(0), ""))
.title = Trim(Replace(file_footer.SongTitle, Chr(0), ""))
.album = Trim(Replace(file_footer.album, Chr(0), ""))
.year = Trim(Replace(file_footer.year, Chr(0), ""))
.genre_id = file_footer.genre
If file_footer.ZeroByte = 0 Then
' Track number is specified, comment can only contain 28 characters
.has_trackno = True
.trackno = file_footer.trackno
.comment = Trim(Replace(file_footer.comment, Chr(0), ""))
Else
' Comment is 30 characters long and no track number is specified
.has_trackno = False
.comment = Trim(Replace(file_footer.comment & Chr(file_footer.ZeroByte) & Chr(file_footer.trackno), Chr(0), ""))
End If
' The tag can be extended according to the specifications
If file_footer.Ext_Header = "TAG+" Then
.artist = .artist & Trim(Replace(file_footer.Ext_Artist, Chr(0), ""))
.title = .title & Trim(Replace(file_footer.Ext_Title, Chr(0), ""))
.album = .album & Trim(Replace(file_footer.Ext_Artist, Chr(0), ""))
.genre_text = Trim(Replace(file_footer.Ext_Genre, Chr(0), ""))
.speed = file_footer.Ext_Speed
Else
.genre_text = id3_genre_name(.genre_id)
End If
End With
Exit Function
id3v1_get_tag_error:
Close #ff
End Function