Batch Art Finder 4.2 - Updated 03/07/2012
Re: Batch Art Finder 4.1 - Updated 31/01/2011
When I use the option "start all images as ticked to be saved" nothing happens when I click the blue links, if I deactivate this option everything is fine
Re: Batch Art Finder 4.1 - Updated 31/01/2011
Should Google search work with 4.1 at the moment or is there something which needs to be fixed?
For me Google search stopped working 3-4 weeks ago (because of IE9?) - i always get "no results".
I have to use the other search sites instead.
For me Google search stopped working 3-4 weeks ago (because of IE9?) - i always get "no results".
I have to use the other search sites instead.
Re: Batch Art Finder 4.1 - Updated 31/01/2011
I first want to thank trixmoto for the nice job on the code. I have an extensive library and would not have been able to keep it up to date without this and other scripts he has put together.
I too have been having trouble running this script as of lately. I recently updated from XP to Win7-64. The Google problem seems to be google itself. I haven't tried modifying the code to batchartfinder to see if I could get it to work with Google. But what I did do was take the lead from someone here suggesting using Bing Images. I reworked the code to browse Bing Images and it works great. I'll Post the code below. I also added another site called http://www.GoMusicNow.com which has a lot of album artwork as well. I save all my artwork in 300X300 px and have had good success with these modifications.
A couple bugs of note: I modified the VB code to browse both Bing and GoMusicNow (I removed Juno & RateYourMusic), but the MM option settings for BatchArtFinder still shows Juno & RageYourMusic instead of Bing & GoMusicNow. I haven't messed around much with trying to modify MM and I just quickly put together the Bing code so I could find artwork for about 25 albums I've ripped to MP3s. So if someone smarter than me can fix that we'd be golden.
Here is the VB code for BatchArtFinder with the modifications. I have to paste it across 4 posts in order for it to fit. (p.s. I hope trixmoto isn't offended I took some liberties with this work)
I too have been having trouble running this script as of lately. I recently updated from XP to Win7-64. The Google problem seems to be google itself. I haven't tried modifying the code to batchartfinder to see if I could get it to work with Google. But what I did do was take the lead from someone here suggesting using Bing Images. I reworked the code to browse Bing Images and it works great. I'll Post the code below. I also added another site called http://www.GoMusicNow.com which has a lot of album artwork as well. I save all my artwork in 300X300 px and have had good success with these modifications.
A couple bugs of note: I modified the VB code to browse both Bing and GoMusicNow (I removed Juno & RateYourMusic), but the MM option settings for BatchArtFinder still shows Juno & RageYourMusic instead of Bing & GoMusicNow. I haven't messed around much with trying to modify MM and I just quickly put together the Bing code so I could find artwork for about 25 albums I've ripped to MP3s. So if someone smarter than me can fix that we'd be golden.
Here is the VB code for BatchArtFinder with the modifications. I have to paste it across 4 posts in order for it to fit. (p.s. I hope trixmoto isn't offended I took some liberties with this work)
Code: Select all
'
' MediaMonkey Script
'
' NAME: BatchArtFinder 4.1
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 31/01/2011
'
' INSTALL: Copy to Scripts\Auto directory and add the following to Scripts.ini
' Don't forget to remove comments (') and set the order appropriately
'
' Thanks to Zachm019 for his beta testing which helped a lot
' Thanks to Ryedunn for finding and fixing change with Google results
' Thanks to Austin Powers for his UTF encoding
'
' NOTE: This script automatically registers the MSInet component to download the images
'
' [BatchArtFinder]
' FileName=Auto\BatchArtFinder.vbs
' ProcName=BatchArtFinder
' Order=28
' DisplayName=Batch Art Finder
' Description=Find album art in batch
' Language=VBScript
' ScriptType=0
'
' FIXES: Fixed "object required: data" error
' Fixed "try next image" not working in single result mode
'
Option Explicit
Dim Version : Version = 401
Dim FileMask,ImageSize,Storage,Extra,Singles,Maximum,Include,Persist,Images
Dim PanelType,Toolbar,Default,StartID,CheckAll,Source,MinW,MinH,MaxW,MaxH
Dim ConfMode,SaveMode,AutoMode,IncludeDone,SetSize,SetW,SetH,FileTypes
Dim MaxD,Titles,NewOpts,Filters(),FilterName,FilterSQL,TotCount,Debug,Exists
Dim api : api = "6cfe51c9bf7e77d6449e63ac0db2ac24"
Sub onStartup
'set default values
Dim ini : Set ini = SDB.IniFile
If ini.StringValue("BatchArtFinder","Storage") = "" Then
ini.StringValue("BatchArtFinder","Storage") = "1" '0=None 1=InTag 2=AsLink 3=Both 4=InTagDeleteFile 5=DownloadOnly
End If
If ini.StringValue("BatchArtFinder","ImageSize") = "" Then
ini.StringValue("BatchArtFinder","ImageSize") = "1" '0=Small 1=Medium 2=Large 3=All 4=Exact
End If
If ini.StringValue("BatchArtFinder","FileMask") = "" Then
ini.StringValue("BatchArtFinder","FileMask") = "<path>\<album>" 'mask for saving images
End If
If ini.StringValue("BatchArtFinder","Extra") = "" Then
ini.StringValue("BatchArtFinder","Extra") = "" 'extra sql in where statement
End If
If ini.StringValue("BatchArtFinder","Singles") = "" Then
ini.StringValue("BatchArtFinder","Singles") = "0" 'include non-album tracks
End If
If ini.StringValue("BatchArtFinder","Maximum") = "" Then
ini.StringValue("BatchArtFinder","Maximum") = "0" 'maximum albums per batch
End If
If ini.StringValue("BatchArtFinder","Include") = "" Then
ini.StringValue("BatchArtFinder","Include") = "0" 'include single titles in search url
End If
If ini.StringValue("BatchArtFinder","PanelType") = "" Then
ini.StringValue("BatchArtFinder","PanelType") = "1" '1=StayOnTop 2=Normal 3=Dockable
End If
If ini.StringValue("BatchArtFinder","Toolbar") = "" Then
ini.StringValue("BatchArtFinder","Toolbar") = "1" 'add toolbar button
End If
If ini.StringValue("BatchArtFinder","Default") = "" Then
ini.StringValue("BatchArtFinder","Default") = "0" 'add none.jpg to images without art
End If
If ini.StringValue("BatchArtFinder","StartID") = "" Then
ini.StringValue("BatchArtFinder","StartID") = "0"
End If
If ini.StringValue("BatchArtFinder","CheckAll") = "" Then
ini.StringValue("BatchArtFinder","CheckAll") = "0"
End If
If ini.StringValue("BatchArtFinder","Source") = "" Then
ini.StringValue("BatchArtFinder","Source") = "0" '0=google 1=bing 2=gomusicnow 3=albumart 4=audioscrobbler
End If
If ini.StringValue("BatchArtFinder","MinW") = "" Then
ini.StringValue("BatchArtFinder","MinW") = "0" 'pixels
End If
If ini.StringValue("BatchArtFinder","MinH") = "" Then
ini.StringValue("BatchArtFinder","MinH") = "0" 'pixels
End If
If ini.StringValue("BatchArtFinder","MaxW") = "" Then
ini.StringValue("BatchArtFinder","MaxW") = "9999" 'pixels
End If
If ini.StringValue("BatchArtFinder","MaxH") = "" Then
ini.StringValue("BatchArtFinder","MaxH") = "9999" 'pixels
End If
If ini.StringValue("BatchArtFinder","ConfMode") = "" Then
ini.StringValue("BatchArtFinder","ConfMode") = "0" '0=prompt 1=yes 2=all
End If
If ini.StringValue("BatchArtFinder","SaveMode") = "" Then
ini.StringValue("BatchArtFinder","SaveMode") = "0" '0=nothing 1=next 2=close 3=trynext
End If
If ini.StringValue("BatchArtFinder","AutoMode") = "" Then
ini.StringValue("BatchArtFinder","AutoMode") = "0"
End If
If ini.StringValue("BatchArtFinder","SetSize") = "" Then
ini.StringValue("BatchArtFinder","SetSize") = "0"
End If
If ini.StringValue("BatchArtFinder","SetW") = "" Then
ini.StringValue("BatchArtFinder","SetW") = "100" 'pixels
End If
If ini.StringValue("BatchArtFinder","SetH") = "" Then
ini.StringValue("BatchArtFinder","SetH") = "100" 'pixels
End If
If ini.StringValue("BatchArtFinder","FileTypes") = "" Then
ini.StringValue("BatchArtFinder","FileTypes") = "jpg"
End If
If ini.StringValue("BatchArtFinder","Persist") = "" Then
ini.StringValue("BatchArtFinder","Persist") = "0"
End If
If ini.StringValue("BatchArtFinder","MaxD") = "" Then
ini.StringValue("BatchArtFinder","MaxD") = "9999" 'pixels
End If
If ini.StringValue("BatchArtFinder","Titles") = "" Then
ini.StringValue("BatchArtFinder","Titles") = "0" 'always use title of first track
End If
If ini.StringValue("BatchArtFinder","NewOpts") = "" Then
ini.StringValue("BatchArtFinder","NewOpts") = "0" 'new options available
End If
If ini.StringValue("BatchArtFinder","FilterName") = "" Then
ini.StringValue("BatchArtFinder","FilterName") = "- No Filter -"
End If
If ini.StringValue("BatchArtFinder","TotCount") = "" Then
ini.StringValue("BatchArtFinder","TotCount") = "0"
End If
If ini.StringValue("BatchArtFinder","Debug") = "" Then
ini.StringValue("BatchArtFinder","Debug") = "0"
End If
If ini.StringValue("BatchArtFinder","Exists") = "" Then
ini.StringValue("BatchArtFinder","Exists") = "0"
End If
If ini.StringValue("BatchArtFinder","Images") = "" Then
ini.StringValue("BatchArtFinder","Images") = "1"
End If
'set default sizes
If ini.StringValue("BatchArtFinder","PanelDockedTo") = "" Then
ini.StringValue("BatchArtFinder","PanelDockedTo") = "4"
End If
If ini.StringValue("BatchArtFinder","PanelWidth") = "" Then
ini.StringValue("BatchArtFinder","PanelWidth") = "600"
End If
If ini.StringValue("BatchArtFinder","PanelHeight") = "" Then
ini.StringValue("BatchArtFinder","PanelHeight") = "400"
End If
If ini.StringValue("BatchArtFinder","PanelTop") = "" Then
ini.StringValue("BatchArtFinder","PanelTop") = "100"
End If
If ini.StringValue("BatchArtFinder","PanelLeft") = "" Then
ini.StringValue("BatchArtFinder","PanelLeft") = "100"
End If
'add option sheet
Call SDB.UI.AddOptionSheet("BatchArtFinder Settings",Script.ScriptPath,"InitSheet","SaveSheet",-3)
'add toolbar button
Dim but : Set but = SDB.Objects("BAFToolbarButton")
If (but Is Nothing) Then
Set but = SDB.UI.AddMenuItem(SDB.UI.Menu_TbStandard,0,0)
but.Caption = "Batch Art Finder"
but.IconIndex = SDB.RegisterIcon("Scripts\Auto\baf.ico",0)
but.UseScript = Script.ScriptPath
but.OnClickFunc = "ToolbarArtFinder"
Set SDB.Objects("BAFToolbarButton") = but
End If
If ini.IntValue("BatchArtFinder","Toolbar") = 1 Then
but.Visible = True
Else
but.Visible = False
End If
'save options for future loops
Dim tmp : tmp = ""
Dim rep : Set rep = SDB.Objects("BatchArtFinderReplies")
If rep Is Nothing Then
Set rep = CreateObject("Scripting.Dictionary")
If ini.IntValue("BatchArtFinder","Persist") = 1 Then
tmp = ini.StringValue("BatchArtFinder","Replies1")
If Not (tmp = "") Then
rep.Item("restrict") = tmp
End If
tmp = ini.StringValue("BatchArtFinder","Replies2")
If Not (tmp = "") Then
rep.Item("beginning") = tmp
End If
tmp = ini.StringValue("BatchArtFinder","Replies3")
If Not (tmp = "") Then
rep.Item("include") = tmp
End If
End If
Set SDB.Objects("BatchArtFinderReplies") = rep
End If
If ini.IntValue("BatchArtFinder","Persist") = 1 Then
tmp = GetHint()
If Not (tmp = "") Then
but.Caption = "Batch Art Finder"&Chr(13)&"-"&Chr(13)&tmp
End If
End If
'add event for auto mode
Call Script.RegisterEvent(SDB,"OnPlay","AutoArtFinder")
End Sub
Sub ToolbarArtFinder(ClickedBtn)
Dim ini : Set ini = SDB.IniFile
ini.BoolValue("BatchArtFinder","IncludeDone") = False
ini.IntValue("BatchArtFinder","TotCount") = 0
If Not (ini.IntValue("BatchArtFinder","Persist") = 1) Then
Set SDB.Objects("BatchArtFinderReplies") = Nothing
End If
Call DoBatchArtFinder(Nothing)
End Sub
Sub AutoArtFinder()
Dim ini : Set ini = SDB.IniFile
If ini.IntValue("BatchArtFinder","AutoMode") = 1 Then
Dim itm : Set itm = SDB.Player.CurrentSong
If Not (itm Is Nothing) Then
If itm.Album.AlbumArt Is Nothing Then
ini.BoolValue("BatchArtFinder","IncludeDone") = False
ini.IntValue("BatchArtFinder","TotCount") = 0
If Not (ini.IntValue("BatchArtFinder","Persist") = 1) Then
Set SDB.Objects("BatchArtFinderReplies") = Nothing
End If
Call DoBatchArtFinder(itm)
End If
End If
End If
End Sub
Sub BatchArtFinder()
Dim ini : Set ini = SDB.IniFile
ini.BoolValue("BatchArtFinder","IncludeDone") = False
ini.IntValue("BatchArtFinder","TotCount") = 0
If Not (ini.IntValue("BatchArtFinder","Persist") = 1) Then
Set SDB.Objects("BatchArtFinderReplies") = Nothing
End If
Call DoBatchArtFinder(Nothing)
End Sub
Sub DoBatchArtFinder(itm)
'check script is not already running
Dim form : Set form = SDB.Objects("BatchArtFinderForm")
If Not (form Is Nothing) Then
Exit Sub
End If
'setup variables
Dim ini : Set ini = SDB.IniFile
Singles = ini.IntValue("BatchArtFinder","Singles")
Maximum = ini.IntValue("BatchArtFinder","Maximum")
Extra = ini.StringValue("BatchArtFinder","Extra")
PanelType = ini.IntValue("BatchArtFinder","PanelType")
CheckAll = ini.IntValue("BatchArtFinder","CheckAll")
Source = ini.IntValue("BatchArtFinder","Source")
ConfMode = ini.IntValue("BatchArtFinder","ConfMode")
IncludeDone = ini.BoolValue("BatchArtFinder","IncludeDone")
Persist = ini.IntValue("BatchArtFinder","Persist")
Titles = ini.IntValue("BatchArtFinder","Titles")
FilterName = ini.StringValue("BatchArtFinder","FilterName")
FilterSQL = GetFilterSQL(FilterName)
TotCount = ini.IntValue("BatchArtFinder","TotCount")
Debug = ini.BoolValue("BatchArtFinder","Debug")
Exists = ini.BoolValue("BatchArtFinder","Exists")
Images = ini.IntValue("BatchArtFinder","Images")
Dim chk : chk = ""
If CheckAll = 1 Then
chk = " checked=""checked"""
End If
'create form
If PanelType = 1 Or PanelType = 2 Then
Set form = SDB.UI.NewForm
form.Common.SetRect 100, 100, 100, 100
form.BorderStyle = 2
form.FormPosition = 4
If PanelType = 1 Then
form.StayOnTop = True
End If
form.SavePositionName = "BatchArtFinderPosition"
ElseIf PanelType = 3 Then
Set form = SDB.UI.NewDockablePanel
form.Common.Visible = False
Dim dock : dock = ini.IntValue("BatchArtFinder","PanelDockedTo")
If (dock > 0) And (dock < 5) Then
form.DockedTo = dock
Else
form.DockedTo = 4
End If
Else
Exit Sub
End If
form.Common.Width = ini.IntValue("BatchArtFinder","PanelWidth")
form.Common.Height = ini.IntValue("BatchArtFinder","PanelHeight")
form.Common.Top = ini.IntValue("BatchArtFinder","PanelTop")
form.Common.Left = ini.IntValue("BatchArtFinder","PanelLeft")
form.Common.ControlName = "BatchArtFinder"
form.Caption = "Batch Art Finder"
Call Script.RegisterEvent(form,"OnClose","FormClose")
Set SDB.Objects("BatchArtFinderForm") = form
Set SDB.Objects("BAFCurrentSong") = itm
'save options for future loops
Dim tmp : tmp = ""
Dim rep : Set rep = SDB.Objects("BatchArtFinderReplies")
If rep Is Nothing Then
Set rep = CreateObject("Scripting.Dictionary")
If Persist = 1 Then
tmp = ini.StringValue("BatchArtFinder","Replies1")
If Not (tmp = "") Then
rep.Item("restrict") = tmp
End If
tmp = ini.StringValue("BatchArtFinder","Replies2")
If Not (tmp = "") Then
rep.Item("beginning") = tmp
End If
tmp = ini.StringValue("BatchArtFinder","Replies3")
If Not (tmp = "") Then
rep.Item("include") = tmp
End If
End If
Set SDB.Objects("BatchArtFinderReplies") = rep
End If
'create todo list
Dim todo : Set todo = CreateObject("Scripting.Dictionary")
Dim list : Set list = SDB.SelectedSongList
Dim list2 : Set list2 = SDB.NewSongList
Dim res : res = 0
Dim total : total = 0
Dim zero : zero = 0
Dim hnt : hnt = ""
If itm Is Nothing Then
'manual
If Not (list Is Nothing) Then
If list.Count = 0 Then
Set list = Nothing
Else
For res = 0 To list.Count-1
If list.Item(res).Album.ID = 0 Then
zero = 1
If Singles = 1 Then
Call list2.Add(list.Item(res))
Else
Exit For
End If
End If
Next
total = list.Albums.Count + list2.Count - zero
Select Case ConfMode
Case 1
res = mrYes
Case 2
res = mrAll
Case Else
If rep.Exists("restrict") Then
res = Int(rep.Item("restrict"))
Else
res = SDB.MessageBox("Batch Art Finder - do you wish to restrict the search to the "&total&" selected albums?",mtConfirmation,Array(mbYes,mbAll,mbCancel))
rep.Item("restrict") = res
If Persist = 1 Then
ini.StringValue("BatchArtFinder","Replies1") = res
hnt = GetHint()
If Not (hnt = "") Then
hnt = Chr(13)&"-"&Chr(13)&hnt
End If
SDB.Objects("BAFToolbarButton").Caption = "Batch Art Finder"&hnt
End If
End If
End Select
Select Case res
Case mrYes
'use list
Case mrAll
Set list = Nothing
Case Else
form.Common.ControlName = ""
Set SDB.Objects("BatchArtFinderForm") = Nothing
Exit Sub
End Select
End If
End If
Else
'automatic
Set list = SDB.NewSongList
Call list.Add(itm)
ini.IntValue("BatchArtFinder","StartID") = 0
End If
'get start position
Dim temp : temp = ini.StringValue("BatchArtFinder","StartID")
If Left(temp,1) = "*" Then
StartID = Int(Mid(temp,2))
Else
If temp = "0" Then
StartID = 0
Else
If rep.Exists("beginning") Then
res = Int(rep.Item("beginning"))
Else
res = SDB.MessageBox("Batch Art Finder - do you wish to start from the beginning? (No will continue from your last run).",mtConfirmation,Array(mbYes,mbNo,mbCancel))
rep.Item("beginning") = res
If Persist = 1 Then
ini.StringValue("BatchArtFinder","Replies2") = res
hnt = GetHint()
If Not (hnt = "") Then
hnt = Chr(13)&"-"&Chr(13)&hnt
End If
SDB.Objects("BAFToolbarButton").Caption = "Batch Art Finder"&hnt
End If
End If
Select Case res
Case mrYes
StartID = 0
Case mrNo
StartID = Int(temp)
Case Else
form.Common.ControlName = ""
Set SDB.Objects("BatchArtFinderForm") = Nothing
Exit Sub
End Select
End If
End If
ini.IntValue("BatchArtFinder","StartID") = StartID
'create hidden browser
Dim wb : Set wb = SDB.UI.NewActiveX(form, "Shell.Explorer")
wb.Common.SetRect 10,10,10,10
Set SDB.Objects("BatchArtFinderShell") = wb.Interf
'create results browser
Set wb = SDB.UI.NewActiveX(form, "Shell.Explorer")
wb.Common.Align = 5
'create panel (for buttons)
Dim foot : Set foot = SDB.UI.NewPanel(form)
foot.Common.Align = 2
foot.Common.Height = 25
'create source dropdown
Dim drp1 : Set drp1 = SDB.UI.NewDropDown(foot)
drp1.Common.SetRect 2,2,125,25
drp1.Common.Anchors = 4+8
drp1.Common.ControlName = "drp1"
drp1.Style = 2
drp1.AddItem("Google")
drp1.AddItem("Bing")
drp1.AddItem("GoMusicNow")
drp1.AddItem("AlbumArt")
drp1.AddItem("AudioScrobbler")
'!
drp1.ItemIndex = Source
drp1.UseScript = Script.ScriptPath
drp1.OnSelectFunc = "SourceClick"
Set SDB.Objects("BatchArtFinderDrp1") = drp1
'create save button
Dim btn1 : Set btn1 = SDB.UI.NewButton(foot)
btn1.Caption = "Save checked images"
btn1.Common.SetRect 0,0,140,25
btn1.Common.Anchors = 4+8
btn1.Common.ControlName = "btn1"
Call Script.RegisterEvent(btn1.Common,"OnClick","SaveClick")
Set SDB.Objects("BatchArtFinderBtn1") = btn1
'create pause button
Dim btn2 : Set btn2 = SDB.UI.NewButton(foot)
btn2.Caption = "Pause"
btn2.Common.SetRect 0,0,65,25
btn2.Common.Anchors = 4+8
btn2.Common.ControlName = "btn2"
Call Script.RegisterEvent(btn2.Common,"OnClick","PauseClick")
Set SDB.Objects("BatchArtFinderBtn2") = btn2
'create next button
If list Is Nothing Then
Dim btn3 : Set btn3 = SDB.UI.NewButton(foot)
btn3.Caption = "Next"
btn3.Common.SetRect 0,0,65,25
btn3.Common.Anchors = 4+8
btn3.Common.ControlName = "btn3"
Call Script.RegisterEvent(btn3.Common,"OnClick","NextClick")
Set SDB.Objects("BatchArtFinderBtn3") = btn3
End If
'create status label
Dim lbl1 : Set lbl1 = SDB.UI.NewLabel(foot)
lbl1.Common.Top = 7
lbl1.Common.Left = 132
lbl1.Common.ControlName = "lbl1"
lbl1.Caption = ""
'create logfile
Dim wsh : Set wsh = CreateObject("WScript.Shell")
Dim paths : Set paths = CreateObject("Scripting.Dictionary")
temp = wsh.ExpandEnvironmentStrings("%TEMP%")
If Not (Right(temp,1) = "\") Then
temp = temp&"\"
End If
paths.Item("log") = temp&"BatchArtFinder.log"
paths.Item("htm") = temp&"BatchArtFinder.htm"
Set SDB.Objects("BatchArtFinderPaths") = paths
Dim fso : Set fso = SDB.Tools.FileSystem
Dim logf : Set logf = Nothing
If Debug Then
Set logf = fso.CreateTextFile(paths.Item("log"),True)
logf.WriteLine Time&" Batch Art Finder started..."
logf.WriteLine Time&" Singles="&Singles
logf.WriteLine Time&" Maximum="&Maximum
logf.WriteLine Time&" Extra="&Extra
logf.WriteLine Time&" PanelType="&PanelType
logf.WriteLine Time&" CheckAll="&CheckAll
logf.WriteLine Time&" Source="&Source
logf.WriteLine Time&" ConfMode="&ConfMode
logf.WriteLine Time&" IncludeDone="&IncludeDone
logf.WriteLine Time&" Persist="&Persist
logf.WriteLine Time&" Titles="&Titles
logf.WriteLine Time&" FilterName="&FilterName
logf.WriteLine Time&" Exists="&Exists
Else
'remove old logfile
If fso.FileExists(paths.Item("log")) Then
fso.DeleteFile(paths.Item("log"))
End If
End If
'create progress bar
Dim sql : sql = ""
Dim stot : stot = 0
Dim atot : atot = 0
Dim acur : acur = 0
Dim cur : cur = 0
Dim albums : Set albums = Nothing
Dim prog : Set prog = SDB.Progress
If list Is Nothing Then
If Singles = 1 Then
sql = "SELECT Count(*) AS SingleCount FROM Songs WHERE Album='' "&FilterSQL
If Debug Then
logf.WriteLine Time&" #"&sql
End If
Set albums = SDB.Database.OpenSQL(sql)
stot = albums.ValueByName("SingleCount")
End If
If FilterSQL = "" Then
sql = "SELECT Count(*) AS AlbumCount FROM Albums WHERE Albums.ID>"&StartID&" AND Albums.Album!='' AND Albums.Tracks>0 "&Extra
Else
sql = "SELECT Count(*) AS AlbumCount FROM Albums,Songs WHERE Albums.ID>"&StartID
sql = sql&" AND Albums.Album!='' AND Albums.Tracks>0 AND Songs.IDAlbum=Albums.ID "&FilterSQL&" "&Extra
End If
If Debug Then
logf.WriteLine Time&" #"&sql
End If
On Error Resume Next
Set albums = SDB.Database.OpenSQL(sql)
If Err.Number <> 0 Then
Call SDB.MessageBox("Batch Art Finder - your Extra option has created an invalid SQL statement.",mtError,Array(mbOk))
form.Common.ControlName = ""
Set SDB.Objects("BatchArtFinderForm") = Nothing
Err.Clear
Exit Sub
End If
atot = albums.ValueByName("AlbumCount")
On Error Goto 0
If TotCount = 0 Then
prog.MaxValue = atot+stot
ini.IntValue("BatchArtFinder","TotCount") = atot+stot
Else
prog.MaxValue = TotCount
cur = TotCount-atot
End If
Else
prog.MaxValue = list.Count 'this is set properly later
End If
prog.Value = cur
prog.Text = "Batch Art Finder - initialising..."
SDB.ProcessMessages
'create document
Dim doc : Set doc = fso.CreateTextFile(paths.Item("htm"),True)
If doc Is Nothing Then
If fso.FileExists(paths.Item("htm")) Then
Call fso.DeleteFile(paths.Item("htm"))
End If
Set doc = fso.CreateTextFile(paths.Item("htm"),True)
If doc Is Nothing Then
Call SDB.MessageBox("Batch Art Finder - interface could not be created.",mtInformation,Array(mbOk))
form.Common.ControlName = ""
Set SDB.Objects("BatchArtFinderForm") = Nothing
Exit Sub
End If
End If
Last edited by joemama on Fri May 27, 2011 5:55 pm, edited 2 times in total.
Re: Batch Art Finder 4.1 - Updated 31/01/2011
Page 2 of the code:
Code: Select all
doc.WriteLine "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"
doc.WriteLine "<html><head><meta http-equiv=""content-type"" content=""text/html; charset=UTF-8"">"
doc.WriteLine "<title>Batch Art Finder</title></head><style type=""text/css"">"
doc.WriteLine " body{font-family:""Verdana"",sans-serif;font-size:9pt;color:black;}"
doc.WriteLine " p{font-family:""Verdana"",sans-serif;font-size:8pt;color:black;}"
doc.WriteLine " td{font-family:""Verdana"",sans-serif;font-size:7pt;color:black;}"
doc.WriteLine " img{border:0px;}"
doc.WriteLine " a:link,a:visited,a:hover,a:active{color:blue;}"
If Images > 1 Then
doc.WriteLine " div.selected{border:solid 1px red;}"
End If
doc.WriteLine "</style><script Language=""VBScript"">"
doc.WriteLine "Function reset(id)"
doc.WriteLine " On Error Resume Next"
doc.WriteLine " Set SDB = CreateObject(""SongsDB.SDBApplication"")"
doc.WriteLine " If Not (SDB is Nothing) Then"
doc.WriteLine " Set data = SDB.Objects(""BAFData""&id)"
doc.WriteLine " If Not (data Is Nothing) Then"
doc.WriteLine " artist = data.Item(""oartist"")"
doc.WriteLine " album = data.Item(""oalbum"")"
doc.WriteLine " data.Item(""artist"") = artist"
doc.WriteLine " data.Item(""album"") = album"
doc.WriteLine " data.Item(""url"") = geturl(artist,album)"
doc.WriteLine " data.Item(""image"") = 0"
doc.WriteLine " data.Item(""result"") = 0"
doc.WriteLine " data.Item(""count"") = 0"
doc.WriteLine " data.Item(""source"") = """""
doc.WriteLine " data.Item(""previous"") = 0"
doc.WriteLine " End If"
doc.WriteLine " End If"
doc.WriteLine " On Error GoTo 0"
doc.WriteLine "End Function"
doc.WriteLine "Function editquery(id)"
doc.WriteLine " On Error Resume Next"
doc.WriteLine " Set SDB = CreateObject(""SongsDB.SDBApplication"")"
doc.WriteLine " If Not (SDB is Nothing) Then"
doc.WriteLine " Set data = SDB.Objects(""BAFData""&id)"
doc.WriteLine " If Not (data Is Nothing) Then"
If (Source = 0) Or (Source = 4) Then
doc.WriteLine " artist = InputBox(""Artist name:"",""BatchArtFinder"",data.Item(""artist""))"
doc.WriteLine " If artist = """" Then"
doc.WriteLine " artist = data.Item(""artist"")"
doc.WriteLine " Else"
doc.WriteLine " data.Item(""artist"") = artist"
doc.WriteLine " End If"
Else
doc.WriteLine " artist = data.Item(""artist"")"
End If
doc.WriteLine " album = InputBox(""Album name:"",""BatchArtFinder"",data.Item(""album""))"
doc.WriteLine " If album = """" Then"
doc.WriteLine " album = data.Item(""album"")"
doc.WriteLine " End If"
doc.WriteLine " data.Item(""album"") = album"
doc.WriteLine " data.Item(""url"") = geturl(artist,album)"
doc.WriteLine " data.Item(""image"") = 0"
doc.WriteLine " data.Item(""result"") = 0"
doc.WriteLine " data.Item(""count"") = 0"
doc.WriteLine " data.Item(""source"") = """""
doc.WriteLine " data.Item(""previous"") = 0"
doc.WriteLine " End If"
doc.WriteLine " End If"
doc.WriteLine " On Error GoTo 0"
doc.WriteLine "End Function"
doc.WriteLine "Function geturl(artist,album)"
doc.WriteLine " On Error Resume Next"
Select Case ini.IntValue("BatchArtFinder","Source")
Case 0
doc.WriteLine " geturl = ""http://images.google.com/images?q=""&mapname(artist)&""+""&mapname(album)"
Select Case ini.IntValue("BatchArtFinder","ImageSize")
Case 0
ImageSize = "&imgsz=icon"
Case 1
ImageSize = "&imgsz=medium"
Case 2
ImageSize = "&imgsz=xxlarge"
Case 4
ImageSize = "&imgw="&ini.IntValue("BatchArtFinder","MinW")&"&imgh="&ini.IntValue("BatchArtFinder","MinH")
Case 5
ImageSize = "&imgw="&ini.IntValue("BatchArtFinder","MaxW")&"&imgh="&ini.IntValue("BatchArtFinder","MaxH")
Case 6
ImageSize = "&imgw="&ini.IntValue("BatchArtFinder","SetW")&"&imgh="&ini.IntValue("BatchArtFinder","SetH")
Case Else
ImageSize = ""
End Select
doc.WriteLine " geturl = geturl&""&svnum=100&hl=en&lr=lang_en&newwindow=0&safe=off&sa=G"&ImageSize&"&ie=UTF-8&oe=UTF-8"""
Case 1
doc.WriteLine " geturl = ""http://www.bing.com/images/search?q=""&artist&""+""&album&""&qs=AS&sk=AS1"""
Case 2
doc.WriteLine " geturl = ""http://www.gomusicnow.com/search.html?query=""&artist&""+""&album"
Case 3
doc.WriteLine " geturl = ""http://www.albumart.org/index.php?srchkey=""&album&""&itempage=1&newsearch=1&searchindex=Music"""
Case 4
doc.WriteLine " geturl = ""http://ws.audioscrobbler.com/2.0/?method=album.getInfo&api_key="&api&"&artist=""&artist&""&album=""&album"
'!
End Select
doc.WriteLine " On Error GoTo 0"
doc.WriteLine "End Function"
doc.WriteLine "Function mapname(name)"
doc.WriteLine " On Error Resume Next"
doc.WriteLine " nameUTF8 = UTF8_Encode(name)"
doc.WriteLine " For i = 1 To Len(nameUTF8)"
doc.WriteLine " Dim c : c = Asc(Mid(nameUTF8,i))"
doc.WriteLine " If (c>32 And c<48) Or (c>57 And c<65) Or (c>90 And c<97) Or (c>122) Then"
doc.WriteLine " mapname = mapname&""%""&CStr(Hex(c))"
doc.WriteLine " Else"
doc.WriteLine " mapname = mapname&Chr(c)"
doc.WriteLine " End If"
doc.WriteLine " Next"
doc.WriteLine " mapname = Replace(mapname,"" "",""+"")"
doc.WriteLine " On Error GoTo 0"
doc.WriteLine "End Function"
doc.WriteLine "Function UTF8_Encode(ByVal UnicodeString)"
doc.WriteLine " On Error Resume Next"
doc.WriteLine " For i = 1 To Len(UnicodeString)"
doc.WriteLine " UnicodeCharCode = AscW(Mid(UnicodeString,i))"
doc.WriteLine " If UnicodeCharCode < &H80 Then"
doc.WriteLine " UTF8_temp = Chr(UnicodeCharCode)"
doc.WriteLine " ElseIf UnicodeCharCode < &H800 Then"
doc.WriteLine " UTF8_temp = Chr(&H80 + (UnicodeCharCode And &H3F))"
doc.WriteLine " UnicodeCharCode = UnicodeCharCode \ &H40"
doc.WriteLine " UTF8_temp = Chr(&HC0 + (UnicodeCharCode And &H1F)) & UTF8_temp"
doc.WriteLine " Else"
doc.WriteLine " UTF8_temp = Chr(&H80 + (UnicodeCharCode And &H3F))"
doc.WriteLine " UnicodeCharCode = UnicodeCharCode \ &H40"
doc.WriteLine " UTF8_temp = Chr(&H80 + (UnicodeCharCode And &H3F)) & UTF8_temp"
doc.WriteLine " UnicodeCharCode = UnicodeCharCode \ &H40"
doc.WriteLine " UTF8_temp = Chr(&HE0 + (UnicodeCharCode And &HF)) & UTF8_temp"
doc.WriteLine " End If"
doc.WriteLine " UTF8_Encode = UTF8_Encode & UTF8_temp"
doc.WriteLine " Next"
doc.WriteLine " On Error GoTo 0"
doc.WriteLine "End Function"
doc.WriteLine "Function showimage(id,dir)"
doc.WriteLine " On Error Resume Next"
doc.WriteLine " Set SDB = CreateObject(""SongsDB.SDBApplication"")"
doc.WriteLine " If Not (SDB Is Nothing) Then"
doc.WriteLine " Set data = SDB.Objects(""BAFData""&id)"
doc.WriteLine " If Not (data Is Nothing) Then"
If Images = 1 Then
doc.WriteLine " Dim div : Set div = document.getElementById(""img""&id)"
Else
doc.WriteLine " Dim div : Set div = document.getElementById(""img""&id&""-1"")"
End If
doc.WriteLine " If Not (div Is Nothing) Then"
doc.WriteLine " Call div.setAttribute(""found"","""")"
If Images = 1 Then
doc.WriteLine " Dim div2 : Set div2 = document.getElementById(""dim""&id)"
Else
doc.WriteLine " Dim div2 : Set div2 = document.getElementById(""dim""&id&""-1"")"
End If
doc.WriteLine " If Not (div2 Is Nothing) Then"
doc.WriteLine " data.Item(""result"") = 1"
doc.WriteLine " Dim cur : cur = Int(data.Item(""image""))+dir"
doc.WriteLine " Dim tot : tot = Int(data.Item(""count""))"
doc.WriteLine " If (cur < 1) Or (cur > tot) Then"
doc.WriteLine " div.innerHTML = ""[No results]"""
If Images = 1 Then
doc.WriteLine " div2.innerHTML = """""
Else
doc.WriteLine " div2.innerHTML = "" """
End If
doc.WriteLine " Else"
doc.WriteLine " Dim src : src = data.Item(""img""&cur)"
doc.WriteLine " data.Item(""image"") = cur"
doc.WriteLine " data.Item(""source"") = src"
doc.WriteLine " If dir = 1 Then"
doc.WriteLine " data.Item(""previous"") = 0"
doc.WriteLine " Else"
doc.WriteLine " data.Item(""previous"") = 1"
doc.WriteLine " End If"
doc.WriteLine " Dim str : str = ""<img src='""&src&""' title='""&src&""' count='""&cur&"" of ""&tot&""'"""
If ini.BoolValue("BatchArtFinder","SetSize") Then
ImageSize = """ width='"&ini.IntValue("BatchArtFinder","SetW")&"px' height='"&ini.IntValue("BatchArtFinder","SetH")&"px'"""
doc.WriteLine " str = str&"&ImageSize
End If
doc.WriteLine " str = str&"" count='' cross='0' /></a>"""
If Images = 1 Then
doc.WriteLine " div.innerHTML = ""<a href=""""javascript://"""">""&str"
Else
doc.WriteLine " div.innerHTML = ""<a href=""""javascript://"""" onclick=""""highlight('""&div.id&""')"""">""&str"
End If
doc.WriteLine " Call div2.setAttribute(""accept"","""")"
doc.WriteLine " div2.innerHTML = ""Image: ""&cur&"" of ""&tot&""<br />Loading..."""
doc.WriteLine " End If"
doc.WriteLine " End If"
doc.WriteLine " End If"
doc.WriteLine " End If"
doc.WriteLine " End If"
doc.WriteLine " On Error GoTo 0"
doc.WriteLine "End Function"
If Images > 1 Then
doc.WriteLine "Function getresult(id)"
doc.WriteLine " getresult = 0"
doc.WriteLine " On Error Resume Next"
doc.WriteLine " Set SDB = CreateObject(""SongsDB.SDBApplication"")"
doc.WriteLine " If Not (SDB is Nothing) Then"
doc.WriteLine " Set data = SDB.Objects(""BAFData""&id)"
doc.WriteLine " If Not (data Is Nothing) Then"
doc.WriteLine " getresult = data.Item(""result"")"
doc.WriteLine " End If"
doc.WriteLine " End If"
doc.WriteLine " On Error GoTo 0"
doc.WriteLine "End Function"
doc.WriteLine "Function setresult(id,res)"
doc.WriteLine " On Error Resume Next"
doc.WriteLine " Set SDB = CreateObject(""SongsDB.SDBApplication"")"
doc.WriteLine " If Not (SDB is Nothing) Then"
doc.WriteLine " Set data = SDB.Objects(""BAFData""&id)"
doc.WriteLine " If Not (data Is Nothing) Then"
doc.WriteLine " data.Item(""result"") = res"
doc.WriteLine " End If"
doc.WriteLine " End If"
doc.WriteLine " On Error GoTo 0"
doc.WriteLine "End Function"
End If
doc.WriteLine "</script><script Language=""JavaScript"">"
doc.WriteLine "function skipimg(id){"
doc.WriteLine " reset(id);"
doc.WriteLine " var d = null;"
doc.WriteLine " if(d=document.getElementById(""dim""+id)) d.innerHTML = """";"
If Images = 1 Then
doc.WriteLine " if(d=document.getElementById(""img""+id)) d.innerHTML = ""[Skipped]"";"
Else
doc.WriteLine " if(d=document.getElementById(""img""+id+""-1"")) d.innerHTML = ""[Skipped]"";"
doc.WriteLine " if(d=document.getElementById(""dim""+id+""-1"")) {"
doc.WriteLine " d.innerHTML = "" "";"
doc.WriteLine " d.setAttribute(""accept"","""");"
doc.WriteLine " }"
doc.WriteLine " for(var i=2;i<="&Images&";i++) {"
doc.WriteLine " if(d=document.getElementById(""img""+id+""-""+i)) d.innerHTML = "" "";"
doc.WriteLine " if(d=document.getElementById(""dim""+id+""-""+i)) {"
doc.WriteLine " d.innerHTML = "" "";"
doc.WriteLine " d.setAttribute(""accept"","""");"
doc.WriteLine " }"
doc.WriteLine " }"
End If
doc.WriteLine " if(d=document.getElementById(""sav""+id)) d.checked = false;"
doc.WriteLine "}"
doc.WriteLine "function nextimg(id){"
doc.WriteLine " var d = null;"
doc.WriteLine " if(d=document.getElementById(""dim""+id)) d.innerHTML = """";"
If Images = 1 Then
doc.WriteLine " if(d=document.getElementById(""img""+id)) {"
doc.WriteLine " if(d.innerHTML==""[Skipped]"") {"
doc.WriteLine " d.innerHTML = ""[Queued]"";"
doc.WriteLine " }"
doc.WriteLine " else {"
doc.WriteLine " showimage(id,1);"
doc.WriteLine " }"
doc.WriteLine " }"
Else
doc.WriteLine " if(d=document.getElementById(""dim""+id+""-1"")) {"
doc.WriteLine " d.innerHTML = "" "";"
doc.WriteLine " d.setAttribute(""accept"","""");"
doc.WriteLine " }"
doc.WriteLine " for(var i=2;i<="&Images&";i++) {"
doc.WriteLine " if(d=document.getElementById(""img""+id+""-""+i)) d.innerHTML = "" "";"
doc.WriteLine " if(d=document.getElementById(""dim""+id+""-""+i)) {"
doc.WriteLine " d.innerHTML = "" "";"
doc.WriteLine " d.setAttribute(""accept"","""");"
doc.WriteLine " }"
doc.WriteLine " }"
doc.WriteLine " if(d=document.getElementById(""img""+id+""-1"")) {"
doc.WriteLine " if(d.innerHTML==""[Skipped]"") {"
doc.WriteLine " d.innerHTML = ""[Queued]"";"
doc.WriteLine " }"
doc.WriteLine " else {"
doc.WriteLine " showimage(id,1);"
doc.WriteLine " }"
doc.WriteLine " }"
End If
doc.WriteLine "}"
doc.WriteLine "function editimg(id){"
doc.WriteLine " editquery(id);"
doc.WriteLine " var d = null;"
doc.WriteLine " if(d=document.getElementById(""dim""+id)) d.innerHTML = """";"
If Images = 1 Then
doc.WriteLine " if(d=document.getElementById(""img""+id)) d.innerHTML = ""[Queued]"";"
Else
doc.WriteLine " if(d=document.getElementById(""img""+id+""-1"")) d.innerHTML = ""[Queued]"";"
doc.WriteLine " if(d=document.getElementById(""dim""+id+""-1"")) {"
doc.WriteLine " d.innerHTML = "" "";"
doc.WriteLine " d.setAttribute(""accept"","""");"
doc.WriteLine " }"
doc.WriteLine " for(var i=2;i<="&Images&";i++) {"
doc.WriteLine " if(d=document.getElementById(""img""+id+""-""+i)) d.innerHTML = "" "";"
doc.WriteLine " if(d=document.getElementById(""dim""+id+""-""+i)) {"
doc.WriteLine " d.innerHTML = "" "";"
doc.WriteLine " d.setAttribute(""accept"","""");"
doc.WriteLine " }"
doc.WriteLine " }"
End If
doc.WriteLine "}"
doc.WriteLine "function previmg(id){"
doc.WriteLine " var d = null;"
doc.WriteLine " if(d=document.getElementById(""dim""+id)) d.innerHTML = """";"
If Images = 1 Then
doc.WriteLine " if(d=document.getElementById(""img""+id)) {"
doc.WriteLine " if(d.innerHTML==""[Skipped]"") {"
doc.WriteLine " d.innerHTML = ""[Queued]"";"
doc.WriteLine " }"
doc.WriteLine " else {"
doc.WriteLine " showimage(id,-1);"
doc.WriteLine " }"
doc.WriteLine " }"
Else
doc.WriteLine " if(d=document.getElementById(""dim""+id+""-1"")) {"
doc.WriteLine " d.innerHTML = "" "";"
doc.WriteLine " d.setAttribute(""accept"","""");"
doc.WriteLine " }"
doc.WriteLine " for(var i=2;i<="&Images&";i++) {"
doc.WriteLine " if(d=document.getElementById(""img""+id+""-""+i)) d.innerHTML = "" "";"
doc.WriteLine " if(d=document.getElementById(""dim""+id+""-""+i)) {"
doc.WriteLine " d.innerHTML = "" "";"
doc.WriteLine " d.setAttribute(""accept"","""");"
doc.WriteLine " }"
doc.WriteLine " }"
doc.WriteLine " if(d=document.getElementById(""img""+id+""-1"")) {"
doc.WriteLine " if(d.innerHTML==""[Skipped]"") {"
doc.WriteLine " d.innerHTML = ""[Queued]"";"
doc.WriteLine " }"
doc.WriteLine " else {"
doc.WriteLine " showimage(id,-1);"
doc.WriteLine " }"
doc.WriteLine " }"
End If
doc.WriteLine "}"
doc.WriteLine "function select(mode){"
doc.WriteLine " var i = 1;"
doc.WriteLine " var d = null;"
doc.WriteLine " while(d=document.getElementById(""sav""+i)) {"
doc.WriteLine " switch(mode) {"
doc.WriteLine " case 0:"
doc.WriteLine " d.checked = true;"
doc.WriteLine " break;"
doc.WriteLine " case 1:"
doc.WriteLine " d.checked = false;"
doc.WriteLine " break;"
doc.WriteLine " case 2:"
doc.WriteLine " d.checked = !d.checked;"
doc.WriteLine " break;"
doc.WriteLine " }"
If Images > 1 Then
doc.WriteLine " saveclick(i);"
End If
doc.WriteLine " i++;"
doc.WriteLine " }"
doc.WriteLine "}"
doc.WriteLine "function trynextall(){"
doc.WriteLine " var i = 1;"
doc.WriteLine " var d = null;"
doc.WriteLine " while(d=document.getElementById(""dim""+i)) {"
doc.WriteLine " d.innerHTML = """";"
If Images > 1 Then
doc.WriteLine " if(d=document.getElementById(""dim""+i+""-1"")) {"
doc.WriteLine " d.innerHTML = "" "";"
doc.WriteLine " d.setAttribute(""accept"","""");"
doc.WriteLine " }"
doc.WriteLine " for(var j=2;j<="&Images&";j++) {"
doc.WriteLine " if(d=document.getElementById(""img""+i+""-""+j)) d.innerHTML = "" "";"
doc.WriteLine " if(d=document.getElementById(""dim""+i+""-""+j)) {"
doc.WriteLine " d.innerHTML = "" "";"
doc.WriteLine " d.setAttribute(""accept"","""");"
doc.WriteLine " }"
doc.WriteLine " }"
End If
doc.WriteLine " showimage(i,1);"
If CheckAll = 1 Then
doc.WriteLine " if(d=document.getElementById(""sav""+i)) {"
doc.WriteLine " d.checked = true;"
If Images > 1 Then
doc.WriteLine " getresult(i);"
End If
End If
doc.WriteLine " i++;"
doc.WriteLine " }"
doc.WriteLine "}"
If Images > 1 Then
doc.WriteLine "function highlight(id){"
doc.WriteLine " var ar = id.substr(3).split(""-"");"
doc.WriteLine " var i = 1;"
doc.WriteLine " var j = (ar[0])*1;"
doc.WriteLine " var k = (ar[1])*1;"
doc.WriteLine " var d = null;"
doc.WriteLine " while(d=document.getElementById(""dim""+j+""-""+i)) {"
doc.WriteLine " if(i==k && d.getAttribute(""accept"")==""accept"") {"
doc.WriteLine " d.className = ""selected"";"
doc.WriteLine " if(d=document.getElementById(""sav""+j)) d.checked = true;"
doc.WriteLine " setresult(j,k);"
doc.WriteLine " }"
doc.WriteLine " else {"
doc.WriteLine " d.className = """";"
doc.WriteLine " }"
doc.WriteLine " i++;"
doc.WriteLine " }"
doc.WriteLine "}"
doc.WriteLine "function saveclick(id){"
doc.WriteLine " var i = 1;"
doc.WriteLine " var j = id;"
doc.WriteLine " var k = getresult(j);"
doc.WriteLine " var d = document.getElementById(""sav""+j);"
doc.WriteLine " var b = d.checked;"
doc.WriteLine " while(d=document.getElementById(""dim""+j+""-""+i)) {"
doc.WriteLine " if(b && i==k) {"
doc.WriteLine " d.className = ""selected"";"
doc.WriteLine " }"
doc.WriteLine " else {"
doc.WriteLine " d.className = """";"
doc.WriteLine " }"
doc.WriteLine " i++;"
doc.WriteLine " }"
doc.WriteLine "}"
End If
doc.WriteLine "</script><body><p><a href=""javascript:select(0)"">Select all</a> <a href=""javascript:select(1)"">Select none</a> <a href=""javascript:select(2)"">Select inverse</a> <a href=""javascript:trynextall()"">Try next image for all</a></p>"
doc.WriteLine "<table border=""1"" cellpadding=""4"" cellspacing=""0"" width=""100%"">"
'loop through all albums looking for those without art
Dim album,id,iter,avgyear,totlength,f,j,k
Dim col : col = Int(50/Images)
Dim i : i = 0
If list Is Nothing Then
If StartID > -1 Then
If Debug Then
logf.WriteLine Time&" (All albums)"
If StartID > 0 Then
logf.WriteLine Time&" (Starting from ID="&StartID&")"
End If
End If
If FilterSQL = "" Then
sql = "SELECT Albums.ID FROM Albums WHERE Albums.ID>"&StartID&" AND Albums.Album!='' AND Albums.Tracks>0 "&Extra&" GROUP BY Albums.ID"
Else
sql = "SELECT Albums.ID FROM Albums,Songs WHERE Albums.ID>"&StartID
sql = sql&" AND Albums.Album!='' AND Albums.Tracks>0 AND Songs.IDAlbum=Albums.ID "&FilterSQL&" "&Extra&" GROUP BY Albums.ID"
End If
If Debug Then
logf.WriteLine Time&" #"&sql
End If
Set albums = SDB.Database.OpenSQL(sql)
Do While Not albums.EOF
prog.Increase
f = " "&i
If Maximum > 0 Then
f = f&"/"&Maximum
End If
prog.Text = "Batch Art Finder - checking album "&prog.Value&"/"&prog.MaxValue&" (found:"&f&")..."
id = albums.ValueByName("ID")
Dim songs : Set songs = SDB.Database.QuerySongs("AND (Songs.IDAlbum="&id&")")
If Not (songs.EOF) Then
Set album = songs.Item.Album
If (album.AlbumArt Is Nothing) Or (IncludeDone) Then
'add album ID to array
If Debug Then
logf.WriteLine Time&" AlbumID="&id
End If
i = i + 1
todo.Item(i) = id
'add album to form
sql = "SELECT Avg(Year/10000) As AvgYear, Sum(SongLength) As TotLength FROM Songs WHERE IDAlbum="&id
If Debug Then
logf.WriteLine Time&" #"&sql
End If
Set iter = SDB.Database.OpenSQL(sql)
avgyear = fixyear(iter.StringByName("AvgYear"))
totlength = gettime(iter.ValueByName("TotLength")/1000)
If Images = 1 Then
doc.WriteLine "<tr id=""row"&i&"a""><td width=""50%"" align=""right"">"
Else
doc.WriteLine "<tr id=""row"&i&"a""><td width=""50%"" align=""right"" rowspan=""2"">"
End If
If Titles = 1 Then
doc.WriteLine "Album: "&UTF8_Encode(songs.Item.Title)
Else
doc.WriteLine "Album: "&UTF8_Encode(songs.Item.AlbumName)
End If
If songs.Item.AlbumArtistName = "" Then
doc.WriteLine "<br />Artist: "&UTF8_Encode(songs.Item.ArtistName)
Else
doc.WriteLine "<br />Artist: "&UTF8_Encode(songs.Item.AlbumArtistName)
End If
doc.WriteLine "<br />Year: "&avgyear
doc.WriteLine "<br />Length: "&totlength
doc.WriteLine "<br /><br /><nobr><a href=""javascript:nextimg('"&i&"')"">Try next image</a></nobr> "
doc.WriteLine "<nobr><a href=""javascript:skipimg('"&i&"')"">Skip this album</a></nobr> "
doc.WriteLine "<nobr><a href=""javascript:editimg('"&i&"')"">Edit album query</a></nobr> "
doc.WriteLine "<nobr><a href=""javascript:previmg('"&i&"')"">Previous image</a></nobr>"
doc.WriteLine "<p>Save:<input type=""checkbox"" id=""sav"&i&""""&chk&" onclick=""saveclick("&i&")"" /></p>"
doc.WriteLine "<div id=""dim"&i&""" accept=""""></div></td>"
If Images = 1 Then
doc.WriteLine "<td width=""50%"" align=""left""><div id=""img"&i&""">[Queued]</div></td></tr>"
Else
doc.WriteLine "<td width="""&col&"%"" align=""center"" style=""border-bottom:0px""><div id=""img"&i&"-1"">[Queued]</div></td>"
For k = 2 To Images
doc.WriteLine "<td width="""&col&"%"" align=""center"" style=""border-bottom:0px""><div id=""img"&i&"-"&k&"""> </div></td>"
Next
doc.WriteLine "</tr><tr id=""row"&i&"b"">"
For k = 1 To Images
doc.WriteLine "<td width="""&col&"%"" align=""center"" style=""border-top:0px""><div id=""dim"&i&"-"&k&""" accept=""""> </div></td>"
Next
doc.WriteLine "</tr>"
End If
End If
End If
Set songs = Nothing
albums.Next
'allow user to cancel
SDB.ProcessMessages
If prog.Terminate Then
If Debug Then
logf.WriteLine Time&" (Cancelled by user)"
logf.Close
End If
form.Common.ControlName = ""
Set SDB.Objects("BatchArtFinderForm") = Nothing
If Debug Then
logf.Close
End If
doc.Close
If fso.FileExists(paths.Item("htm")) Then
Call fso.DeleteFile(paths.Item("htm"))
End If
Exit Sub
End If
'maximum batch size
If Maximum > 0 Then
If i >= Maximum Then
If Debug Then
logf.WriteLine Time&" (Maximum of "&Maximum&" reached)"
End If
Exit Do
End If
End If
Loop
End If
If (Singles = 1) And ((Maximum = 0) Or (i < Maximum)) Then
sql = ""
If Debug Then
logf.WriteLine Time&" (All singles)"
End If
If StartID < 0 Then
StartID = Abs(StartID)
sql = " AND Songs.ID>"&StartID
If Debug Then
logf.WriteLine Time&" (Starting from ID="&StartID&")"
End If
End If
sql = "SELECT Songs.ID FROM Songs WHERE Songs.Album = ''"&sql&" GROUP BY Songs.ID"
If Debug Then
logf.WriteLine Time&" #"&sql
End If
Set albums = SDB.Database.OpenSQL(sql)
Do While Not albums.EOF
prog.Increase
f = " "&i
If Maximum > 0 Then
f = f&"/"&Maximum
End If
prog.Text = "Batch Art Finder - checking album "&prog.Value&"/"&prog.MaxValue&" (found:"&f&")..."
id = albums.ValueByName("ID")
Set songs = SDB.Database.QuerySongs("AND (Songs.ID="&id&")")
If Not (songs.EOF) Then
Set album = songs.Item
If (album.AlbumArt.Count = 0) Or (IncludeDone) Then
'add song ID to array
If Debug Then
logf.WriteLine Time&" SongID="&id
End If
i = i + 1
todo.Item(i) = "*"&id
'add album to form
If Images = 1 Then
doc.WriteLine "<tr id=""row"&i&"a""><td width=""50%"" align=""right"">"
Else
doc.WriteLine "<tr id=""row"&i&"a""><td width=""50%"" align=""right"" rowspan=""2"">"
End If
doc.WriteLine "Single: "&UTF8_Encode(album.Title)
doc.WriteLine "<br />Artist: "&UTF8_Encode(album.Artist.Name)
doc.WriteLine "<br />Year: "&fixyear(album.Year)
doc.WriteLine "<br />Length: "&gettime(album.SongLength/1000)
doc.WriteLine "<br /><br /><nobr><a href=""javascript:nextimg('"&i&"')"">Try next image</a></nobr> "
doc.WriteLine "<nobr><a href=""javascript:skipimg('"&i&"')"">Skip this album</a></nobr> "
doc.WriteLine "<nobr><a href=""javascript:editimg('"&i&"')"">Edit album query</a></nobr> "
doc.WriteLine "<nobr><a href=""javascript:previmg('"&i&"')"">Previous image</a></nobr>"
doc.WriteLine "<p>Save:<input type=""checkbox"" id=""sav"&i&""""&chk&" onclick=""saveclick("&i&")"" /></p>"
doc.WriteLine "<div id=""dim"&i&""" accept=""""></div></td>"
If Images = 1 Then
doc.WriteLine "<td width=""50%"" align=""left""><div id=""img"&i&""">[Queued]</div></td></tr>"
Else
doc.WriteLine "<td width="""&col&"%"" align=""center"" style=""border-bottom:0px""><div id=""img"&i&"-1"">[Queued]</div></td>"
For k = 2 To Images
doc.WriteLine "<td width="""&col&"%"" align=""center"" style=""border-bottom:0px""><div id=""img"&i&"-"&k&"""> </div></td>"
Next
doc.WriteLine "</tr><tr id=""row"&i&"b"">"
For k = 1 To Images
doc.WriteLine "<td width="""&col&"%"" align=""center"" style=""border-top:0px""><div id=""dim"&i&"-"&k&""" accept=""""> </div></td>"
Next
doc.WriteLine "</tr>"
End If
End If
End If
Set songs = Nothing
albums.Next
'allow user to cancel
SDB.ProcessMessages
If prog.Terminate Then
If Debug Then
logf.WriteLine Time&" (Cancelled by user)"
logf.Close
End If
form.Common.ControlName = ""
Set SDB.Objects("BatchArtFinderForm") = Nothing
If Debug Then
logf.Close
End If
doc.Close
If fso.FileExists(paths.Item("htm")) Then
Call fso.DeleteFile(paths.Item("htm"))
End If
Exit Sub
End If
'maximum batch size
If Maximum > 0 Then
If i >= Maximum Then
If Debug Then
logf.WriteLine Time&" (Maximum of "&Maximum&" reached)"
End If
Exit Do
End If
End If
Loop
End If
Else
If Debug Then
logf.WriteLine Time&" (Selected albums)"
End If
prog.MaxValue = total+zero
Set albums = list.Albums
For j = 0 To albums.Count-1
prog.Increase
f = " "&i
If Maximum > 0 Then
f = f&"/"&Maximum
End If
prog.Text = "Batch Art Finder - checking album "&prog.Value&"/"&prog.MaxValue&" (found:"&f&")..."
Set album = albums.Item(j)
id = album.ID
If id > 0 Then
If (album.AlbumArt Is Nothing) Or (IncludeDone) Then
'add album ID to array
If Debug Then
logf.WriteLine Time&" AlbumID="&id
End If
i = i + 1
todo.Item(i) = id
'add album to form
sql = "SELECT Avg(Year/10000) As AvgYear, Sum(SongLength) As TotLength FROM Songs WHERE IDAlbum="&id
If Debug Then
logf.WriteLine Time&" #"&sql
End If
Set iter = SDB.Database.OpenSQL(sql)
avgyear = fixyear(iter.StringByName("AvgYear"))
totlength = gettime(iter.ValueByName("TotLength")/1000)
If Images = 1 Then
doc.WriteLine "<tr id=""row"&i&"a""><td width=""50%"" align=""right"">"
Else
doc.WriteLine "<tr id=""row"&i&"a""><td width=""50%"" align=""right"" rowspan=""2"">"
End If
doc.WriteLine "Album: "&UTF8_Encode(album.Name)
doc.WriteLine "<br />Artist: "&UTF8_Encode(album.Artist.Name)
doc.WriteLine "<br />Year: "&avgyear
doc.WriteLine "<br />Length: "&totlength
doc.WriteLine "<br /><br /><nobr><a href=""javascript:nextimg('"&i&"')"">Try next image</a></nobr> "
doc.WriteLine "<nobr><a href=""javascript:skipimg('"&i&"')"">Skip this album</a></nobr> "
doc.WriteLine "<nobr><a href=""javascript:editimg('"&i&"')"">Edit album query</a></nobr> "
doc.WriteLine "<nobr><a href=""javascript:previmg('"&i&"')"">Previous image</a></nobr>"
doc.WriteLine "<p>Save:<input type=""checkbox"" id=""sav"&i&""""&chk&" onclick=""saveclick("&i&")"" /></p>"
doc.WriteLine "<div id=""dim"&i&""" accept=""""></div></td>"
If Images = 1 Then
doc.WriteLine "<td width=""50%"" align=""left""><div id=""img"&i&""">[Queued]</div></td></tr>"
Else
doc.WriteLine "<td width="""&col&"%"" align=""center"" style=""border-bottom:0px""><div id=""img"&i&"-1"">[Queued]</div></td>"
For k = 2 To Images
doc.WriteLine "<td width="""&col&"%"" align=""center"" style=""border-bottom:0px""><div id=""img"&i&"-"&k&"""> </div></td>"
Next
doc.WriteLine "</tr><tr id=""row"&i&"b"">"
For k = 1 To Images
doc.WriteLine "<td width="""&col&"%"" align=""center"" style=""border-top:0px""><div id=""dim"&i&"-"&k&""" accept=""""> </div></td>"
Next
doc.WriteLine "</tr>"
End If
End If
End If
'allow user to cancel
SDB.ProcessMessages
If prog.Terminate Then
If Debug Then
logf.WriteLine Time&" (Cancelled by user)"
logf.Close
End If
form.Common.ControlName = ""
Set SDB.Objects("BatchArtFinderForm") = Nothing
If Debug Then
logf.Close
End If
doc.Close
If fso.FileExists(paths.Item("htm")) Then
Call fso.DeleteFile(paths.Item("htm"))
End If
Exit Sub
End If
'maximum batch size
If Maximum > 0 Then
If i >= Maximum Then
If Debug Then
logf.WriteLine Time&" (Maximum of "&Maximum&" reached)"
End If
Exit For
End If
End If
Next
If (Singles = 1) And ((Maximum = 0) Or (i < Maximum)) Then
If Debug Then
logf.WriteLine Time&" (Selected singles)"
End If
For j = 0 To list2.Count-1
prog.Increase
f = " "&i
If Maximum > 0 Then
f = f&"/"&Maximum
End If
prog.Text = "Batch Art Finder - checking album "&prog.Value&"/"&prog.MaxValue&" (found:"&f&")..."
Set album = list2.Item(j)
id = album.ID
If id > 0 Then
If (album.AlbumArt.Count = 0) Or (IncludeDone) Then
'add album ID to array
If Debug Then
logf.WriteLine Time&" SongID="&id
End If
i = i + 1
todo.Item(i) = "*"&id
'add single to form
If Images = 1 Then
doc.WriteLine "<tr id=""row"&i&"a""><td width=""50%"" align=""right"">"
Else
doc.WriteLine "<tr id=""row"&i&"a""><td width=""50%"" align=""right"" rowspan=""2"">"
End If
doc.WriteLine "Single: "&UTF8_Encode(album.Title)
doc.WriteLine "<br />Artist: "&UTF8_Encode(album.ArtistName)
doc.WriteLine "<br />Year: "&fixyear(album.Year)
doc.WriteLine "<br />Length: "&gettime(album.SongLength/1000)
doc.WriteLine "<br /><br /><nobr><a href=""javascript:nextimg('"&i&"')"">Try next image</a></nobr> "
doc.WriteLine "<nobr><a href=""javascript:skipimg('"&i&"')"">Skip this album</a></nobr> "
doc.WriteLine "<nobr><a href=""javascript:editimg('"&i&"')"">Edit album query</a></nobr> "
doc.WriteLine "<nobr><a href=""javascript:previmg('"&i&"')"">Previous image</a></nobr>"
doc.WriteLine "<p>Save:<input type=""checkbox"" id=""sav"&i&""""&chk&" onclick=""saveclick("&i&")"" /></p>"
doc.WriteLine "<div id=""dim"&i&""" accept=""""></div></td>"
If Images = 1 Then
doc.WriteLine "<td width=""50%"" align=""left""><div id=""img"&i&""">[Queued]</div></td></tr>"
Else
doc.WriteLine "<td width="""&col&"%"" align=""center"" style=""border-bottom:0px""><div id=""img"&i&"-1"">[Queued]</div></td>"
For k = 2 To Images
doc.WriteLine "<td width="""&col&"%"" align=""center"" style=""border-bottom:0px""><div id=""img"&i&"-"&k&"""> </div></td>"
Next
doc.WriteLine "</tr><tr id=""row"&i&"b"">"
For k = 1 To Images
doc.WriteLine "<td width="""&col&"%"" align=""center"" style=""border-top:0px""><div id=""dim"&i&"-"&k&""" accept=""""> </div></td>"
Next
doc.WriteLine "</tr>"
End If
End If
End If
Re: Batch Art Finder 4.1 - Updated 31/01/2011
page 3 of the code:
Code: Select all
'allow user to cancel
SDB.ProcessMessages
If prog.Terminate Then
If Debug Then
logf.WriteLine Time&" (Cancelled by user)"
logf.Close
End If
form.Common.ControlName = ""
Set SDB.Objects("BatchArtFinderForm") = Nothing
If Debug Then
logf.Close
End If
doc.Close
If fso.FileExists(paths.Item("htm")) Then
Call fso.DeleteFile(paths.Item("htm"))
End If
Exit Sub
End If
'maximum batch size
If Maximum > 0 Then
If i >= Maximum Then
If Debug Then
logf.WriteLine Time&" (Maximum of "&Maximum&" reached)"
End If
Exit For
End If
End If
Next
End If
End If
'finish document
doc.WriteLine "</table><p><a href=""javascript:select(0)"">Select all</a> <a href=""javascript:select(1)"">Select none</a> <a href=""javascript:select(2)"">Select inverse</a> <a href=""javascript:trynextall()"">Try next image for all</a></p>"
If ini.BoolValue("BatchArtFinder","SetSize") Then
doc.WriteLine "<span style=""visibility:hidden""><img id=""img0"" src=""""></span>"
End If
doc.WriteLine "</body></html>"
doc.Close
If Debug Then
logf.WriteLine Time&" Total="&i
logf.Close
End If
Set prog = Nothing
'show form if results
If i > 0 Then
Call wb.Interf.Navigate(paths.Item("htm"))
form.Common.Visible = True
If list Is Nothing Then
btn3.Common.Left = foot.Common.Width - btn3.Common.Width
btn2.Common.Left = btn3.Common.Left - btn2.Common.Width
Else
btn2.Common.Left = foot.Common.Width - btn2.Common.Width
End If
btn1.Common.Left = btn2.Common.Left - btn1.Common.Width
Set SDB.Objects("BatchArtFinderForm") = form
Set SDB.Objects("BatchArtFinderDoc") = wb.Interf.Document
'start first search
todo.Item("key") = 0
todo.Item("max") = i
todo.Item("mid") = 0
Set SDB.Objects("BatchArtFinderToDo") = todo
Call TriggerNext()
Else
form.Common.ControlName = ""
Set SDB.Objects("BatchArtFinderForm") = Nothing
If fso.FileExists(paths.Item("htm")) Then
Call fso.DeleteFile(paths.Item("htm"))
End If
ini.IntValue("BatchArtFinder","StartID") = 0
If IncludeDone Then
Call SDB.MessageBox("Batch Art Finder - all albums have been processed.",mtInformation,Array(mbOk))
Else
If rep.Exists("include") Then
i = Int(rep.Item("include"))
If i = mrNo Then
Call SDB.MessageBox("Batch Art Finder - there are no albums with missing artwork.",mtInformation,Array(mbOk))
End If
Else
i = SDB.MessageBox("Batch Art Finder - there are no albums with missing artwork, do you want to process albums with artwork?",mtConfirmation,Array(mbYes,mbNo))
rep.Item("include") = i
If Persist = 1 Then
ini.StringValue("BatchArtFinder","Replies3") = i
hnt = GetHint()
If Not (hnt = "") Then
hnt = Chr(13)&"-"&Chr(13)&hnt
End If
SDB.Objects("BAFToolbarButton").Caption = "Batch Art Finder"&hnt
End If
End If
If i = mrYes Then
ini.BoolValue("BatchArtFinder","IncludeDone") = True
Call DoBatchArtFinder(itm)
Exit Sub
End If
End If
End If
End Sub
Sub FormClose(form)
If Not (form Is Nothing) Then
Dim ini : Set ini = SDB.IniFile
If ini.IntValue("BatchArtFinder","PanelType") = 3 Then
ini.IntValue("BatchArtFinder","PanelDockedTo") = form.DockedTo
Else
ini.IntValue("BatchArtFinder","PanelTop") = form.Common.Top
ini.IntValue("BatchArtFinder","PanelLeft") = form.Common.Left
End If
ini.IntValue("BatchArtFinder","PanelWidth") = form.Common.Width
ini.IntValue("BatchArtFinder","PanelHeight") = form.Common.Height
form.Common.ControlName = ""
End If
Call ClearData()
End Sub
Sub TriggerNext()
'check for to-do list
SDB.ProcessMessages
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
If todo Is Nothing Then
Exit Sub
End If
If Int(todo.Item("mid")) = 1 Then
Exit Sub
End If
'get next item from list
Dim key : key = Int(todo.Item("key"))+1
Dim max : max = Int(todo.Item("max"))
todo.Item("key") = key
todo.Item("mid") = 1
'trigger next search
Dim form : Set form = SDB.Objects("BatchArtFinderForm")
If key <= max Then
Dim doc : Set doc = SDB.Objects("BatchArtFinderDoc")
If Not (doc Is Nothing) Then
Dim i,j,div,div2,qc,sc,nc,cc
Dim ini : Set ini = SDB.IniFile
MinW = ini.IntValue("BatchArtFinder","MinW")
MaxW = ini.IntValue("BatchArtFinder","MaxW")
MinH = ini.IntValue("BatchArtFinder","MinH")
MaxH = ini.IntValue("BatchArtFinder","MaxH")
MaxD = ini.IntValue("BatchArtFinder","MaxD")
SetSize = ini.BoolValue("BatchArtFinder","SetSize")
Debug = ini.BoolValue("BatchArtFinder","Debug")
Images = ini.IntValue("BatchArtFinder","Images")
'update status message
For i = 1 To max
If Images = 1 Then
Set div = doc.getElementById("img"&i)
Else
Set div = doc.getElementById("img"&i&"-1")
End If
If Not (div Is Nothing) Then
If div.innerHTML = "[Queued]" Then
qc = qc+1
End If
If div.innerHTML = "[Skipped]" Then
sc = sc+1
End If
If div.innerHTML = "[No results]" Then
nc = nc+1
End If
If div.innerHTML = "[Searching]" Then
cc = cc+1
End If
End If
Next
Dim fc : fc = max-(qc+sc+nc+cc)
Dim lbl : Set lbl = form.Common.ChildControl("lbl1")
lbl.Caption = "Found:"&fc&"/"&max&" (Queued:"&Int(qc)&" - Skipped:"&Int(sc)&" - No results:"&Int(nc)&")"
'check item status
If Images = 1 Then
Set div = doc.getElementById("img"&key)
Else
Set div = doc.getElementById("img"&key&"-1")
End If
If Not (div Is Nothing) Then
If div.innerHTML = "[Queued]" Then
div.innerHTML = "[Searching]"
Dim id : id = todo.Item(key)
Dim songs : Set songs = Nothing
If IsNumeric(id) Then
Set songs = SDB.Database.QuerySongs("AND (Songs.IDAlbum="&id&")")
If Not (songs.EOF) Then
Call ArtFinder(songs.Item)
todo.Item("mid") = 0
Exit Sub
Else
div.innerHTML = "[Skipped]"
doc.getElementById("dim"&key).innerHTML = ""
If Images > 1 Then
doc.getElementById("dim"&key&"-1").innerHTML = " "
For j = 2 To Images
doc.getElementById("img"&key&"-"&j).innerHTML = " "
doc.getElementById("dim"&key&"-"&j).innerHTML = " "
Next
End If
doc.getElementById("sav"&key).checked = False
End If
Else
Set songs = SDB.Database.QuerySongs("AND (Songs.ID="&Mid(id,2)&")")
If Not (songs.EOF) Then
Call ArtFinderSingle(songs.Item)
todo.Item("mid") = 0
Exit Sub
End If
End If
Set songs = Nothing
Else
For j = 1 To Images
If Images = 1 Then
Set div2 = doc.getElementById("dim"&key)
Else
Set div = doc.getElementById("img"&key&"-"&j)
Set div2 = doc.getElementById("dim"&key&"-"&j)
End If
If Not (div2 Is Nothing) And (div2.getAttribute("accept") <> "accept") And (div.innerHTML <> " ") Then
Dim img : Set img = div.Children.Item(0) '<a>
If Not (img Is Nothing) Then
Set img = img.Children.Item(0) '<img>
If Not (img Is Nothing) Then
Dim cnt : cnt = img.getAttribute("count")
If Not (cnt = "") Then
cnt = "Image: "&cnt&"<br />"
End If
Dim sts : sts = img.readyState
If (sts = "complete") Or (img.complete = True) Then
If SetSize Then
Dim img2 : Set img2 = doc.getElementById("img0")
If Not (img2 Is Nothing) Then
img2.src = img.src
If (img2.Width > 0) And (img2.Height > 0) Then
If (img2.Width = 28) And (img2.Height = 30) Then 'red cross
div2.innerHTML = cnt&"Not available"
If Debug Then
Call out("Image '"&img.src&"' showing red cross (album:"&key&" column:"&j&")")
End If
Call ShowNextResult(key)
Else
Dim dif2 : dif2 = Abs(img2.Width-img2.Height)
If (img2.Width<MinW) Or (img2.Width>MaxW) Or (img2.Height<MinH) Or (img2.Height>MaxH) Or (dif2>MaxD) Then
If (img2.Width<MinW) Or (img2.Height<MinH) Then
div2.innerHTML = cnt&"Size: "&img2.Width&"x"&img2.Height&"<br />Too small"
If Debug Then
Call out("Image '"&img2.src&"' is too small: "&img2.Width&"x"&img2.Height&" (album:"&key&" column:"&j&")")
End If
Else
If (img2.Width>MaxW) Or (img2.Height>MaxH) Then
div2.innerHTML = cnt&"Size: "&img2.Width&"x"&img2.Height&"<br />Too large"
If Debug Then
Call out("Image '"&img2.src&"' is too large: "&img2.Width&"x"&img2.Height&" (album:"&key&" column:"&j&")")
End If
Else
div2.innerHTML = cnt&"Size: "&img2.Width&"x"&img2.Height&"<br />Not square"
If Debug Then
Call out("Image '"&img2.src&"' is not square: "&img2.Width&"x"&img2.Height&" (album:"&key&" column:"&j&")")
End If
End If
End If
Call ShowNextResult(key)
Else
div2.innerHTML = cnt&"Size: "&img2.Width&"x"&img2.Height
If Debug Then
Call out("Image '"&img2.src&"' is ok (album:"&key&" column:"&j&")")
End If
Call div2.setAttribute("accept","accept")
If Images > 1 Then
Call ShowNextResult(key)
End If
End If
End If
End If
img2.src = ""
End If
Else
If (img.Width > 0) And (img.Height > 0) Then
If (img.Width = 28) And (img.Height = 30) Then 'red cross
div2.innerHTML = cnt&"Not available"
If Debug Then
Call out("Image '"&img.src&"' showing red cross (album:"&key&" column:"&j&")")
End If
Call ShowNextResult(key)
Else
Dim dif : dif = Abs(img.Width-img.Height)
If (img.Width<MinW) Or (img.Width>MaxW) Or (img.Height<MinH) Or (img.Height>MaxH) Or (dif>MaxD) Then
If (img.Width<MinW) Or (img.Height<MinH) Then
div2.innerHTML = cnt&"Size: "&img.Width&"x"&img.Height&"<br />Too small"
If Debug Then
Call out("Image '"&img.src&"' is too small: "&img.Width&"x"&img.Height&" (album:"&key&" column:"&j&")")
End If
Else
If (img.Width>MaxW) Or (img.Height>MaxH) Then
div2.innerHTML = cnt&"Size: "&img.Width&"x"&img.Height&"<br />Too large"
If Debug Then
Call out("Image '"&img.src&"' is too large: "&img.Width&"x"&img.Height&" (album:"&key&" column:"&j&")")
End If
Else
div2.innerHTML = cnt&"Size: "&img.Width&"x"&img.Height&"<br />Not square"
If Debug Then
Call out("Image '"&img.src&"' is not square: "&img.Width&"x"&img.Height&" (album:"&key&" column:"&j&")")
End If
End If
End If
Call ShowNextResult(key)
Else
div2.innerHTML = cnt&"Size: "&img.Width&"x"&img.Height
If Debug Then
Call out("Image '"&img.src&"' is ok (album:"&key&" column:"&j&")")
End If
Call div2.setAttribute("accept","accept")
If Images > 1 Then
Call ShowNextResult(key)
End If
End If
End If
End If
End If
Else
If sts = "uninitialized" Then
Dim red : red = Int(img.getAttribute("cross"))
If red = 3 Then
div2.innerHTML = cnt&"Not available"
If Debug Then
Call out("Image '"&img.src&"' showing red cross (album:"&key&" column:"&j&")")
End If
Call ShowNextResult(key)
Else
Call img.setAttribute("cross",red+1)
End If
End If
End If
End If
End If
End If
Next
End If
End If
End If
todo.Item("mid") = 0
Call TriggerNext()
Else
'check form still exists and visible
If Not (form Is Nothing) Then
If form.Common.Visible Then
'pause then start from the top
todo.Item("key") = 0
todo.Item("mid") = 0
Call Script.RegisterEvent(SDB.CreateTimer(1000),"OnTimer","DelayTrigger")
Exit Sub
End If
End If
Call ClearData()
End If
End Sub
Sub DelayTrigger(DelayTimer)
Call Script.UnregisterEvents(DelayTimer)
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
If todo Is Nothing Then
Exit Sub
End If
If Int(todo.Item("mid")) = 0 Then
Call TriggerNext()
End If
End Sub
Sub ArtFinder(itm)
'check for previous search
Dim url : url = ""
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
Dim key : key = todo.Item("key")
Dim data : Set data = SDB.Objects("BAFData"&key)
Dim ini : Set ini = SDB.IniFile
Source = ini.IntValue("BatchArtFinder","Source")
Titles = ini.IntValue("BatchArtFinder","Titles")
Debug = ini.BoolValue("BatchArtFinder","Debug")
FileMask = ini.StringValue("BatchArtFinder","FileMask")
Exists = ini.BoolValue("BatchArtFinder","Exists")
FileTypes = ini.StringValue("BatchArtFinder","FileTypes")
Images = ini.IntValue("BatchArtFinder","Images")
Dim path : path = itm.Path
Dim i : i = InStrRev(path,"\")-1
If i > 0 Then
path = Left(path,i)
Else
If Debug Then
Call out("path="&path)
End If
path = ""
End If
If Not (data Is Nothing) Then
'use previous data
url = data.Item("url")
Exists = False 'only check first time
Else
'create search url
Dim artist : artist = ""
If itm.AlbumArtistName = "" Then
artist = mapname(itm.ArtistName)
Else
artist = mapname(itm.AlbumArtistName)
End If
Dim album : album = ""
If Titles = 1 Then
album = mapname(itm.Title)
Else
album = mapname(itm.AlbumName)
End If
Select Case Source
Case 0
url = "http://images.google.com/images?q="&artist&"+"&album
Select Case ini.IntValue("BatchArtFinder","ImageSize")
Case 0
ImageSize = "&imgsz=icon"
Case 1
ImageSize = "&imgsz=medium"
Case 2
ImageSize = "&imgsz=xxlarge"
Case 4
ImageSize = "&imgw="&ini.IntValue("BatchArtFinder","MinW")&"&imgh="&ini.IntValue("BatchArtFinder","MinH")
Case 5
ImageSize = "&imgw="&ini.IntValue("BatchArtFinder","MaxW")&"&imgh="&ini.IntValue("BatchArtFinder","MaxH")
Case 6
ImageSize = "&imgw="&ini.IntValue("BatchArtFinder","SetW")&"&imgh="&ini.IntValue("BatchArtFinder","SetH")
Case Else
ImageSize = ""
End Select
url = url&"&svnum=100&hl=en&lr=lang_en&newwindow=0&safe=off&sa=G"&ImageSize&"&ie=UTF-8&oe=UTF-8"
Case 1
url = "http://www.bing.com/images/search?q="&artist&"+"&album&"&qs=AS&sk=AS1"
Case 2
url = "http://www.gomusicnow.com/search.html?query="&artist&"+"&album
Case 3
url = "http://www.albumart.org/index.php?srchkey="&album&"&itempage=1&newsearch=1&searchindex=Music"
Case 4
url = "http://ws.audioscrobbler.com/2.0/?method=album.getInfo&api_key="&api&"&artist="&artist&"&album="&album
'!
End Select
'store data and url
Set data = CreateObject("Scripting.Dictionary")
data.Add "path",path
If itm.AlbumArtistName = "" Then
data.Add "artist",itm.ArtistName
data.Add "oartist",itm.ArtistName
Else
data.Add "artist",itm.AlbumArtistName
data.Add "oartist",itm.AlbumArtistName
End If
If Titles = 1 Then
data.Add "album",itm.Title
data.Add "oalbum",itm.Title
Else
data.Add "album",itm.AlbumName
data.Add "oalbum",itm.AlbumName
End If
data.Add "id",itm.Album.ID
data.Add "type","album"
data.Add "image",0
data.Add "result",0
data.Add "count",0
data.Add "url",url
data.Add "previous",0
Set SDB.Objects("BAFData"&todo.Item("key")) = data
End If
'check for existing file
If Exists Then
Dim dest : dest = FileMask
dest = Replace(dest,"<path>",path)
If itm.AlbumArtistName = "" Then
dest = Replace(dest,"<artist>",itm.ArtistName)
Else
dest = Replace(dest,"<artist>",itm.AlbumArtistName)
End If
If Titles = 1 Then
dest = Replace(dest,"<album>",itm.Title)
Else
dest = Replace(dest,"<album>",itm.AlbumName)
End If
dest = Replace(dest,"<id>",itm.Album.ID)
dest = Left(dest,2)&CorrectPath(Mid(dest,3))&"."
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim arr : arr = Split(FileTypes,",")
For i = 0 To UBound(arr)
Dim src : src = dest&arr(i)
If fso.FileExists(src) Then
If Debug Then
Call out("Image '"&src&"' already exists (album:"&key&")")
End If
Dim doc : Set doc = SDB.Objects("BatchArtFinderDoc")
If Not (doc Is Nothing) Then
Dim div,div2
If Images = 1 Then
Set div = doc.getElementById("img"&key)
Set div2 = doc.getElementById("dim"&key)
Else
Set div = doc.getElementById("img"&key&"-1")
Set div2 = doc.getElementById("dim"&key&"-1")
End If
If Not (div Is Nothing) Then
Call div.setAttribute("found","found")
If Not (div2 Is Nothing) Then
div2.className = ""
dest = Replace(src,"\","/")
data.Item("source") = src
data.Item("dest") = src
Dim str : str = "<img src=""file://"&dest&""" title="""&src&""""
If ini.BoolValue("BatchArtFinder","SetSize") Then
str = str&" width="""&ini.IntValue("BatchArtFinder","SetW")&"px"" height="""&ini.IntValue("BatchArtFinder","SetH")&"px"""
End If
str = str&" count="""" cross=""0"" /></a>"
If Images = 1 Then
div.innerHTML = "<a href=""javascript://"">"&str
Else
div.innerHTML = "<a href=""javascript://"" onclick=""highlight('"&div.id&"')"">"&str
End If
div2.innerHTML = "Image 1 of 1<br />Loading..."
Call Script.RegisterEvent(SDB.CreateTimer(1000),"OnTimer","DelayTrigger")
Exit Sub
End If
End If
End If
End If
Next
End If
'navigate to search url
Select Case Source
Case 4
If Debug Then
Call out("@"&url)
End If
Dim xml : Set xml = CreateObject("Microsoft.XMLHTTP")
Call xml.open("GET",url,true)
Call xml.send()
Set SDB.Objects("BatchArtFinderXML") = xml
Call Script.RegisterEvent(SDB.CreateTimer(500),"OnTimer","WaitTilReady2")
Case Else
Dim IE : Set IE = SDB.Objects("BatchArtFinderShell")
If Not (IE Is Nothing) Then
If Debug Then
Call out("@"&url)
End If
Call IE.Navigate(url)
Call Script.RegisterEvent(SDB.CreateTimer(500),"OnTimer","WaitTilReady")
End If
End Select
End Sub
Sub ArtFinderSingle(itm)
'check for previous search
Dim url : url = ""
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
Dim data : Set data = SDB.Objects("BAFData"&todo.Item("key"))
Dim ini : Set ini = SDB.IniFile
Source = ini.IntValue("BatchArtFinder","Source")
Debug = ini.BoolValue("BatchArtFinder","Debug")
If Not (data Is Nothing) Then
'use previous data
url = data.Item("url")
Else
'create search url
Dim path : path = itm.Path
Dim i : i = InStrRev(path,"\")-1
Dim artist : artist = mapname(itm.ArtistName)
Dim album : album = mapname(itm.Title)
Select Case Source
Case 0
url = "http://images.google.com/images?q="&artist
If ini.IntValue("BatchArtFinder","Include") = 1 Then
url = url&"+"&album
End If
Select Case ini.IntValue("BatchArtFinder","ImageSize")
Case 0
ImageSize = "&imgsz=icon"
Case 1
ImageSize = "&imgsz=medium"
Case 2
ImageSize = "&imgsz=xxlarge"
Case 4
ImageSize = "&imgw="&ini.IntValue("BatchArtFinder","MinW")&"&imgh="&ini.IntValue("BatchArtFinder","MinH")
Case 5
ImageSize = "&imgw="&ini.IntValue("BatchArtFinder","MaxW")&"&imgh="&ini.IntValue("BatchArtFinder","MaxH")
Case 6
ImageSize = "&imgw="&ini.IntValue("BatchArtFinder","SetW")&"&imgh="&ini.IntValue("BatchArtFinder","SetH")
Case Else
ImageSize = ""
End Select
url = url&"&svnum=100&hl=en&lr=lang_en&newwindow=0&safe=off&sa=G"&ImageSize&"&ie=UTF-8&oe=UTF-8"
Case 1
url = "http://www.bing.com/images/search?q="&artist&"+"&album&"&qs=AS&sk=AS1"
Case 2
url = "http://www.gomusicnow.com/search.html?query="&artist&"+"&album
Case 3
url = "http://www.albumart.org/index.php?srchkey="&album&"&itempage=1&newsearch=1&searchindex=Music"
Case 4
url = "http://ws.audioscrobbler.com/2.0/?method=album.getInfo&api_key="&api&"&artist="&artist&"&album="&album
'!
End Select
'store data and url
Set data = CreateObject("Scripting.Dictionary")
data.Add "path",Mid(path,1,i)
data.Add "artist",itm.ArtistName
data.Add "album",itm.Title
data.Add "oartist",itm.ArtistName
data.Add "oalbum",itm.Title
data.Add "id",itm.ID
data.Add "type","track"
data.Add "image",0
data.Add "result",0
data.Add "count",0
data.Add "url",url
data.Add "previous",0
Set SDB.Objects("BAFData"&todo.Item("key")) = data
End If
'navigate to search url
Select Case Source
Case 4
If Debug Then
Call out("@"&url)
End If
Dim xml : Set xml = CreateObject("Microsoft.XMLDOM")
xml.async = True
Call xml.Load(url)
Set SDB.Objects("BatchArtFinderXML") = xml
Call Script.RegisterEvent(SDB.CreateTimer(500),"OnTimer","WaitTilReady2")
Case Else
Dim IE : Set IE = SDB.Objects("BatchArtFinderShell")
If Not (IE Is Nothing) Then
If Debug Then
Call out("@"&url)
End If
Call IE.Navigate(url)
Call Script.RegisterEvent(SDB.CreateTimer(500),"OnTimer","WaitTilReady")
End If
End Select
End Sub
Sub WaitTilReady(WaitTimer)
'check search page exists
Dim IE : Set IE = SDB.Objects("BatchArtFinderShell")
If (IE Is Nothing) Then
'user cancelled
Call Script.UnregisterEvents(WaitTimer)
Else
'check page is ready
If (IE.ReadyState = 4) Then
Call Script.UnregisterEvents(WaitTimer)
ShowFirstResult(IE.Document.Images)
End If
End If
End Sub
Function ShowFirstResult(list)
ShowFirstResult = False
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
If todo Is Nothing Then
Exit Function
End If
Dim key : key = todo.Item("key")
Dim data : Set data = SDB.Objects("BAFData"&key)
If data Is Nothing Then
Exit Function
End If
'get settings
Dim i : i = 0
Dim cur : cur = 0
Dim tot : tot = 0
Dim max : max = list.Length
Dim str : str = ""
Dim ext : ext = ""
Dim ini : Set ini = SDB.IniFile
Debug = ini.BoolValue("BatchArtFinder","Debug")
Source = ini.IntValue("BatchArtFinder","Source")
ImageSize = ini.IntValue("BatchArtFinder","ImageSize")
SetSize = ini.BoolValue("BatchArtFinder","SetSize")
If SetSize Then
SetW = ini.IntValue("BatchArtFinder","SetW")
SetH = ini.IntValue("BatchArtFinder","SetH")
str = " width="""&SetW&"px"" height="""&SetH&"px"""
End If
FileTypes = ini.StringValue("BatchArtFinder","FileTypes")
Images = ini.IntValue("BatchArtFinder","Images")
Dim arr : arr = Split(UCase(FileTypes),",")
'check list of images returned
For i = 0 To max-1
'check for invalid pointer
On Error Resume Next
Dim itm : Set itm = list.Item(i)
Dim src : src = itm.getAttribute("src")
If Not (Err.Number = 0) Then
Err.Clear
src = ""
End If
If (src = "") Or (Left(src,5) = "data:") Then
src = ""
If UCase(itm.parentNode.tagName) = "A" Then
src = itm.parentNode.getAttribute("href")
If Not (Err.Number = 0) Then
Err.Clear
src = ""
End If
End If
End If
On Error Goto 0
'fix source url
If Not (src = "") Then
src = Replace(src,"%25","%")
src = Replace(src,"%20"," ")
src = Replace(src,"%2F","/")
Select Case Source
Case 0
If InStr(src,"http://images.google.com/imgres?imgurl=") = 1 Then
src = Replace(src,"http://images.google.com/imgres?imgurl=","")
If InStr(src,"&imgrefurl=") > 1 Then
src = Left(src,InStr(src,"&imgrefurl=")-1)
End If
End If
Case 1
src = Replace(src,"/album_images/t","/album_images/s")
Case 2
If ImageSize > 0 Then
If ImageSize = 1 Then
src = Replace(src,"/75/","/150/")
src = Replace(src,"-TN","")
Else
src = Replace(src,"/75/","/full/")
If InStr(src,"-TN") > 0 Then
src = Replace(src,"-TN","-BIG")
Else
src = Replace(src,".jpg","-BIG.jpg")
End If
End If
End If
Case 3
If ImageSize > 1 Then
src = Replace(src,"160","500")
End If
'!
End Select
'check filetype
If InFileTypes(arr,src,ext) Then
cur = cur+1
tot = tot+1
data.Item("img"&cur) = src
If Debug Then
Call out("Image '"&src&"' is ok (album:"&key&" found:"&tot&")")
End If
Else
If Debug Then
Call out("Image '"&src&"' is wrong type: "&UCase(Mid(ext,2))&" (album:"&key&")")
End If
End If
End If
Next
If Debug Then
Call out("Images="&tot&"/"&max)
End If
'update document
Dim doc : Set doc = SDB.Objects("BatchArtFinderDoc")
If Not (doc Is Nothing) Then
Dim div,div2
If Images = 1 Then
Set div = doc.getElementById("img"&key)
Set div2 = doc.getElementById("dim"&key)
Else
Set div = doc.getElementById("img"&key&"-1")
Set div2 = doc.getElementById("dim"&key&"-1")
End If
If Not (div Is Nothing) Then
Call div.setAttribute("found","")
If Not (div2 Is Nothing) Then
div2.className = ""
If tot = 0 Then
div.innerHTML = "[No results]"
Else
ShowFirstResult = True
src = data.Item("img1")
data.Item("image") = 1
data.Item("result") = 1
data.Item("count") = tot
data.Item("source") = src
data.Item("previous") = 0
str = "<img src="""&src&""" title="""&src&""" count=""1 of "&tot&""""&str&" cross=""0"" /></a>"
If Images = 1 Then
div.innerHTML = "<a href="""&data.Item("url")&""" target=""_blank"">"&str
Else
div.innerHTML = "<a href=""javascript://"" onclick=""highlight('"&div.id&"')"">"&str
End If
div2.innerHTML = "Image: 1 of "&tot&"<br />Loading..."
End If
End If
End If
End If
'start next search
Call TriggerNext()
End Function
Sub ShowNextResult(key)
Dim data : Set data = SDB.Objects("BAFData"&key)
If data Is Nothing Then
Exit Sub
End If
Dim ini : Set ini = SDB.IniFile
Images = ini.IntValue("BatchArtFinder","Images")
'update document
Dim doc : Set doc = SDB.Objects("BatchArtFinderDoc")
If Not (doc Is Nothing) Then
Dim div,div2,res,i
If Images = 1 Then
res = 1
Set div = doc.getElementById("img"&key)
Set div2 = doc.getElementById("dim"&key)
Else
res = Int(data.Item("result"))
Set div = doc.getElementById("img"&key&"-"&res)
Set div2 = doc.getElementById("dim"&key&"-"&res)
End If
If Not (div Is Nothing) Then
If Not (div2 Is Nothing) Then
If (Images > 1) And (div2.getAttribute("accept") = "accept") Then
res = res+1
If res > Images Then
Exit Sub
End If
Set div = doc.getElementById("img"&key&"-"&res)
Set div2 = doc.getElementById("dim"&key&"-"&res)
End If
Call div.setAttribute("found","")
div2.className = ""
Dim cur : cur = Int(data.Item("image"))+1
If Int(data.Item("previous")) = 1 Then
cur = cur-2
End If
Dim tot : tot = Int(data.Item("count"))
If (cur < 1) Or (cur > tot) Then
div.innerHTML = "[No results]"
If Images = 1 Then
div2.innerHTML = ""
Else
div2.innerHTML = " "
End If
Else
Dim src : src = data.Item("img"&cur)
data.Item("image") = cur
data.Item("result") = res
data.Item("source") = src
Dim str : str = "<img src="""&src&""" title="""&src&""" count="""&cur&" of "&tot&""""
If ini.BoolValue("BatchArtFinder","SetSize") Then
str = str&" width="""&ini.IntValue("BatchArtFinder","SetW")&"px"" height="""&ini.IntValue("BatchArtFinder","SetH")&"px"""
End If
str = str&" cross=""0"" /></a>"
If Images = 1 Then
div.innerHTML = "<a href="""&data.Item("url")&""" target=""_blank"">"&str
Else
div.innerHTML = "<a href=""javascript://"" onclick=""highlight('"&div.id&"')"">"&str
End If
div2.innerHTML = "Image: "&cur&" of "&tot&"<br />Loading..."
End If
End If
End If
End If
End Sub
Sub WaitTilReady2(WaitTimer)
'check xml exists
Dim xml : Set xml = SDB.Objects("BatchArtFinderXML")
If (xml Is Nothing) Then
'user cancelled
Call Script.UnregisterEvents(WaitTimer)
Else
'check xml is ready
If (xml.ReadyState = 4) Then
Call Script.UnregisterEvents(WaitTimer)
Dim str : str = xml.responseText
Set xml = LoadLastFmXML(str)
ShowFirstResult2(xml)
End If
End If
End Sub
Function ShowFirstResult2(xml)
ShowFirstResult2 = False
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
If todo Is Nothing Then
Exit Function
End If
Dim key : key = todo.Item("key")
Dim data : Set data = SDB.Objects("BAFData"&key)
If data Is Nothing Then
Exit Function
End If
Dim ini : Set ini = SDB.IniFile
Debug = ini.BoolValue("BatchArtFinder","Debug")
Images = ini.IntValue("BatchArtFinder","Images")
'get relevant data
Dim tot : tot = 0
Dim img : img = Int(data.Item("image"))
If img = 0 Then
Dim str : str = ""
ImageSize = ini.IntValue("BatchArtFinder","ImageSize")
SetSize = ini.BoolValue("BatchArtFinder","SetSize")
If SetSize Then
SetW = ini.IntValue("BatchArtFinder","SetW")
SetH = ini.IntValue("BatchArtFinder","SetH")
str = " width="""&SetW&"px"" height="""&SetH&"px"""
End If
FileTypes = ini.StringValue("BatchArtFinder","FileTypes")
Dim arr : arr = Split(UCase(FileTypes),",")
If ImageSize < 3 Then
img = ImageSize
Else
img = 2
End If
Dim alb,ele,i,src,ext
For Each alb In xml.getElementsByTagName("album")
For i = img+1 To 0 Step -1
Set ele = alb.getElementsByTagName("image").Item(i)
If Not (ele Is Nothing) Then
src = ele.Text
If Not (src = "") Then
If InFileTypes(arr,src,ext) Then
tot = 1
data.Item("img1") = src
If Debug Then
Call out("Image '"&src&"' is ok (album:"&key&" found:1)")
End If
Exit For
Else
If Debug Then
Call out("Image '"&src&"' is wrong type: "&UCase(Mid(ext,2))&" (album:"&key&")")
End If
End If
End If
End If
Next
Next
End If
If Debug Then
Call out("Images="&tot&"/1")
End If
'update document
Dim doc : Set doc = SDB.Objects("BatchArtFinderDoc")
If Not (doc Is Nothing) Then
Dim div : Set div = doc.getElementById("img"&key)
If Not (div Is Nothing) Then
If tot = 0 Then
div.innerHTML = "[No results]"
Else
ShowFirstResult2 = True
src = data.Item("img1")
data.Item("image") = 1
data.Item("result") = 1
data.Item("count") = 1
data.Item("source") = src
data.Item("previous") = 0
If Images = 1 Then
Set div2 = doc.getElementById("dim"&key)
Else
Set div = doc.getElementById("img"&key&"-1")
Set div2 = doc.getElementById("dim"&key&"-1")
End If
If Not (div Is Nothing) Then
Call div.setAttribute("found","")
If Not (div2 Is Nothing) Then
str = "<img src="""&src&""" title="""&src&""" count=""1 of 1"""&str&" cross=""0"" /></a>"
If Images = 1 Then
div.innerHTML = "<a href="""&data.Item("url")&""" target=""_blank"">"&str
Else
div.innerHTML = "<a href=""javascript://"" onclick=""highlight('"&div.id&"')"">"&str
End If
div2.innerHTML = "Image: 1 of 1<br />Loading..."
End If
End If
End If
End If
End If
Re: Batch Art Finder 4.1 - Updated 31/01/2011
Page 4 of the code:
Code: Select all
'start next search
Call TriggerNext()
End Function
Sub TryClick()
Dim ini : Set ini = SDB.IniFile
CheckAll = ini.IntValue("BatchArtFinder","CheckAll")
Images = ini.IntValue("BatchArtFinder","Images")
Dim doc : Set doc = SDB.Objects("BatchArtFinderDoc")
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
Dim max : max = Int(todo.Item("max"))
Dim i,j,tot,div,row,img,chk
For i = 1 To max
Set div = doc.getElementById("dim"&i)
If Not (div Is Nothing) Then
If div.innerHTML = "Saved!" Then
Set row = doc.getElementById("row"&i&"a")
If Not (row Is Nothing) Then
row.style.display = "none"
tot = tot+1
If Images > 1 Then
Set row = doc.getElementById("row"&i&"b")
If Not (row Is Nothing) Then
row.style.display = "none"
End If
End If
End If
Else
div.innerHTML = ""
Call ShowNextResult(i)
If CheckAll = 1 Then
Set chk = doc.getElementById("sav"&i)
If Not (chk Is Nothing) Then
chk.checked = True
End If
End If
End If
End If
Next
If tot < max Then
Dim but : Set but = SDB.Objects("BAFClickedBtn")
but.Common.Enabled = True
Set SDB.Objects("BAFClickedBtn") = Nothing
Else
Call NextClick(Nothing)
End If
End Sub
Sub SaveClick(ClickedBtn)
ClickedBtn.Common.Enabled = False
Set SDB.Objects("BAFClickedBtn") = ClickedBtn
'check status of images
Dim ini : Set ini = SDB.IniFile
Dim doc : Set doc = SDB.Objects("BatchArtFinderDoc")
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
Dim max : max = Int(todo.Item("max"))
Dim count : count = 0
Dim i,div
For i = 1 To max
Set div = doc.getElementById("sav"&i)
If Not (div Is Nothing) Then
If div.Checked Then
count = count + 1
End If
End If
Next
Dim oldmax : oldmax = todo.Item("max")
todo.Item("max") = "0"
'exit if no images to save
If count = 0 Then
todo.Item("key") = 0
todo.Item("max") = oldmax
'perform save action
Select Case ini.IntValue("BatchArtFinder","SaveMode")
Case 1 'next
Call NextClick(Nothing)
Case 2 'exit
Dim form : Set form = SDB.Objects("BatchArtFinderForm")
form.Common.Visible = False
Call FormClose(form)
Case 3 'trynext
Call TryClick()
Case Else 'nothing
ClickedBtn.Common.Enabled = True
Call TriggerNext()
End Select
Exit Sub
End If
'setup internet connection
On Error Resume Next
Dim inet : Set inet = CreateObject("InetCtls.Inet")
If Err.Number <> 0 Then
Dim wsh : Set wsh = CreateObject("WScript.Shell")
wsh.RegWrite "HKLM\SOFTWARE\Classes\Licenses\78E1BDD1-9941-11cf-9756-00AA00C00908\","yjrjvqkjlqqjnqkjvprqsjnjvkuknjpjtoun","REG_SZ"
Dim cmd : cmd = SDB.ApplicationPath&"Scripts\Auto\msinet.ocx"
cmd = "regsvr32 "&Chr(34)&cmd&Chr(34)&" /s"
i = wsh.Run(cmd,1,1)
Err.Clear
Set inet = CreateObject("InetCtls.Inet")
If Err.Number <> 0 Then
Call SDB.MessageBox("Batch Art Finder - the MSInet component could not be found, please install before running this script.",mtError,Array(mbOk))
Call ClearData()
Exit Sub
End If
End If
On Error GoTo 0
Set SDB.Objects("BAFinet") = Nothing
'setup download queue
Dim queue : Set queue = CreateObject("Scripting.Dictionary")
queue.Item("i") = 1
queue.Item("max") = max
queue.Item("old") = oldmax
Set SDB.Objects("BAFQueue") = queue
'start first download
Call Script.RegisterEvent(SDB.CreateTimer(100),"onTimer","preDownload")
End Sub
Sub preDownload(preTmr)
'wait for space
SDB.ProcessMessages
Dim ini : Set ini = SDB.IniFile
Debug = ini.BoolValue("BatchArtFinder","Debug")
Images = ini.IntValue("BatchArtFinder","Images")
Dim inet : Set inet = SDB.Objects("BAFinet")
If inet Is Nothing Then
'create internet connection
Set inet = CreateObject("InetCtls.Inet")
Set SDB.Objects("BAFinet") = inet
'get queue data
Dim queue : Set queue = SDB.Objects("BAFQueue")
Dim i : i = Int(queue.Item("i"))
Dim max : max = Int(queue.Item("max"))
If i > max Then
Call Script.UnregisterEvents(preTmr)
Call queueIsEmpty()
Exit Sub
End If
If Debug Then
Call out("Initialising "&i&" of "&max)
End If
'check there is an image to save
Dim doc : Set doc = SDB.Objects("BatchArtFinderDoc")
If Not (doc Is Nothing) Then
Dim div : Set div = doc.getElementById("sav"&i)
If Not (div Is Nothing) Then
If div.Checked = True Then
Dim data : Set data = SDB.Objects("BAFData"&i)
If Images = 1 Then
Set div = doc.getElementById("img"&i)
Else
Dim res : res = Int(data.Item("result"))
Set div = doc.getElementById("img"&i&"-"&res)
End If
If Not (div Is Nothing) Then
If div.getAttribute("found") = "found" Then
Call postDownload(i)
Else
If Left(div.innerHTML,1) = "<" Then
'build path from mask and data
FileMask = ini.StringValue("BatchArtFinder","FileMask")
Dim url : url = data.Item("source")
Dim dest : dest = FileMask&LCase(Mid(url,InStrRev(url,".")))
dest = Replace(dest,"<path>",data.Item("path"))
dest = Replace(dest,"<artist>",data.Item("oartist"))
dest = Replace(dest,"<album>",data.Item("oalbum"))
dest = Replace(dest,"<id>",data.Item("id"))
Dim path : path = CorrectPath(Mid(dest,3))
data.Item("dest") = Left(dest,2)&path
'start next download
If Debug Then
Call out("Downloading "&url)
End If
inet.url = url
inet.requestTimeout = 10
On Error Resume Next
Call inet.Execute
If Err.Number > 0 Then
If Debug Then
Call out("***"&Err.Number&" - "&Err.Description&" ("&Err.Source&")")
Call out("Retrying...")
End If
Err.Clear
Set SDB.Objects("BAFinet") = Nothing
Exit Sub
End If
On Error GoTo 0
Call Script.RegisterEvent(SDB.CreateTimer(100),"onTimer","theDownload")
Exit Sub
Else
If ini.IntValue("BatchArtFinder","Default") = 1 Then
data.Item("dest") = getnonejpg()
Call postDownload(i)
End If
End If
End If
End If
End If
End If
End If
'update queue
queue.Item("i") = i+1
Set SDB.Objects("BAFinet") = Nothing
End If
End Sub
Sub theDownload(theTmr)
'wait for connection
SDB.ProcessMessages
Dim ini : Set ini = SDB.IniFile
Debug = ini.BoolValue("BatchArtFinder","Debug")
Dim inet : Set inet = SDB.Objects("BAFinet")
If Not inet.StillExecuting Then
Call Script.UnregisterEvents(theTmr)
If Debug Then
Call out("Downloading complete")
End If
'get queue data
Dim queue : Set queue = SDB.Objects("BAFQueue")
Dim i : i = Int(queue.Item("i"))
Dim data : Set data = SDB.Objects("BAFData"&i)
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim dest : dest = data.Item("dest")
Dim path : path = Left(dest,InStrRev(dest,"\"))
Call GeneratePath(fso,path)
'create binary file
On Error Resume Next
Dim bin : Set bin = CreateObject("ADODB.Stream")
If Not (bin Is Nothing) Then
If Debug Then
Call out("Saving "&dest)
End If
bin.Type = 1
Call bin.Open()
'copy from buffer in chunks
Dim done : done = False
Do
SDB.ProcessMessages
Dim buf : buf = inet.GetChunk(512,1)
If UBound(buf) < 1 Then
done = True
Else
Call bin.Write(buf)
End If
Loop Until done
'save binary file
Call bin.SaveToFile(dest,2)
Call bin.Close()
Set bin = Nothing
End If
'error handling
If Err.Number > 0 Then
If Debug Then
Call out("***"&Err.Number&" - "&Err.Description&" ("&Err.Source&")")
End If
Err.Clear
End If
On Error GoTo 0
'check file downloaded
Dim save : save = True
If fso.FileExists(dest) Then
Dim jpg : Set jpg = fso.GetFile(dest)
If Not (jpg Is Nothing) Then
'check file size
If jpg.Size = 0 Then
Set jpg = Nothing
Else
'check html file
Dim txt : Set txt = fso.OpenTextFile(dest,1,False)
Dim str : str = UCase(txt.Read(5))
If (str = "<HTML") Or (str = "<!DOC") Then
Set jpg = Nothing
End If
Call txt.Close()
Set txt = Nothing
End If
End If
'remove empty file
If jpg Is Nothing Then
Call fso.DeleteFile(dest)
save = False
If Debug Then
Call out("File '"&dest&"' was empty or html")
End If
End If
Else
save = False
If Debug Then
Call out("File '"&dest&"' was missing")
End If
End If
'update tracks
If save Then
If Debug Then
Call out("Saving complete")
End If
Call postDownload(i)
Else
'update document
Dim doc : Set doc = SDB.Objects("BatchArtFinderDoc")
If Not (doc Is Nothing) Then
Dim div : Set div = doc.getElementById("dim"&i)
If Not (div Is Nothing) Then
div.innerHTML = "Error :("
End If
End If
End If
'update queue
queue.Item("i") = i+1
Set SDB.Objects("BAFinet") = Nothing
End If
End Sub
Sub postDownload(i)
SDB.ProcessMessages
Dim ini : Set ini = SDB.IniFile
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim data : Set data = SDB.Objects("BAFData"&i)
Dim dest : dest = data.Item("dest")
'calculate storage
Debug = ini.BoolValue("BatchArtFinder","Debug")
Storage = ini.IntValue("BatchArtFinder","Storage")-1
Images = ini.IntValue("BatchArtFinder","Images")
If (Storage > -1) And (Storage < 4) Then
If Debug Then
Call out("Tagging "&dest)
End If
Dim sto : sto = Storage
If Storage = 2 Or Storage = 3 Then
sto = 0
End If
'select tracks to update
Dim sql : sql = ""
If data.Item("type") = "track" Then
sql = "AND (Songs.ID="&data.Item("id")&")"
Else
sql = "AND (Songs.IDAlbum="&data.Item("id")&")"
End If
Dim list : Set list = SDB.NewSongList
Dim iter : Set iter = SDB.Database.QuerySongs(sql)
While Not (iter.EOF)
SDB.ProcessMessages
list.Add(iter.Item) 'convert SongIterator into SongList
iter.Next
WEnd
Set iter = Nothing
'add to tags
If Debug Then
Call out("Tagging "&list.Count&" track(s)")
End If
SDB.Database.BeginTransaction
Dim j : j = 0
For j = 0 To list.Count-1
SDB.ProcessMessages
Dim itm : Set itm = list.Item(j)
Call puttrackart(itm,dest,sto)
If Storage = 2 Then
Call puttrackart(itm,dest,1)
End If
SDB.ProcessMessages
itm.UpdateDB
Next
list.UpdateAll
For j = 0 To list.Count-1
SDB.ProcessMessages
list.Item(j).WriteTags
Next
SDB.Database.Commit
'delete if necessary
If Storage = 3 Then
If Not (dest = getnonejpg()) Then
If Debug Then
Call out("Deleting "&dest)
End If
fso.DeleteFile(dest)
End If
End If
'check cover paths
sql = "SELECT Count(*) FROM Covers WHERE CoverPath!='' AND CoverStorage=0"
If Debug Then
Call out("#"&sql)
End If
Dim tot : tot = SDB.Database.OpenSQL(sql).ValueByIndex(0)
If tot > 0 Then
sql = "UPDATE Covers SET CoverPath='' WHERE CoverStorage=0"
If Debug Then
Call out("#"&sql)
End If
SDB.Database.ExecSQL(sql)
End If
If Debug Then
Call out("Tagging complete")
End If
End If
'update document
SDB.ProcessMessages
Dim doc : Set doc = SDB.Objects("BatchArtFinderDoc")
If Not (doc Is Nothing) Then
Dim div : Set div = doc.getElementById("sav"&i)
If Not (div Is Nothing) Then
div.Checked = False
If Images = 1 Then
Set div = doc.getElementById("img"&i)
Else
Set div = doc.getElementById("img"&i&"-1")
End If
If Not (div Is Nothing) Then
Dim div2 : Set div2 = doc.getElementById("dim"&i)
If Not (div2 Is Nothing) Then
If Not (Left(div.innerHTML,1) = "<") Then
Dim str : str = ""
If ini.BoolValue("BatchArtFinder","SetSize") Then
str = " width="""&ini.IntValue("BatchArtFinder","SetW")&"px"" height="""&ini.IntValue("BatchArtFinder","SetH")&"px"""
End If
div.innerHTML = "<img src="""&dest&""""&str&" />"
End If
div2.innerHTML = "Saved!"
SDB.ProcessMessages
End If
End If
End If
End If
End Sub
Sub queueIsEmpty()
'reset todo list
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
Dim queue : Set queue = SDB.Objects("BAFQueue")
todo.Item("max") = queue.Item("old")
Set SDB.Objects("BAFQueue") = Nothing
Dim ini : Set ini = SDB.IniFile
'perform save action
Select Case ini.IntValue("BatchArtFinder","SaveMode")
Case 1 'next
Call NextClick(Nothing)
Case 2 'exit
Dim form : Set form = SDB.Objects("BatchArtFinderForm")
form.Common.Visible = False
Call FormClose(form)
Case 3 'trynext
Call TryClick()
Case Else 'nothing
Dim but : Set but = SDB.Objects("BAFClickedBtn")
but.Common.Enabled = True
Set SDB.Objects("BAFClickedBtn") = Nothing
End Select
End Sub
Sub puttrackart(itm,dest,sto)
Dim pics : Set pics = itm.AlbumArt
If pics Is Nothing Then Exit Sub
'add image to artwork
Dim img : Set img = pics.AddNew
img.PicturePath = dest
img.Description = "Added by Trixmoto's BatchArtFinder script"
img.ItemStorage = sto
img.ItemType = 3
pics.UpdateDB
End Sub
Function getnonejpg()
getnonejpg = Replace(Script.ScriptPath,"BatchArtFinder.vbs","none.jpg")
End Function
Function gettime(sec)
Dim min : min = 0
sec = Int(sec)
Do While sec > 59
sec = sec - 60
min = min + 1
Loop
If sec < 10 Then
gettime = min&":0"&sec
Else
gettime = min&":"&sec
End If
End Function
Function mapname(name)
Dim i : i = 0
Dim nameUTF8 : nameUTF8 = UTF8_Encode(name)
For i = 1 To Len(nameUTF8)
Dim c : c = Asc(Mid(nameUTF8,i))
If (c>32 And c<48) Or (c>57 And c<65) Or (c>90 And c<97) Or (c>122) Then
mapname = mapname&"%"&CStr(Hex(c))
Else
mapname = mapname&Chr(c)
End If
Next
mapname = Replace(mapname," ","+")
End Function
Sub ClearData()
Dim paths : Set paths = SDB.Objects("BatchArtFinderPaths")
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
Dim ini : Set ini = SDB.IniFile
Dim max : max = Int(todo.Item("max"))
If max > 0 Then
Dim i : i = 0
For i = 1 To max
Set SDB.Objects("BAFData"&i) = Nothing
Next
Set SDB.Objects("BatchArtFinderToDo") = Nothing
Set SDB.Objects("BatchArtFinderForm") = Nothing
Set SDB.Objects("BatchArtFinderDoc") = Nothing
Set SDB.Objects("BatchArtFinderShell") = Nothing
Set SDB.Objects("BatchArtFinderPanel") = Nothing
Set SDB.Objects("BAFQueue") = Nothing
Set SDB.Objects("BAFCurrentSong") = Nothing
Set SDB.Objects("BatchArtFinderPaths") = Nothing
Set SDB.Objects("BatchArtFinderDrp1") = Nothing
Set SDB.Objects("BatchArtFinderBtn1") = Nothing
Set SDB.Objects("BatchArtFinderBtn2") = Nothing
Set SDB.Objects("BatchArtFinderBtn3") = Nothing
End If
If Not (ini.IntValue("BatchArtFinder","Persist") = 1) Then
Set SDB.Objects("BatchArtFinderReplies") = Nothing
End If
Dim fso : Set fso = SDB.Tools.FileSystem
If fso.FileExists(paths.Item("htm")) Then
Call fso.DeleteFile(paths.Item("htm"))
End If
End Sub
Sub PauseClick(ClickedBtn)
'toggle button
Dim stat1,stat2,i,div
If ClickedBtn.Caption = "Pause" Then
ClickedBtn.Caption = "Resume"
stat1 = "[Queued]"
stat2 = "[Paused]"
Else
ClickedBtn.Caption = "Pause"
stat1 = "[Paused]"
stat2 = "[Queued]"
End If
'update images
Dim ini : Set ini = SDB.IniFile
Images = ini.IntValue("BatchArtFinder","Images")
Dim doc : Set doc = SDB.Objects("BatchArtFinderDoc")
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
Dim max : max = Int(todo.Item("max"))
For i = 1 To max
If Images = 1 Then
Set div = doc.getElementById("img"&i)
Else
Set div = doc.getElementById("img"&i&"-1")
End If
If Not (div Is Nothing) Then
If div.innerHTML = stat1 Then
div.innerHTML = stat2
End If
End If
Next
End Sub
Sub NextClick(ClickedBtn)
'calculate next start
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
Dim str : str = todo.Item(Int(todo.Item("max")))
Dim id : id = 0
If IsNumeric(str) Then
id = Int(str)
Else
id = 0 - Int(Mid(str,2))
End If
Dim ini : Set ini = SDB.IniFile
ini.StringValue("BatchArtFinder","StartID") = "*"&id
'close current form
Dim form : Set form = SDB.Objects("BatchArtFinderForm")
form.Common.Visible = False
Call FormClose(form)
'start next batch
Call DoBatchArtFinder(Nothing)
End Sub
Sub SourceClick(Drp)
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
If todo.Item("drp") = "" Then
todo.Item("drp") = Drp.ItemIndex
Call Script.RegisterEvent(SDB.CreateTimer(500),"OnTimer","DelaySelect")
End If
End Sub
Sub DelaySelect(Tmr)
Call Script.UnregisterEvents(Tmr)
'change source
Dim todo : Set todo = SDB.Objects("BatchArtFinderToDo")
Dim ini : Set ini = SDB.IniFile
ini.IntValue("BatchArtFinder","Source") = Int(todo.Item("drp"))
todo.Item("drp") = ""
Dim itm : Set itm = SDB.Objects("BAFCurrentSong")
'close current form
Dim form : Set form = SDB.Objects("BatchArtFinderForm")
form.Common.Visible = False
Call FormClose(form)
'start next batch
Call DoBatchArtFinder(itm)
End Sub
Sub InitSheet(Sheet)
Dim ini : Set ini = SDB.IniFile
NewOpts = ini.IntValue("BatchArtFinder","NewOpts")
Dim foo : foo = ""
If NewOpts < Version Then
foo = " *NEW*"
End If
Storage = ini.IntValue("BatchArtFinder","Storage")
ImageSize = ini.IntValue("BatchArtFinder","ImageSize")
FileMask = ini.StringValue("BatchArtFinder","FileMask")
Extra = ini.StringValue("BatchArtFinder","Extra")
Maximum = ini.IntValue("BatchArtFinder","Maximum")
Singles = ini.IntValue("BatchArtFinder","Singles")
Include = ini.IntValue("BatchArtFinder","Include")
PanelType = ini.IntValue("BatchArtFinder","PanelType")
Toolbar = ini.IntValue("BatchArtFinder","Toolbar")
Default = ini.IntValue("BatchArtFinder","Default")
CheckAll = ini.IntValue("BatchArtFinder","CheckAll")
Source = ini.IntValue("BatchArtFinder","Source")
MinW = ini.IntValue("BatchArtFinder","MinW")
MaxW = ini.IntValue("BatchArtFinder","MaxW")
MinH = ini.IntValue("BatchArtFinder","MinH")
MaxH = ini.IntValue("BatchArtFinder","MaxH")
ConfMode = ini.IntValue("BatchArtFinder","ConfMode")
SaveMode = ini.IntValue("BatchArtFinder","SaveMode")
AutoMode = ini.IntValue("BatchArtFinder","AutoMode")
SetSize = ini.IntValue("BatchArtFinder","SetSize")
SetW = ini.IntValue("BatchArtFinder","SetW")
SetH = ini.IntValue("BatchArtFinder","SetH")
FileTypes = ini.StringValue("BatchArtFinder","FileTypes")
Persist = ini.IntValue("BatchArtFinder","Persist")
MaxD = ini.IntValue("BatchArtFinder","MaxD")
Titles = ini.IntValue("BatchArtFinder","Titles")
FilterName = ini.StringValue("BatchArtFinder","FilterName")
Debug = ini.BoolValue("BatchArtFinder","Debug")
Exists = ini.BoolValue("BatchArtFinder","Exists")
Images = ini.IntValue("BatchArtFinder","Images")
Dim ui : Set ui = SDB.UI
Dim edt : Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 5, 10, 50, 20
edt.Caption = "Storage type:"
edt.Autosize = False
Set edt = ui.NewDropDown(Sheet)
edt.Common.SetRect 85, 7, 150, 20
edt.Common.ControlName = "BAFStorage"
edt.Style = 2
edt.AddItem("None")
edt.AddItem("Save in tag")
edt.AddItem("Save as link")
edt.AddItem("In tag and as link")
edt.AddItem("In tag only (delete image)")
edt.AddItem("Download file (don't tag)")
edt.ItemIndex = Storage
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 260, 10, 50, 20
edt.Caption = "Panel type:"
edt.Autosize = False
Set edt = ui.NewDropDown(Sheet)
edt.Common.SetRect 330, 7, 100, 20
edt.Common.ControlName = "BAFPanelType"
edt.Style = 2
edt.AddItem("Stay-on-top")
edt.AddItem("Normal")
edt.AddItem("Dockable")
edt.ItemIndex = PanelType - 1
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 5, 35, 50, 20
edt.Caption = "Source:"
edt.Autosize = False
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 260, 35, 50, 20
edt.Caption = "Image size:"
edt.Autosize = False
Set edt = ui.NewDropDown(Sheet)
edt.Common.SetRect 330, 32, 100, 20
edt.Common.ControlName = "BAFImageSize"
edt.Style = 2
edt.AddItem("Small")
edt.AddItem("Medium")
edt.AddItem("Large")
edt.AddItem("All")
edt.AddItem("Exact (min)")
edt.AddItem("Exact (max)")
edt.AddItem("Exact (disp)")
edt.ItemIndex = ImageSize
Set edt = ui.NewDropDown(Sheet)
edt.Common.SetRect 85, 32, 150, 20
edt.Common.ControlName = "BAFSource"
edt.Style = 2
edt.AddItem("images.google.com")
edt.AddItem("bing.com")
edt.AddItem("gomusicnow.com")
edt.AddItem("albumart.org")
edt.AddItem("ws.audioscrobbler.com")
'!
edt.ItemIndex = Source
edt.UseScript = Script.ScriptPath
edt.OnSelectFunc = "ShowImageSize"
Call ShowImageSize(edt)
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 5, 60, 50, 20
edt.Common.Hint = "Valid fields: <path> <artist> <album>"
edt.Caption = "File mask:"
edt.Autosize = False
Set edt = ui.NewEdit(Sheet)
edt.Common.SetRect 85, 57, 345, 20
edt.Common.ControlName = "BAFFileMask"
edt.Common.Hint = "Valid fields: <path><artist><album><id>"
edt.Text = FileMask
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 5, 85, 50, 20
edt.Common.Hint = "Part of SQL Where statement: 'AND ...'"
edt.Caption = "Extra:"
edt.Autosize = False
Set edt = ui.NewEdit(Sheet)
edt.Common.SetRect 85, 82, 345, 20
edt.Common.ControlName = "BAFExtra"
edt.Common.Hint = "Part of SQL Where statement: 'AND ...'"
edt.Text = Extra
Dim tst : Set tst = ui.NewButton(Sheet)
tst.Common.SetRect 432, 82, 21, 21
tst.Common.ControlName = "BAFTestQuery"
tst.Common.Hint = "Test query"
tst.Caption = "?"
tst.UseScript = Script.ScriptPath
tst.OnClickFunc = "TestExtra"
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 5, 110, 50, 20
edt.Caption = "Batch limit:"
edt.Autosize = False
Set edt = ui.NewSpinEdit(Sheet)
edt.Common.SetRect 85, 107, 100, 20
edt.Common.ControlName = "BAFMaximum"
edt.MinValue = 0
edt.MaxValue = 9999
edt.Value = Maximum
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 190, 110, 100, 20
edt.Caption = "(None=0)"
edt.Autosize = False
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 260, 110, 100, 20
edt.Common.Hint = "Comma separated list including: jpg,png,gif,bmp"
edt.Caption = "File types:"
edt.Autosize = False
Set edt = ui.NewEdit(Sheet)
edt.Common.SetRect 330, 107, 100, 20
edt.Common.ControlName = "BAFFileTypes"
edt.Common.Hint = "Comma separated list including: jpg,png,gif,bmp"
edt.Text = FileTypes
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 5, 135, 50, 20
edt.Common.Hint = "Minimum image width in pixels"
edt.Caption = "Min. width:"
edt.Autosize = False
Set edt = ui.NewSpinEdit(Sheet)
edt.Common.SetRect 85, 132, 100, 20
edt.Common.ControlName = "BAFMinW"
edt.Common.Hint = "Minimum image width in pixels"
edt.MinValue = 0
edt.MaxValue = 9999
edt.Value = MinW
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 260, 135, 50, 20
edt.Common.Hint = "Maximum image width in pixels"
edt.Caption = "Max. width:"
edt.Autosize = False
Set edt = ui.NewSpinEdit(Sheet)
edt.Common.SetRect 330, 132, 100, 20
edt.Common.ControlName = "BAFMaxW"
edt.Common.Hint = "Maximum image width in pixels"
edt.MinValue = 0
edt.MaxValue = 9999
edt.Value = MaxW
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 5, 160, 50, 20
edt.Common.Hint = "Minimum image height in pixels"
edt.Caption = "Min. height:"
edt.Autosize = False
Set edt = ui.NewSpinEdit(Sheet)
edt.Common.SetRect 85, 157, 100, 20
edt.Common.ControlName = "BAFMinH"
edt.Common.Hint = "Minimum image height in pixels"
edt.MinValue = 0
edt.MaxValue = 9999
edt.Value = MinH
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 260, 160, 50, 20
edt.Common.Hint = "Maximum image height in pixels"
edt.Caption = "Max. height:"
edt.Autosize = False
Set edt = ui.NewSpinEdit(Sheet)
edt.Common.SetRect 330, 157, 100, 20
edt.Common.ControlName = "BAFMaxH"
edt.Common.Hint = "Maximum image height in pixels"
edt.MinValue = 0
edt.MaxValue = 9999
edt.Value = MaxH
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 5, 185, 50, 20
edt.Common.Hint = "Maximum difference between image width and height in pixels"
edt.Caption = "Max. diff.:"
edt.Autosize = False
Set edt = ui.NewSpinEdit(Sheet)
edt.Common.SetRect 85, 182, 100, 20
edt.Common.ControlName = "BAFMaxD"
edt.Common.Hint = "Maximum difference between image width and height in pixels"
edt.MinValue = 0
edt.MaxValue = 9999
edt.Value = MaxD
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 260, 185, 50, 20
edt.Caption = "Selection:"
edt.Autosize = False
Set edt = ui.NewDropDown(Sheet)
edt.Common.SetRect 330, 182, 100, 20
edt.Common.ControlName = "BAFConfMode"
edt.Style = 2
edt.AddItem("Prompt")
edt.AddItem("Selected only")
edt.AddItem("All albums")
edt.ItemIndex = ConfMode
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 5, 210, 50, 20
edt.Caption = "Filter:"
edt.Autosize = False
Set edt = ui.NewDropDown(Sheet)
edt.Common.SetRect 85, 207, 150, 20
edt.Common.ControlName = "BAFFilterName"
edt.Style = 2
Call CreateFiltersArray()
Call FillDropDownFromArray(edt,Filters)
edt.ItemIndex = GetFiltersArrayID(FilterName)
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 260, 210, 50, 20
edt.Caption = "After saving:"
edt.Autosize = False
Set edt = ui.NewDropDown(Sheet)
edt.Common.SetRect 330, 207, 100, 20
edt.Common.ControlName = "BAFSaveMode"
edt.Style = 2
edt.AddItem("Do nothing")
edt.AddItem("Click next")
edt.AddItem("Close form")
edt.AddItem("Try next")
edt.ItemIndex = SaveMode
Set edt = ui.NewCheckbox(Sheet)
edt.Common.SetRect 5, 231, 250, 20
edt.Common.ControlName = "BAFSetSize"
edt.Caption = "Set image display size ---------------------------->"
If SetSize = 1 Then
edt.Checked = True
Else
edt.Checked = False
End If
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 260, 233, 50, 20
edt.Common.Hint = "Display width of image in pixels"
edt.Caption = "Disp. width:"
edt.Autosize = False
Set edt = ui.NewSpinEdit(Sheet)
edt.Common.SetRect 330, 230, 100, 20
edt.Common.ControlName = "BAFSetW"
edt.Common.Hint = "Display width of image in pixels"
edt.MinValue = 10
edt.MaxValue = 999
edt.Value = SetW
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 260, 257, 50, 20
edt.Common.Hint = "Display height of image in pixels"
edt.Caption = "Disp. height:"
edt.Autosize = False
Set edt = ui.NewSpinEdit(Sheet)
edt.Common.SetRect 330, 254, 100, 20
edt.Common.ControlName = "BAFSetH"
edt.Common.Hint = "Display height of image in pixels"
edt.MinValue = 10
edt.MaxValue = 999
edt.Value = SetH
Set edt = ui.NewCheckbox(Sheet)
edt.Common.SetRect 5, 251, 250, 20
edt.Common.ControlName = "BAFExists"
edt.Caption = "Check for image before searching"
edt.Checked = Exists
Set edt = ui.NewCheckbox(Sheet)
edt.Common.SetRect 5, 271, 250, 20
edt.Common.ControlName = "BAFPersist"
edt.Caption = "Remember prompt values"
If Persist = 1 Then
edt.Checked = True
edt.Common.Hint = GetHint()
Else
edt.Checked = False
Set SDB.Objects("BatchArtFinderReplies") = Nothing
End If
Set edt = ui.NewCheckbox(Sheet)
edt.Common.SetRect 5, 291, 250, 20
edt.Common.ControlName = "BAFToolbar"
edt.Caption = "Add run button to the standard toolbar"
If Toolbar = 1 Then
edt.Checked = True
Else
edt.Checked = False
End If
Set edt = ui.NewCheckbox(Sheet)
edt.Common.SetRect 5, 311, 250, 20
edt.Common.ControlName = "BAFSingles"
edt.Caption = "Include non-album tracks as albums"
If Singles = 1 Then
edt.Checked = True
Else
edt.Checked = False
End If
Set edt = ui.NewCheckbox(Sheet)
edt.Common.SetRect 5, 331, 250, 20
edt.Common.ControlName = "BAFInclude"
edt.Caption = "Include non-album track titles in url"
If Include = 1 Then
edt.Checked = True
Else
edt.Checked = False
End If
Set edt = ui.NewCheckbox(Sheet)
edt.Common.SetRect 5, 351, 400, 20
edt.Common.ControlName = "BAFAutoMode"
edt.Caption = "Automatically launch script when playing track without artwork"
If AutoMode = 1 Then
edt.Checked = True
Else
edt.Checked = False
End If
Set edt = ui.NewCheckbox(Sheet)
edt.Common.SetRect 5, 371, 350, 20
edt.Common.ControlName = "BAFTitles"
edt.Caption = "Always use first track title in url (instead of album name)"
If Titles = 1 Then
edt.Checked = True
Else
edt.Checked = False
End If
Set edt = ui.NewCheckbox(Sheet)
edt.Common.SetRect 5, 391, 300, 20
edt.Common.ControlName = "BAFCheckAll"
edt.Caption = "Start all images as ticked to be saved"
If CheckAll = 1 Then
edt.Checked = True
Else
edt.Checked = False
End If
Set edt = ui.NewCheckbox(Sheet)
edt.Common.SetRect 5, 411, 300, 20
edt.Common.ControlName = "BAFDefault"
edt.Caption = "Add default image when no results"
If Default = 1 Then
edt.Checked = True
Else
edt.Checked = False
End If
Set edt = ui.NewCheckbox(Sheet)
edt.Common.SetRect 320, 411, 250, 20
edt.Common.ControlName = "BAFDebug"
edt.Caption = "Create debug logfile"
edt.Checked = Debug
Set edt = ui.NewLabel(Sheet)
edt.Common.SetRect 260, 281, 50, 20
edt.Common.Hint = "Display multiple image results at once"
edt.Caption = "Results:"
edt.Autosize = False
Set edt = ui.NewSpinEdit(Sheet)
edt.Common.SetRect 330, 278, 100, 20
edt.Common.ControlName = "BAFImages"
edt.Common.Hint = "Display multiple image results at once"
edt.MinValue = 1
edt.MaxValue = 9
edt.Value = Images
End Sub
Sub TestExtra(but)
Dim str : str = "test passed."
Dim typ : typ = mtInformation
Dim edt : Set edt = but.Common.TopParent.Common.ChildControl("BAFExtra")
If edt Is Nothing Then
str = "test error."
typ = mtError
Else
On Error Resume Next
Dim temp : Set temp = SDB.Database.OpenSQL("SELECT Count(*) AS AlbumCount FROM Albums WHERE Albums.ID>0 "&edt.Text)
If Err.Number <> 0 Then
str = "test failed."
typ = mtError
Err.Clear
End If
On Error Goto 0
End If
Call SDB.MessageBox("Batch Art Finder - "&str,typ,Array(mbOk))
End Sub
Sub ShowImageSize(src)
Dim size : Set size = src.Common.TopParent.Common.ChildControl("BAFImageSize")
Select Case src.ItemIndex
Case 0
size.Common.Enabled = True
Case 1
size.Common.Enabled = False
Case 2
size.Common.Enabled = True
Case 3
size.Common.Enabled = True
Case 4
size.Common.Enabled = True
'!
End Select
End Sub
Sub SaveSheet(Sheet)
Dim ini : Set ini = SDB.IniFile
ini.IntValue("BatchArtFinder","NewOpts") = Version
ini.IntValue("BatchArtFinder","Storage") = Sheet.Common.ChildControl("BAFStorage").ItemIndex
ini.IntValue("BatchArtFinder","ImageSize") = Sheet.Common.ChildControl("BAFImageSize").ItemIndex
ini.StringValue("BatchArtFinder","FileMask") = Sheet.Common.ChildControl("BAFFileMask").Text
ini.StringValue("BatchArtFinder","Extra") = Sheet.Common.ChildControl("BAFExtra").Text
ini.IntValue("BatchArtFinder","Maximum") = Sheet.Common.ChildControl("BAFMaximum").Value
ini.IntValue("BatchArtFinder","PanelType") = Sheet.Common.ChildControl("BAFPanelType").ItemIndex + 1
ini.StringValue("BatchArtFinder","FileTypes") = Sheet.Common.ChildControl("BAFFileTypes").Text
Dim edt : Set edt = Sheet.Common.ChildControl("BAFFilterName")
ini.StringValue("BatchArtFinder","FilterName") = edt.ItemText(edt.ItemIndex)
If Sheet.Common.ChildControl("BAFSingles").Checked Then
ini.IntValue("BatchArtFinder","Singles") = 1
Else
ini.IntValue("BatchArtFinder","Singles") = 0
End If
If Sheet.Common.ChildControl("BAFInclude").Checked Then
ini.IntValue("BatchArtFinder","Include") = 1
Else
ini.IntValue("BatchArtFinder","Include") = 0
End If
Dim but : Set but = SDB.Objects("BAFToolbarButton")
If Sheet.Common.ChildControl("BAFToolbar").Checked Then
ini.IntValue("BatchArtFinder","Toolbar") = 1
but.Visible = True
Else
ini.IntValue("BatchArtFinder","Toolbar") = 0
but.Visible = False
End If
If Sheet.Common.ChildControl("BAFDefault").Checked Then
ini.IntValue("BatchArtFinder","Default") = 1
Else
ini.IntValue("BatchArtFinder","Default") = 0
End If
If Sheet.Common.ChildControl("BAFCheckAll").Checked Then
ini.IntValue("BatchArtFinder","CheckAll") = 1
Else
ini.IntValue("BatchArtFinder","CheckAll") = 0
End If
If Sheet.Common.ChildControl("BAFAutoMode").Checked Then
ini.IntValue("BatchArtFinder","AutoMode") = 1
Else
ini.IntValue("BatchArtFinder","AutoMode") = 0
End If
ini.IntValue("BatchArtFinder","Source") = Sheet.Common.ChildControl("BAFSource").ItemIndex
ini.IntValue("BatchArtFinder","MaxW") = Sheet.Common.ChildControl("BAFMaxW").Value
ini.IntValue("BatchArtFinder","MinW") = Sheet.Common.ChildControl("BAFMinW").Value
ini.IntValue("BatchArtFinder","MaxH") = Sheet.Common.ChildControl("BAFMaxH").Value
ini.IntValue("BatchArtFinder","MinH") = Sheet.Common.ChildControl("BAFMinH").Value
ini.IntValue("BatchArtFinder","ConfMode") = Sheet.Common.ChildControl("BAFConfMode").ItemIndex
ini.IntValue("BatchArtFinder","SaveMode") = Sheet.Common.ChildControl("BAFSaveMode").ItemIndex
ini.IntValue("BatchArtFinder","MaxD") = Sheet.Common.ChildControl("BAFMaxD").Value
If Sheet.Common.ChildControl("BAFTitles").Checked Then
ini.IntValue("BatchArtFinder","Titles") = 1
Else
ini.IntValue("BatchArtFinder","Titles") = 0
End If
If Sheet.Common.ChildControl("BAFSetSize").Checked Then
ini.IntValue("BatchArtFinder","SetSize") = 1
Else
ini.IntValue("BatchArtFinder","SetSize") = 0
End If
ini.IntValue("BatchArtFinder","SetW") = Sheet.Common.ChildControl("BAFSetW").Value
ini.IntValue("BatchArtFinder","SetH") = Sheet.Common.ChildControl("BAFSetH").Value
If Sheet.Common.ChildControl("BAFPersist").Checked Then
ini.IntValue("BatchArtFinder","Persist") = 1
Dim hnt : hnt = GetHint()
If Not (hnt = "") Then
hnt = Chr(13)&"-"&Chr(13)&hnt
End If
SDB.Objects("BAFToolbarButton").Caption = "Batch Art Finder"&hnt
Else
ini.IntValue("BatchArtFinder","Persist") = 0
ini.StringValue("BatchArtFinder","Replies1") = ""
ini.StringValue("BatchArtFinder","Replies2") = ""
ini.StringValue("BatchArtFinder","Replies3") = ""
SDB.Objects("BAFToolbarButton").Caption = "Batch Art Finder"
Set SDB.Objects("BatchArtFinderReplies") = CreateObject("Scripting.Dictionary")
End If
ini.BoolValue("BatchArtFinder","Debug") = Sheet.Common.ChildControl("BAFDebug").Checked
ini.BoolValue("BatchArtFinder","Exists") = Sheet.Common.ChildControl("BAFExists").Checked
ini.IntValue("BatchArtFinder","Images") = Sheet.Common.ChildControl("BAFImages").Value
End Sub
Function UTF8_Encode(ByVal UnicodeString)
Dim i,UnicodeCharCode,UTF8_temp
On Error Resume Next
For i = 1 To Len(UnicodeString)
UnicodeCharCode = AscW(Mid(UnicodeString,i))
If UnicodeCharCode < &H80 Then
UTF8_temp = Chr(UnicodeCharCode)
ElseIf UnicodeCharCode < &H800 Then
UTF8_temp = Chr(&H80 + (UnicodeCharCode And &H3F))
UnicodeCharCode = UnicodeCharCode \ &H40
UTF8_temp = Chr(&HC0 + (UnicodeCharCode And &H1F)) & UTF8_temp
Else
UTF8_temp = Chr(&H80 + (UnicodeCharCode And &H3F))
UnicodeCharCode = UnicodeCharCode \ &H40
UTF8_temp = Chr(&H80 + (UnicodeCharCode And &H3F)) & UTF8_temp
UnicodeCharCode = UnicodeCharCode \ &H40
UTF8_temp = Chr(&HE0 + (UnicodeCharCode And &HF)) & UTF8_temp
End If
UTF8_Encode = UTF8_Encode & UTF8_temp
If Not (Err.Number = 0) Then
Err.Clear
UTF8_Encode = UnicodeString
Exit For
End If
Next
On Error Goto 0
End Function
Function fixyear(str)
fixyear = str
Dim i : i = InStr(fixyear,".")
If i > 1 Then
fixyear = Left(fixyear,i-1)
End If
While Len(fixyear) < 4
fixyear = "0"&fixyear
WEnd
If fixyear = "0000" Then
fixyear = "????"
End If
End Function
Function InFileTypes(arr,src,ext)
InFileTypes = False
ext = ""
Dim i : i = InStrRev(src,".")
If i > 1 Then
Dim s : s = UCase(Mid(src,i))
ext = LCase(s)
For i = 0 To UBound(arr)
If s = "."&arr(i) Then
InFileTypes = True
Exit Function
End If
Next
End If
End Function
Function GetHint()
Dim tmp : tmp = ""
Dim rep : Set rep = SDB.Objects("BatchArtFinderReplies")
If Not (rep Is Nothing) Then
If rep.Exists("restrict") Then
tmp = "Restrict to selected albums: "
Select Case Int(rep.Item("restrict"))
Case mrYes
tmp = tmp&"Yes"
Case mrAll
tmp = tmp&"All"
Case mrCancel
tmp = tmp&"Cancel"
Case Else
tmp = tmp&"("&rep.Item("restrict")&")"
End Select
End If
If rep.Exists("beginning") Then
If tmp = "" Then
tmp = "Start from the beginning: "
Else
tmp = tmp&Chr(13)&"Start from the beginning: "
End If
Select Case Int(rep.Item("beginning"))
Case mrYes
tmp = tmp&"Yes"
Case mrNo
tmp = tmp&"No"
Case mrCancel
tmp = tmp&"Cancel"
Case Else
tmp = tmp&"("&rep.Item("beginning")&")"
End Select
End If
If rep.Exists("include") Then
If tmp = "" Then
tmp = "Process albums with artwork: "
Else
tmp = tmp&Chr(13)&"Process albums with artwork: "
End If
Select Case Int(rep.Item("include"))
Case mrYes
tmp = tmp&"Yes"
Case mrNo
tmp = tmp&"No"
Case Else
tmp = tmp&"("&rep.Item("include")&")"
End Select
End If
End If
GetHint = tmp
End Function
Sub out(txt)
Dim pat : Set pat = SDB.Objects("BatchArtFinderPaths")
If Not (pat Is Nothing) Then
Dim loc : loc = pat.Item("log")
If Not (loc = "") Then
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim logf : Set logf = fso.OpenTextFile(loc,8,True)
logf.WriteLine(Time&" "&SDB.ToAscii(txt))
logf.Close
End If
End If
End Sub
Sub Install()
Dim form : Set form = SDB.Objects("BatchArtFinderForm")
If Not (form Is Nothing) Then
form.Common.Visible = False
form.Common.ControlName = ""
Set SDB.Objects("BatchArtFinderForm") = Nothing
End If
Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
If Not (inif Is Nothing) Then
inif.StringValue("BatchArtFinder","Filename") = "Auto\BatchArtFinder.vbs"
inif.StringValue("BatchArtFinder","Procname") = "BatchArtFinder"
inif.StringValue("BatchArtFinder","Order") = "28"
inif.StringValue("BatchArtFinder","DisplayName") = "Batch Art Finder"
inif.StringValue("BatchArtFinder","Description") = "Find album art in batch"
inif.StringValue("BatchArtFinder","Language") = "VBScript"
inif.StringValue("BatchArtFinder","ScriptType") = "0"
SDB.RefreshScriptItems
End If
Call OnStartup()
End Sub
Function CorrectPath(str)
Dim fso : Set fso = SDB.Tools.FileSystem
Dim arr : arr = Split(str,"\")
Dim i : i = 0
CorrectPath = arr(i)
For i = 1 To UBound(arr)
CorrectPath = CorrectPath&"\"&fso.CorrectFilename(arr(i))
Next
End Function
Function GetFilterID(Name)
Dim nam : nam = "'"&Replace(Name,"'","''")&"'"
If SDB.Database.OpenSQL("SELECT COUNT(*) FROM Filters WHERE Name="&nam).ValueByIndex(0) = 0 Then
SDB.IniFile.StringValue("BatchArtFinder","FilterName") = "- No Filter -"
GetFilterID = -1
Else
GetFilterID = SDB.Database.OpenSQL("SELECT ID FROM Filters WHERE Name="&nam).ValueByIndex(0)
End If
End Function
Sub FillDropDownFromArray(DropDown,SourceArray)
Dim i : i = 0
For i = 0 To UBound(SourceArray)
Call DropDown.AddItem(SourceArray(i))
Next
End Sub
Sub CreateFiltersArray
Redim Filters(SDB.Database.OpenSQL("SELECT COUNT(*) FROM Filters").ValueByIndex(0)+1)
Filters(0) = "- No Filter -"
Filters(1) = "- Active Filter -"
Dim i : i = 2
Dim iter : Set iter = SDB.Database.OpenSQL("SELECT Name FROM Filters ORDER BY Pos")
Do While Not iter.EOF
Filters(i) = iter.StringByIndex(0)
i = i+1
iter.Next
Loop
Set iter = Nothing
End Sub
Function GetFiltersArrayID(Name)
Dim i : i = 0
For i = 0 To UBound(Filters)
If Filters(i) = Name Then
GetFiltersArrayID = i
Exit Function
End If
Next
GetFiltersArrayID = 0
End Function
Function GetFilterSQL(Name)
GetFilterSQL = ""
Dim sql : sql = ""
Select Case Name
Case "- No Filter -"
GetFilterSQL = ""
Case "- Active Filter -"
sql = SDB.Database.ActiveFilterQuery
If Not (sql = "") Then
GetFilterSQL = "AND "&sql
End If
Case Else
Dim id : id = GetFilterID(Name)
If id > -1 Then
sql = SDB.Database.GetFilterQuery(id)
If Not (sql = "") Then
GetFilterSQL = "AND "&sql
End If
End If
End Select
End Function
Function GeneratePath(fso,pFolderPath)
GeneratePath = False
If Not fso.FolderExists(pFolderPath) Then
If GeneratePath(fso,fso.GetParentFolderName(pFolderPath)) Then
GeneratePath = True
Call fso.CreateFolder(pFolderPath)
End If
Else
GeneratePath = True
End If
End Function
Function LoadLastFmXML(str)
Set LoadLastFmXML = CreateObject("Microsoft.XMLDOM")
Call LoadLastFmXML.LoadXML(str)
If LoadLastFmXML.parseError.errorCode <> 0 Then
Call LogMe("@ErrorCode="&LoadLastFmXML.parseError.errorCode)
Call LogMe("@ErrorMess="&LoadLastFmXML.parseError.reason)
Call LogMe("@ErrorLine="&LoadLastFmXML.parseError.line)
Call LogMe("@ErrorChar="&LoadLastFmXML.parseError.linepos)
Call LogMe("@ErrorText="&LoadLastFmXML.parseError.srcText)
Set LoadLastFmXML = Nothing
Else
If InStr(str,"<lfm status=""ok"">") = 0 Then
Dim lfm : Set lfm = Nothing
For Each lfm In LoadLastFmXML.getElementsByTagName("lfm")
Call LogMe("@ErrorStat="&lfm.attributes.getNamedItem("status").nodeValue)
Next
For Each lfm In LoadLastFmXML.getElementsByTagName("error")
Call LogMe("@ErrorCode="&lfm.attributes.getNamedItem("code").nodeValue)
Call LogMe("@ErrorMess="&lfm.Text)
Next
Set LoadLastFmXML = Nothing
End If
End If
End Function
Re: Batch Art Finder 4.1 - Updated 31/01/2011
Thanks for the code, I'll take a look and see if I can include it in the next release, along with attempting to fix Google.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Re: Batch Art Finder 4.1 - Updated 31/01/2011
just to make it easy, the only code I really changed was the following
This is found basically in 3 spots in different variations. The rest of the code remains unchanged.
Code: Select all
Case 1
doc.WriteLine " geturl = ""http://www.bing.com/images/search?q=""&artist&""+""&album&""&qs=AS&sk=AS1"""
Case 2
doc.WriteLine " geturl = ""http://www.gomusicnow.com/search.html?query=""&artist&""+""&album"
Re: Batch Art Finder 4.1 - Updated 31/01/2011
Good idea to post that "short version" - thx! I'll try it out.
Re: Batch Art Finder 4.1 - Updated 31/01/2011
I suggest renaming the original "BatchArtFinder.vbs" to "BatchArtFinder_Orig.vbs", selecting all the text and then pasteing the "long" version all together into the vbs script and saving it as "BatchArtFinder.vbs". There were other small changes, but the above small code is the main functioning code to get Bing to work (with minor tweeks in different areas). Again, I replaced Juno & RateYourMusic, but in the MM option menu these two still appear. Just know that Juno=GoMusicNow and RateYourMusic=Bing (But only in the MM options menu. The popup window shows the correct menu names).Guest wrote:Where we need to put this code? Thank you!
And again, this is just a quick fix I came up with and it worked for me. trixmoto really gets all the credit. And I can't guarentee that it will work for anyone else. I set the picture parameters in the MM options menu to look for pictures 295-305 X 295-305px and it filters all pictures to those sizes.
Good luck
-
- Posts: 5
- Joined: Wed May 25, 2011 2:33 pm
"the MSInet component could not be found"
I'm stuck on the MSInet problem.
I use Windows 7, 64-bit
I registered the MSInet component by executing the following commands logged in as admin (I also did that in a batch file with the same result):
cd C:\
cd windows\syswow64
regsvr32 "C:\Program Files (x86)\MediaMonkey\Scripts\Auto\msinet.ocx"
Windows reports back that the registration was successful.
Next, I log in as a user, run MediaMonkey, select one file, run batch art finder, click on 'save checked images' and
I still get the same error message: "Batch Art Finder - the MSInet component could not be found, please install before running this script."
Any ideas how to solve this?
Thanks.
I use Windows 7, 64-bit
I registered the MSInet component by executing the following commands logged in as admin (I also did that in a batch file with the same result):
cd C:\
cd windows\syswow64
regsvr32 "C:\Program Files (x86)\MediaMonkey\Scripts\Auto\msinet.ocx"
Windows reports back that the registration was successful.
Next, I log in as a user, run MediaMonkey, select one file, run batch art finder, click on 'save checked images' and
I still get the same error message: "Batch Art Finder - the MSInet component could not be found, please install before running this script."
Any ideas how to solve this?
Thanks.
Re: Batch Art Finder 4.1 - Updated 31/01/2011
I was having the same problem since my upgrade to win7-64 as you have described above. I registered msinet.ocx several times but continued to get he same error. I finally got it working, but I'm not exactly sure how. I'll describe what I did before getting it to work and you can give it a try.
I found that Win7-64 registers msinet differently than in XP, both in the registry and in the windows systems folder (it's in the syswow64 folder). I also found that batchartfinder looks for msinet in a specific location in the registry and if it is not found attempts to modify the registry to point to the file in the mediamonkey "auto" script folder. Windows 7 prevents mediamonkey from modifying the registry unless it is ran as administrator. So I ran MM as administrator by right clicking on it and choosing to run as administrator. I then ran batchartfinder and attempted to save an image, closed MM and re-ran it normaly. Things seemed to work after that.
As I stated earlier I don't know if this was what fixed my problem or not but it did start working after doing this. So give it a try and let us know if you also get positive results.
Good luck!
I found that Win7-64 registers msinet differently than in XP, both in the registry and in the windows systems folder (it's in the syswow64 folder). I also found that batchartfinder looks for msinet in a specific location in the registry and if it is not found attempts to modify the registry to point to the file in the mediamonkey "auto" script folder. Windows 7 prevents mediamonkey from modifying the registry unless it is ran as administrator. So I ran MM as administrator by right clicking on it and choosing to run as administrator. I then ran batchartfinder and attempted to save an image, closed MM and re-ran it normaly. Things seemed to work after that.
As I stated earlier I don't know if this was what fixed my problem or not but it did start working after doing this. So give it a try and let us know if you also get positive results.
Good luck!
-
- Posts: 5
- Joined: Wed May 25, 2011 2:33 pm
"MSI component could not be found"
Joemama,
Unfortunately, I don't find an improvement. I've run MediaMonkey while logged in as admin, and also in Windows XP compatibility mode, but I keep running into the same roadblock.
Unfortunately, I don't find an improvement. I've run MediaMonkey while logged in as admin, and also in Windows XP compatibility mode, but I keep running into the same roadblock.
-
- Posts: 5
- Joined: Wed May 25, 2011 2:33 pm
SOLVED: "MSI component could not be found"
I tried one more time and now I've the solution: you have to run MediaMonkey as administrator AND Windows XP compatibility mode.
While running that way you execute the Batch Art Finder script one time.
After this, it's working for me, even without using administrator and compatibility mode.
So, to put it all together in a summary:
1. This is about fixing the "MSI component could not be found" error for Windows 7 64-bit computers.
2. Log in as administrator, start the Windows command prompt program (it's in accessories) and type the following commands:
cd C:\
cd windows\syswow64
regsvr32 "C:\Program Files (x86)\MediaMonkey\Scripts\Auto\msinet.ocx"
Windows should now report back that the MSInet component was registered with success.
3. While still logged in as administrator, set MediaMonkey to Windows XP compatibility mode.
You do that by going to the MediaMonkey program icon in the "All Programs" list on your computer, right-click on that icon, go to "properties", then to "compatibility", click on "Run this program in Compatibility mode" for Windows XP (Service Pack 3)
4. You should now be able to use the BatchArtFinder script without getting the MSInet error. Do that for at least one song.
5. Now turn compatibility mode back off, log out as administrator, log in as a normal user and you should be able to proceed normally.
If the procedure above doesn't work, try rebooting the computer in between steps.
While running that way you execute the Batch Art Finder script one time.
After this, it's working for me, even without using administrator and compatibility mode.
So, to put it all together in a summary:
1. This is about fixing the "MSI component could not be found" error for Windows 7 64-bit computers.
2. Log in as administrator, start the Windows command prompt program (it's in accessories) and type the following commands:
cd C:\
cd windows\syswow64
regsvr32 "C:\Program Files (x86)\MediaMonkey\Scripts\Auto\msinet.ocx"
Windows should now report back that the MSInet component was registered with success.
3. While still logged in as administrator, set MediaMonkey to Windows XP compatibility mode.
You do that by going to the MediaMonkey program icon in the "All Programs" list on your computer, right-click on that icon, go to "properties", then to "compatibility", click on "Run this program in Compatibility mode" for Windows XP (Service Pack 3)
4. You should now be able to use the BatchArtFinder script without getting the MSInet error. Do that for at least one song.
5. Now turn compatibility mode back off, log out as administrator, log in as a normal user and you should be able to proceed normally.
If the procedure above doesn't work, try rebooting the computer in between steps.