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