by palmernet » Wed Apr 29, 2009 6:12 am
Bex wrote:Hi palmernet,
If you post the code it's easier to understand the problem and help!
The line which throws an error is
Call list.AddTrack(MyTracks.Item)
The full script is:
Code: Select all
'
' MediaMonkey Script
'
' NAME: TextToPlaylist 1.0
'
'Derived from http://www.mediamonkey.com/forum/viewtopic.php?f=2&t=6879&start=0
'
' [TextToPlaylist]
' FileName=TextToPlaylist.vbs
' ProcName=TextToPlaylist
' Order=18
' DisplayName=Combine Albums
' Description=Change album naming conventions
' Language=VBScript
' ScriptType=0
'
Sub TextToPlaylist
'create logfile
Dim wsh : Set wsh = CreateObject("WScript.Shell")
Dim loc : loc = wsh.ExpandEnvironmentStrings("%TEMP%")&"\TextToPlaylist.log"
Set logf = SDB.Tools.FileSystem.CreateTextFile(loc,True)
Call logf.WriteLine("")
res = InputBox ("Enter filename of TxT to import:","Import TXT playlist")
Set progress = SDB.Progress
progress.Text = "Opening: "&res
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(res) Then
Set file = filesys.OpenTextFile(res, 1, false)
name = filesys.getFileName(res)
name = mid(name,1,len(name)-4)
progress.Text = "Creating playlist: "&name
Set list = SDB.PlaylistByTitle("").CreateChildPlaylist(name)
do while not file.AtEndOfStream
line = file.ReadLine
line = line & vbTab & ""
progress.Text = "Finding: "&line
line_arr = split(line, vbTab)
'Dim sql : sql = ""
'sql = "SELECT Songs.Id FROM Songs WHERE (Songs.artist='"& Trim(Replace(line_arr(1),"'","''")) &"' AND Songs.songtitle='"& Trim(Replace(line_arr(0),"'","''")) &"')"
'Dim qit : Set qit = SDB.Database.OpenSQL(sql)
sql_where = "AND (Songs.artist='"& Trim(Replace(line_arr(1),"'","''")) &"' AND Songs.songtitle='"& Trim(Replace(line_arr(0),"'","''")) &"')"
Set MyTracks = SDB.Database.QuerySongs(sql_where)
l_added = 0
If Not MyTracks.EOF Then
Call list.AddTrack(MyTracks.Item)
'Call list.AddTrackById(qit.StringByIndex(0))
l_added = l_added + 1
progress.text = "Adding: "&line_arr(0)&" ("&l_added&")"
Else
'sql = "SELECT Songs.Id FROM Songs WHERE (Songs.artist like '%' || '"& Trim(Replace(line_arr(1),"'","''")) &"' || '%' AND Songs.songtitle like '%' || '"& Trim(Replace(line_arr(0),"'","''")) &"' || '%')"
'Set qit = SDB.Database.OpenSQL(sql)
sql_where = "AND (Songs.artist like '%' || '"& Trim(Replace(line_arr(1),"'","''")) &"' || '%' AND Songs.songtitle like '%' || '"& Trim(Replace(line_arr(0),"'","''")) &"' || '%')"
Set MyTracks = SDB.Database.QuerySongs(sql_where)
If Not MyTracks.EOF Then
Call list.AddTrack(MyTracks.Item)
'Call list.AddTrackById(qit.StringByIndex(0))
l_added = l_added + 1
progress.text = "Adding: "&line_arr(0)&" ("&l_added&")"
'MyTracks.next
End If
End If
if l_added = 0 then
progress.text = "notfound_SQL: "&sql_where
no_entry = no_entry + " " + "'"&line_arr(0)&", "&line_arr(1)&"'"
logf.WriteLine(line_arr(0)& vbTab &line_arr(1) & vbTab & sql_where)
end if
loop
res = SDB.MessageBox("Entries not found: "&no_entry, mtError, array(mbOK))
progress.Text = "Closing: "&res
file.close
Else
res = SDB.MessageBox("This playlist could not be found", mtError, Array(mbOk))
End If
Set progress = nothing
logf.Close
filesys.Close
End Sub
Sub AddTrack(itm,rel,out)
Dim InAlbum : InAlbum = False
If InStr(itm.Path,rel) = 1 Then
InAlbum = True
End If
If Not(AlbumOnly) Or InAlbum Then
If Debug Then Call logf.WriteLine("---"&itm.Path)
Call out.WriteLine(SDB.toASCII("#EXTINF:"&Left(CStr(itm.SongLength),3)&","&itm.ArtistName&" - "&itm.Title))
If Err.Number <> 0 Then
Call out.WriteLine("#EXTINF:"&itm.ID&" ["&Err.Number&"]")
Err.Clear
End If
If FullPath Then
Call out.WriteLine(itm.Path)
Else
If InAlbum Then
Call out.WriteLine(Replace(itm.Path,rel,""))
Else
Call out.WriteLine(itm.Path)
End If
End If
If Err.Number <> 0 Then
Call out.WriteLine("#"&SDB.toASCII(itm.Path)&" ["&Err.Number&"]")
Err.Clear
End If
Else
If Debug Then Call logf.WriteLine("---(Ignoring track: "&itm.Path&")")
End If
End Sub
[quote="Bex"]Hi palmernet,
If you post the code it's easier to understand the problem and help![/quote]
The line which throws an error is
Call list.AddTrack(MyTracks.Item)
The full script is:
[code]'
' MediaMonkey Script
'
' NAME: TextToPlaylist 1.0
'
'Derived from http://www.mediamonkey.com/forum/viewtopic.php?f=2&t=6879&start=0
'
' [TextToPlaylist]
' FileName=TextToPlaylist.vbs
' ProcName=TextToPlaylist
' Order=18
' DisplayName=Combine Albums
' Description=Change album naming conventions
' Language=VBScript
' ScriptType=0
'
Sub TextToPlaylist
'create logfile
Dim wsh : Set wsh = CreateObject("WScript.Shell")
Dim loc : loc = wsh.ExpandEnvironmentStrings("%TEMP%")&"\TextToPlaylist.log"
Set logf = SDB.Tools.FileSystem.CreateTextFile(loc,True)
Call logf.WriteLine("")
res = InputBox ("Enter filename of TxT to import:","Import TXT playlist")
Set progress = SDB.Progress
progress.Text = "Opening: "&res
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(res) Then
Set file = filesys.OpenTextFile(res, 1, false)
name = filesys.getFileName(res)
name = mid(name,1,len(name)-4)
progress.Text = "Creating playlist: "&name
Set list = SDB.PlaylistByTitle("").CreateChildPlaylist(name)
do while not file.AtEndOfStream
line = file.ReadLine
line = line & vbTab & ""
progress.Text = "Finding: "&line
line_arr = split(line, vbTab)
'Dim sql : sql = ""
'sql = "SELECT Songs.Id FROM Songs WHERE (Songs.artist='"& Trim(Replace(line_arr(1),"'","''")) &"' AND Songs.songtitle='"& Trim(Replace(line_arr(0),"'","''")) &"')"
'Dim qit : Set qit = SDB.Database.OpenSQL(sql)
sql_where = "AND (Songs.artist='"& Trim(Replace(line_arr(1),"'","''")) &"' AND Songs.songtitle='"& Trim(Replace(line_arr(0),"'","''")) &"')"
Set MyTracks = SDB.Database.QuerySongs(sql_where)
l_added = 0
If Not MyTracks.EOF Then
Call list.AddTrack(MyTracks.Item)
'Call list.AddTrackById(qit.StringByIndex(0))
l_added = l_added + 1
progress.text = "Adding: "&line_arr(0)&" ("&l_added&")"
Else
'sql = "SELECT Songs.Id FROM Songs WHERE (Songs.artist like '%' || '"& Trim(Replace(line_arr(1),"'","''")) &"' || '%' AND Songs.songtitle like '%' || '"& Trim(Replace(line_arr(0),"'","''")) &"' || '%')"
'Set qit = SDB.Database.OpenSQL(sql)
sql_where = "AND (Songs.artist like '%' || '"& Trim(Replace(line_arr(1),"'","''")) &"' || '%' AND Songs.songtitle like '%' || '"& Trim(Replace(line_arr(0),"'","''")) &"' || '%')"
Set MyTracks = SDB.Database.QuerySongs(sql_where)
If Not MyTracks.EOF Then
Call list.AddTrack(MyTracks.Item)
'Call list.AddTrackById(qit.StringByIndex(0))
l_added = l_added + 1
progress.text = "Adding: "&line_arr(0)&" ("&l_added&")"
'MyTracks.next
End If
End If
if l_added = 0 then
progress.text = "notfound_SQL: "&sql_where
no_entry = no_entry + " " + "'"&line_arr(0)&", "&line_arr(1)&"'"
logf.WriteLine(line_arr(0)& vbTab &line_arr(1) & vbTab & sql_where)
end if
loop
res = SDB.MessageBox("Entries not found: "&no_entry, mtError, array(mbOK))
progress.Text = "Closing: "&res
file.close
Else
res = SDB.MessageBox("This playlist could not be found", mtError, Array(mbOk))
End If
Set progress = nothing
logf.Close
filesys.Close
End Sub
Sub AddTrack(itm,rel,out)
Dim InAlbum : InAlbum = False
If InStr(itm.Path,rel) = 1 Then
InAlbum = True
End If
If Not(AlbumOnly) Or InAlbum Then
If Debug Then Call logf.WriteLine("---"&itm.Path)
Call out.WriteLine(SDB.toASCII("#EXTINF:"&Left(CStr(itm.SongLength),3)&","&itm.ArtistName&" - "&itm.Title))
If Err.Number <> 0 Then
Call out.WriteLine("#EXTINF:"&itm.ID&" ["&Err.Number&"]")
Err.Clear
End If
If FullPath Then
Call out.WriteLine(itm.Path)
Else
If InAlbum Then
Call out.WriteLine(Replace(itm.Path,rel,""))
Else
Call out.WriteLine(itm.Path)
End If
End If
If Err.Number <> 0 Then
Call out.WriteLine("#"&SDB.toASCII(itm.Path)&" ["&Err.Number&"]")
Err.Clear
End If
Else
If Debug Then Call logf.WriteLine("---(Ignoring track: "&itm.Path&")")
End If
End Sub[/code]