Tip

Read ID3-Tags from MP3 Files

This code do a recursive search from the start directory for MP3-files. For each file, it extract the ID3-tag which contain information about title, artist, year of release, genre, album, etc., and put the data in a new document. The form for the document (called MP3) contain the following fields:
Title, Artist, Album, Year, Genre, Comment, Location : Text Created : Date, compute when composed using the formula @Now

Change the content of the variable pathName$ to the top directory for your MP3 files.

Enjoy!


The agent contain the following:

----(Declarations)----
Public servername As String
Public basepath As String

---- Rest of code ----

Sub Initialize
Dim ses As New NotesSession
Dim db As NotesDatabase

Set db = ses.CurrentDatabase
pathName$ = "d:MP3"
basepath=pathname$

fileSpec$ = "*.mp3"
If Right$(pathName$, 1) <> "" Then pathName$ = pathName$ & ""

Call processDirectory(db, pathName$, fileSpec$)
Print "Finished Scanning"
End Sub

Sub processDirectory(db As NotesDatabase, pathName$, fileSpec$)
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim object As NotesEmbeddedObject
Dim fileList List As String
Dim importList List As String
Dim dirList List As String

Print "Scanning: " & pathName$
Chdir (pathName$)

fileName$ = Dir$(pathName$ & "*.*", 0)
Do While fileName$ <> ""
fileList(fileName$) = fileName$
fileName$ = Dir$()
Loop
fileName$ = Dir$(pathName$ & fileSpec$, 0)
Do While fileName$ <> ""
importList(fileName$) = fileName$
fileName$ = Dir$()
Loop

fileName$ = Dir$(pathName$ & "*", 16)
Do While fileName$ <> ""
If Left$(fileName$, 1) <> "." And Not Iselement(fileList(fileName$)) Then
dirList(fileName$) = fileName$
fileName$ = Dir$()
Loop

Forall i In importList
Dim MP3len As Long
Dim cnt As Long
Dim MP3filename As String
Dim MP3tag As String*3
Dim Title As String*30
Dim Artist As String*30
Dim Album As String*30
Dim ProdYear As String*4
Dim Genre As String
Dim Comment As String*30
Dim MP3head As String

Dim db2 As NotesDatabase
Dim session As New NotesSession
Dim col As NotesDocumentCollection
Dim DateTime As New NotesDateTime("1/1/99")
Set db2= session.currentdatabase
DirStr=Mid(Pathname$,Len(BasePath$),256) + i
Set col=db2.search(|Location="|+DirStr+i+|"|,DateTime,0)
MP3filename=PathName$+i
Print "Processing "+MP3filename
If col.Count = 0 Then

Open MP3filename For Binary As #1
MP3Len=Filelen(MP3filename)
Print "Reading MP3 tag from " + MP3filename
MP3Len=MP3Len-127
If MP3Len >1024 Then
Seek #1,MP3len
MP3head=Inputbp(128,#1)
End If
Close #1

MP3tag=Mid$(MP3head,1,3)
Title=Trim$(Mid(MP3head,4,30))
Artist=Trim$(Mid(MP3head,34,30))
Album=Trim$(Mid(MP3head,64,30))
ProdYear=Trim$(Mid(MP3head,94,4))
Comment=Trim$(Mid(MP3head,98,30))
Genre=Mid(MP3head,128,1)

Set doc = New NotesDocument(db2)
doc.Form="MP3"
DirStr=Mid(Pathname$,Len(BasePath$),256) + i
doc.Location=DirStr
If MP3tag="TAG" Then
Print "Getting ID3 for "+pathName$+i
doc.Title=Title
doc.Album=Album
doc.Artist=Artist
doc.Year=Prodyear
doc.Comment=Comment
doc.Genre=Cstr(Genre)
success = doc.ComputeWithForm(False, False)
End If
Call doc.Save(False,False)
End If
End Forall

Forall d In dirList
newPath$ = pathName$ & d
If Right$(newPath$, 1) <> "" Then newPath$ = newPath$ & ""
Call processDirectory(db, newPath$, fileSpec$)
End Forall
End Sub

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.