' -------------------------------------------------------------- ' This script searches for a specific picture in subfolders of ' all songs and copies it into the jukebox picture database. ' (if no picture is already assigned to album or artist) ' ' Written by T.G.ViRUS - 05.01.2005 ' -------------------------------------------------------------- Sub Main() Dim strAsk1, strAsk2, strTxt1, strTxt2, strTxt3, strTxt4 Dim strAlbumArtistName, strRootPath Dim strPicName, strPrefix Dim lngCount, lngProcessed Dim lngFound strAsk1 = "This script searches for a specific picture in subfolders of" & vbCrLf strAsk1 = strAsk1 & "all songs and copies it into the jukebox picture database." & vbCrLf strAsk1 = strAsk1 & "(if no picture is already assigned to album or artist)" & vbCrLf & vbCrLf strAsk1 = strAsk1 & "Search pictures to assign for..." & vbCrLf & vbCrLf strAsk1 = strAsk1 & "1. Albums" & vbCrLf strAsk1 = strAsk1 & "2. Artists" & vbCrLf strAsk1 = strAsk1 & "3. Cancel" strAsk2 = "Name of picture file to search for (i.e.: picture.jpg, folder.jpg)" strTxt1 = "Search folder picture from Song " strTxt2 = " of " strTxt3 = "Found and copied: " strTxt4 = "Search for pictures finished!" Start: Select Case InputBox(strAsk1, 3) Case "1" strPrefix = "A " 'Album prefix Case "2" strPrefix = "I " 'Artist prefix Case Else 'Cancel wizard Exit Sub End Select strPicName = InputBox(strAsk2, "folder.jpg") If strPicName = "" Then GoTo Start 'Loop through all songs now... rs.Open("SELECT Album, Artist, PathOfSong from qry_Song") lngCount = rs.RecordCount lngProcessed = 0 lngFound = 0 db.StartProgressMonitor(lngCount) Do Until rs.EOF strAlbumArtistName = NameToFile(rs.GetField(IIf(strPrefix = "A ", "Album", "Artist"))) strRootPath = fs.GetParentFolderName(db.SQLToPath(rs.GetField("PathOfSong"))) If Right(strRootPath, 1) <> "\" Then strRootPath = strRootPath & "\" If CopyPicture(strPrefix & strAlbumArtistName, strRootPath & strPicName) Then lngFound = lngFound + 1 End If lngProcessed = lngProcessed + 1 If (lngProcessed Mod 10) = 0 Then db.PrintProgressMonitor(strTxt1 & lngProcessed & strTxt2 & lngCount & vbCrLf & strTxt3 & lngFound) End If db.SetProgressMonitor(lngProcessed) rs.MoveNext Loop db.PrintProgressMonitor(strTxt3 & lngFound & vbCrLf & strTxt4) db.EndProgressMonitor End Sub '--------------------------------------------------------- ' Copy existing Picture to the Jukebox picture database '--------------------------------------------------------- Function CopyPicture(vstrName, vstrPicturePath) Dim strExt Dim strDestPic ' Search now for picture in folders If fs.FileExists(vstrPicturePath) Then strExt = fs.GetExtensionName(vstrPicturePath) strDestPic = App.Path & "\Pictures\" & vstrName & "." & strExt ' Don't overwrite existing pictures If Not fs.FileExists(strDestPic) Then ' Copy picture now to picture database fs.CopyFile(vstrPicturePath, strDestPic) Return True End If End If Return False End Function '--------------------------------------------------------- ' Convert Album or Artist Name to a file compatible format '--------------------------------------------------------- Function NameToFile(vstrName) Dim strNewName strNewName = Replace(vstrName, Chr(160), " ") strNewName = Replace(strNewName, "/", "_") strNewName = Replace(strNewName, "\", "_") strNewName = Replace(strNewName, ":", ";") strNewName = Replace(strNewName, "*", ".") strNewName = Replace(strNewName, "|", "!") strNewName = Replace(strNewName, "?", "!") strNewName = Replace(strNewName, """", "'") strNewName = Replace(strNewName, ">", "") strNewName = Replace(strNewName, "<", "") Return strNewName End Function