Backup Playlists 2.2 - Updated 18/10/10

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Backup Playlists 2.2 - Updated 18/10/10

Post by trixmoto »

This script was suggested/discussed here: http://www.mediamonkey.com/forum/viewtopic.php?t=6930

It allows you to export your autoplaylist criteria (not the songs themselves, nor manual playlists) into a separate database. You can then use this script to import those criteria into your MM database. This can be used for backing up autoplaylists but cannot be used for transferring them from one database to another as the IDs would not match.

As always, installers for this script can be downloaded from my website!

Code: Select all

'
' MediaMonkey Script
'
' NAME: BackupPlaylists 2.2
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 18/10/2010
'
' Thank you to Steegy for his help.
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'
' [BackupPlaylists]
' FileName=BackupPlaylists.vbs
' ProcName=BackupPlaylists
' Order=15
' DisplayName=Backup Playlists
' Description=Backup playlists
' Language=VBScript
' ScriptType=0 
'
' FIXES: Removed old MM2 code 
'        Fixed problems caused by apostrophes
'

Option Explicit

Sub BackupPlaylists
  Dim Form : Set Form = SDB.UI.NewForm
  Form.Common.SetRect 100, 100, 235, 110 
  Form.BorderStyle  = 3
  Form.FormPosition = 4
  Form.Caption = "Backup Playlists"

  Dim Btn1 : Set Btn1 = SDB.UI.NewButton(Form)
  Btn1.Caption = "Export to backup"
  Btn1.Common.Top = 10
  Btn1.Common.Left = 10
  Btn1.Common.Width = 200
  Btn1.UseScript = Script.ScriptPath
  Btn1.ModalResult = 1

  Dim Btn2 : Set Btn2 = SDB.UI.NewButton(Form)
  Btn2.Caption = "Import from backup"
  Btn2.Common.Top = 40
  Btn2.Common.Left = 10
  Btn2.Common.Width = 200
  Btn2.UseScript = Script.ScriptPath
  Btn2.ModalResult = 3
  
  Dim result : result = Form.showModal 
  If result = 1 Then
    Call Export()
  ElseIf result = 3 Then
    Call Import()
  End If
End Sub 

Function getdbpath()
  getdbpath = SDB.IniFile.StringValue("Scripts","BackupPlaylistsDir")
  getdbpath = SDB.SelectFolder(getdbpath, "Select your BackupPlaylists database location:")
  If getdbpath = "" Then
    Exit Function
  End If
  If Not (Right(getdbpath,1) = "\") Then
    SDB.IniFile.StringValue("Scripts","BackupPlaylistsDir") = getdbpath&"\"
    getdbpath = getdbpath&"\BackupPlaylists.DB"
  Else
    SDB.IniFile.StringValue("Scripts","BackupPlaylistsDir") = getdbpath
    getdbpath = getdbpath&"BackupPlaylists.DB"
  End If
End Function

Sub Export()
  If InstallLiteX() Then
    Dim output : output = "Starting export..."&Chr(13)
    Dim mmpath : mmpath = SDB.Database.Path
    output = output&"MMPath="&mmpath&Chr(13)
    If Not (mmpath = "") Then
      Dim dbpath : dbpath = getdbpath()
      output = output&"DBPath="&dbpath&Chr(13)
      If Not (dbpath = "") Then
        Dim db : Set db = CreateObject("LiteX.LiteConnection")
        If Not (db Is Nothing) Then
          db.Open(mmpath)
          Dim bp : Set bp = CreateObject("LiteX.LiteConnection")
          If Not (bp Is Nothing) Then
            bp.Open(dbpath)
            output = output&"Backup database created"&Chr(13)
            bp.Execute("DROP TABLE IF EXISTS Playlists")
            bp.Execute("CREATE TABLE Playlists (IDPlaylist integer, PlaylistName text, ParentPlaylist integer, Comment text, IsAutoPlaylist integer, QueryData text, srcMedia integer, srcPath text, Persistent integer, Synchronize integer, CONSTRAINT Index1 PRIMARY KEY (IDPlaylist))")
            bp.Execute("BEGIN TRANSACTION")
            output = output&"Playlists table created"&Chr(13)            
            Dim qy : Set qy = db.Prepare("SELECT * FROM Playlists WHERE (IsAutoPlaylist = 1 OR IDPlaylist IN (SELECT ParentPlaylist FROM Playlists))")
            If Not (qy Is Nothing) Then
              Dim ns : ns = "IDPlaylist, PlaylistName, ParentPlaylist, Comment, IsAutoPlaylist, QueryData, srcMedia, srcPath, Persistent, Synchronize"
              While (Not qy.Step())
                Dim ri : Set ri = qy.Rows.Item
                Dim vs : vs = FixInt(ri(0))&",'"&FixStr(ri(1))&"',"&FixInt(ri(2))&",'"&FixStr(ri(3))&"',"&FixInt(ri(4))&",'"&FixStr(ri(5))&"',"&FixInt(ri(6))&",'"&FixStr(ri(7))&"',"&FixInt(ri(8))&","&FixInt(ri(9))
                bp.Execute("INSERT INTO Playlists ("&ns&") Values ("&vs&")")
                output = output&"Playlist exported: "&ri(1)&Chr(13)
              WEnd
              qy.Close()
            End If
            bp.Execute("COMMIT TRANSACTION")
            bp.Close()
            Call SDB.MessageBox(output&"Export complete.", mtInformation, Array(mbOk))
          Else
            Call SDB.MessageBox(output&"Error: 'LiteX' could not be created.",mtError,Array(mbOk))  
          End If
          db.Close()
        Else
          Call SDB.MessageBox(output&"Error: 'LiteX' could not be created.",mtError,Array(mbOk))  
        End If
      Else
        Call SDB.MessageBox(output&"Error: 'BackupPlaylists.DB' was not selected.",mtError,Array(mbOk))  
      End If
    Else
      Call SDB.MessageBox(output&"Error: 'MM.DB' could not be found.",mtError,Array(mbOk))  
    End If
  Else
    Call SDB.MessageBox(output&"Error: 'LiteX' could not be installed.",mtError,Array(mbOk))  
  End If
End Sub

Sub Import()
  If InstallLiteX() Then
    Dim output : output = "Starting import..."&Chr(13)
    Dim dbpath : dbpath = getdbpath()
    output = output&"DBPath="&dbpath&Chr(13)
    If Not (dbpath = "") Then
      Dim mmpath : mmpath = SDB.Database.Path
      output = output&"MMPath="&mmpath&Chr(13)
      If Not (mmpath = "") Then
        Dim bp : Set bp = CreateObject("LiteX.LiteConnection")
        If Not (bp Is Nothing) Then
          bp.Open(dbpath)
          Dim db : Set db = SDB.Database
          If Not (db Is Nothing) Then
            Dim id : id = FixInt(db.OpenSQL("SELECT Max(IDPlaylist) FROM Playlists").ValueByIndex(0))
            Dim ns : ns = "IDPlaylist, PlaylistName, ParentPlaylist, Comment, IsAutoPlaylist, QueryData, srcMedia, srcPath, Persistent, Synchronize"
            Dim qy : Set qy = bp.Prepare("SELECT * FROM Playlists WHERE (IsAutoPlaylist = 1 OR IDPlaylist IN (SELECT ParentPlaylist FROM Playlists))")
            If Not (qy Is Nothing) Then      
              While (Not qy.Step())
                Dim ri : Set ri = qy.Rows.Item
                Dim ps : ps = FixInt(db.OpenSQL("SELECT Count(*) FROM Playlists WHERE PlaylistName='"&FixStr(ri(1))&"'").ValueByIndex(0))
                If ps = 0 Then
                  id = id+1
                  Dim vs : vs = id&",'"&FixStr(ri(1))&"',"&FixInt(ri(2))&",'"&FixStr(ri(3))&"',"&FixInt(ri(4))&",'"&FixStr(ri(5))&"',"&FixInt(ri(6))&",'"&FixStr(ri(7))&"',"&FixInt(ri(8))&","&FixInt(ri(9))
                  db.ExecSQL("INSERT INTO Playlists ("&ns&") Values ("&vs&")")
                  output = output&"Playlist imported: "&ri(1)&Chr(13)
                Else
                  output = output&"Playlist already exists: "&ri(1)&Chr(13)
                End If
              WEnd
              qy.Close()
            End If  
            Call SDB.MessageBox(output&"Import complete.", mtInformation, Array(mbOk))
          Else
            Call SDB.MessageBox(output&"Error: 'LiteX' could not be created.",mtError,Array(mbOk))            
          End If
        Else
          Call SDB.MessageBox(output&"Error: 'LiteX' could not be created.",mtError,Array(mbOk))  
        End If
      Else
        Call SDB.MessageBox(output&"Error: 'MM.DB' could not be found.",mtError,Array(mbOk))  
      End If
    Else
      Call SDB.MessageBox(output&"Error: 'BackupPlaylists.DB' was not selected.",mtError,Array(mbOk))  
    End If
  Else
    Call SDB.MessageBox(output&"Error: 'LiteX' could not be installed.",mtError,Array(mbOk))  
  End If
End Sub

Function InstallLiteX()
  InstallLiteX = False
  On Error Resume Next
  Dim litex : Set litex = CreateObject("LiteX.LiteConnection")
  If Not (Err.Number = 0) Then
    Err.Clear
    Dim dll : dll = SDB.ApplicationPath&"Scripts\sqlite3u.dll"
    Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
    If Not fso.FileExists(dll) Then 
      Exit Function
    End If
    Dim wsh : Set wsh = CreateObject("WScript.Shell")
    Dim res : res = wsh.Run("regsvr32 "&Chr(34)&dll&Chr(34)&" /s",1,1)
  End If  
  On Error GoTo 0    
  InstallLiteX = True
End Function

Function FixInt(num)
  If IsNull(num) Then
    FixInt = "0"
  Else
    If num = "" Then
      FixInt = "0"
    Else
      FixInt = CStr(num)
    End If
  End If
End Function

Function FixStr(str)
  If IsNull(str) Then
    FixStr = ""
  Else
    FixStr = Replace(str,"'","''")
  End If
End Function

Sub Install()
  Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
  Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  If Not (inif Is Nothing) Then
    inif.StringValue("BackupPlaylists","Filename") = "BackupPlaylists.vbs"
    inif.StringValue("BackupPlaylists","Procname") = "BackupPlaylists"
    inif.StringValue("BackupPlaylists","Order") = "15"
    inif.StringValue("BackupPlaylists","DisplayName") = "Backup Playlists"
    inif.StringValue("BackupPlaylists","Description") = "Backup Playlists"
    inif.StringValue("BackupPlaylists","Language") = "VBScript"
    inif.StringValue("BackupPlaylists","ScriptType") = "0"
    SDB.RefreshScriptItems
  End If
End Sub
Last edited by trixmoto on Fri Apr 27, 2007 3:42 am, edited 2 times in total.
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.
gab
Posts: 328
Joined: Tue Oct 11, 2005 1:20 pm

Post by gab »

Trix:

I'm getting an error running this script: "Error # 2147217900 - Microsoft JET database engine...". Any ideas what I'm doing wrong. Also, any way to integrate the playlist backup with your other Backup script to make it a one step process?

Thanks,
George
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

You probably do not have the Jet engine installed correctly. There are Windows version specific instructions here: http://www.zuggsoft.com/data/
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.
martialartsguy
Posts: 312
Joined: Mon Apr 03, 2006 9:11 am
Location: Denver, CO

Jet Incompatibility

Post by martialartsguy »

I was receiving the same error when attempting to output the Playlists.

After attempting to download the Jet engine as suggested from your link, I receive the error:

Setup has detected that the Service Pack version of this system is
newer than the update you are applying.

Any suggestions or should I just wait for MM 3.0?

Love this script btw. Makes keeping track of my playlists much easier.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

If you have a different version installed you might need to update this line...

Code: Select all

getconnection.Provider = "Microsoft.Jet.OLEDB.4.0"
This script will not work in MM3 as it uses an ADODB connection which I don't think will be compatible with the new SQLite database.
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.
martialartsguy
Posts: 312
Joined: Mon Apr 03, 2006 9:11 am
Location: Denver, CO

Post by martialartsguy »

Thank - I'll give it a try when I get home.

Bummer it won't work w/MM3 but I see you have a rewrite in red on the scripts page. I look forward to it.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

I don't know if it will be possible as I haven't learnt SQList yet, but hopefully I will rewrite this script for MM3.
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.
martialartsguy
Posts: 312
Joined: Mon Apr 03, 2006 9:11 am
Location: Denver, CO

Post by martialartsguy »

Trix-

That's actually the line in my current version. I tried to do a search to see if I could find out the version I had of Jet, but no luck. Any other ideas?
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Backup Playlists 2.0 [MM2+3]

Post by trixmoto »

New version (2.0) is now available to download from my website. I have made it compatible with MM3, but nothing has changed in MM2 so no need to upgrade this script if you haven't upgraded your monkey! :)

In MM3 a component called "LiteX" needs to be installed. The script will attempt to do this automatically but if you have UAC enabled on Vista then this will probably fail. In this case you can manually install the component by right-clicking on a "cmd.exe" shortcut and select "Run as administrator". You should get a black window in which you can enter...

regsvr32 "C:\Program Files\MediaMonkey\Scripts\sqlite3u.dll"

...although you might need to update the path! After doing this the script should function fully. I have tested with some unicode characters but I don't have many in my library so please let me know if you have any problems.
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.
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: Backup Playlists 2.0 [MM2+3]

Post by nynaevelan »

trixmoto wrote:
In MM3 a component called "LiteX" needs to be installed.
Is this LiteX included with the sript, if not where would one download it from??

Nyn

EDIT: Ok, I found the program from a link in one of your other posts but since there is not exe file, how do I install it? :-?
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Backup Playlists 2.0 [MM2+3]

Post by trixmoto »

Yes, the file is included in the installation package. It should be here: "C:\Program Files\MediaMonkey\Scripts\sqlite3u.dll"
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.
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: Backup Playlists 2.0 [MM2+3]

Post by nynaevelan »

That's what I thought but when I follow your instructions I get this error, I tried it with and without the quotation marks:

Image

Nyn

Ok, I got it to work, you had a typo in there "regsvr32" :oops:
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: Backup Playlists 2.0 [MM2+3]

Post by nynaevelan »

Ok, now that I got it to work I get this error when running an export:

Image

Nyn

It appears the error is in two of my playlists since they had a name with the apostrophe in it, once I removed it the export worked. Now I have another problem, the backup is not exporting all of my playlists. I have my playlists nested into groups with a total of 153 playlists. In the Playlists table of the main db I have 168 rows, in the Playlists table of the Backup Playlists db I have 27 rows. After comparing the results to my actual playlists, the script is exporting all the autoplaylists but it is only exporting the Parent playlists. It is not exporting the nested static playlists. Any suggestions?? BTW, sorry for making a PITA of myself, AGAIN. :oops:

Nyn
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
MusicBringer
Posts: 622
Joined: Wed Oct 25, 2006 12:53 pm

Re: Backup Playlists 2.0 [MM2+3]

Post by MusicBringer »

nynaevelan wrote:Ok, now that I got it to work I get this error when running an export:

Image
Sorry to say that I too, am getting the sort of error message.
It happens on both my PC and my laptop.
MediaMonkey user since 2006
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: Backup Playlists 2.0 [MM2+3]

Post by nynaevelan »

MusicBringer:

Check the name of your playlists, I had a couple of playlists that started with a ', once I changed it the script ran successfully. I only ran into this with the playlists which started with the apostrophe, I don't know if it will create a problem for those with the apostrophe in the middle because none of my nested playlists are being exported. :cry:

Nyn
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
Post Reply