[MM2+3] Change Drive-ID after moving Files to a new Drive

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

Moderators: Peke, Gurus

onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

[MM2+3] Change Drive-ID after moving Files to a new Drive

Post by onkel_enno »

For locating Files, MediaMonkey uses the SerialNumber of each device instead of using the drive letter.
There are several reasons for that. You can read about it here.

Some people (like me) bought a new, larger harddrive and moved their complete Music Archive to this new drive.
MediaMonkey now doesn't find the Files, having the same drive letter or not.
For that you could try Files -> Find moved/missed Tracks, but in that case it doesn't work always properly.

This Script lets you choose where you have moved the Files to and corrects the Serial-Number stored in the Library.

Attention: Make a Backup of your Library (My Documents\...\MediaMonkey\MediaMonkey.mdb) before.

Code: Select all

'1. Shutdown MediaMonkey

'2. Create the follwing Lines (without 'REM ' )  in MediaMonkey\Scripts\Scripts.ini:
REM [HDDSerial]
REM FileName=MM_HDDSerial.vbs
REM ProcName=Change_HDD_Serial
REM Order=99
REM DisplayName=Move Device Content
REM Description=Corrects broken links after exchanged harddrive
REM Language=VBScript
REM ScriptType=0

'3.  Restart MediaMonkey
'4. Make sure every Device (harddrive) has a Label (Library -> Location)
'5. Select Tools -> Scripts -> Move Device Content
'6. Select on the left side the old device (harddrive)
'7. Select on the right side the new drive
'8. OK
'9. Restart MediaMonkey

'Now MediaMonkey should find all the files which where located on the old drive and are now on the new one.

Option Explicit

Sub Change_HDD_Serial()
  Const PanelWidth = 200
  Const PanelHeight = 100
  Const objSpace = 10
  
  Dim cntMedias
  Dim arrRadioMedia()
  Dim arrRadioMediaID()
  Dim cntDrives
  Dim arrRadioDrive()
  Dim arrRadioDriveLetter()
  Dim arrRadioDriveSN()
  Dim arrRadioDriveTypes()

  Dim SDB
  Set SDB = CreateObject("SongsDB.SDBApplication")
  Dim FSO
  Set FSO = CreateObject("Scripting.FileSystemObject")
  Dim UI
  Set UI = SDB.UI

  'Create the window to be shown
  Dim Form
  Set Form = UI.NewForm
  Form.Common.ClientWidth = objSpace + PanelWidth + objSpace + PanelWidth + objSpace
  Form.FormPosition = 4   ' Screen Center
  Form.BorderStyle = 3    ' Dialog
  Form.Caption = "Move MediaMonkey's Device Content"
  
  Dim Label
  Set Label = UI.NewLabel(Form)
  Label.Caption = "from ..."
  Label.Common.Top = objSpace
  Label.Common.Left = objSpace
  Label.Common.Width = PanelWidth
  
  Set Label = UI.NewLabel(Form)
  Label.Caption = "to ..."
  Label.Common.Top = objSpace
  Label.Common.Left = objSpace + PanelWidth + objSpace
  Label.Common.Width = PanelWidth
  
  Dim PanelMedia
  Set PanelMedia = UI.NewPanel(Form)
  PanelMedia.Common.SetRect objSpace, objSpace + Label.Common.Height + objSpace, PanelWidth, PanelHeight
  
  'Add Medias
  Dim ds
  Dim RadioBtn
  Dim BtnTop
  Dim Caption

  'Delete unused Medias
  SDB.DataBase.ExecSQL ("DELETE FROM Medias WHERE (DriveType < 10) AND (IDMedia NOT IN (SELECT IDMedia FROM Songs GROUP BY IDMedia))")
  
  BtnTop = 0
  cntMedias = 0
  Set ds = SDB.DataBase.OpenSQL("SELECT * FROM Medias WHERE DriveType < 10")
  While Not ds.EOF
    Caption = ""
    'If ds.StringByName("Driveletter") <> "" Then Caption = Chr(ds.ValueByName("DriveLetter") + 65) & ": "
    If ds.StringByName("Label") <> "" Then
      'If Caption <> "" Then Caption = Caption & "- "
      Caption = Caption & ds.StringByName("Label")
    End If
    If ds.StringByName("ShowLabel") <> "" Then
      If Caption <> "" Then Caption = Caption & "- "
      Caption = Caption & ds.StringByName("ShowLabel")
    End If
    If Caption = "" Then Caption = ds.StringByName("Comment")
    
    Set RadioBtn = UI.NewRadioButton(PanelMedia)
    RadioBtn.Common.Top = BtnTop
    RadioBtn.Common.Width = PanelWidth
    BtnTop = BtnTop + RadioBtn.Common.Height + 3
    PanelMedia.Common.ClientHeight = BtnTop
    RadioBtn.Caption = Caption
    RadioBtn.Common.Hint = ds.StringByName("Comment")
    
    cntMedias = cntMedias + 1
    ReDim Preserve arrRadioMedia(cntMedias)
    ReDim Preserve arrRadioMediaID(cntMedias)
    Set arrRadioMedia(cntMedias) = RadioBtn
    arrRadioMediaID(cntMedias) = ds.ValueByName("IDMedia")
    
    ds.Next
  Wend
  
  Dim PanelDrives
  Set PanelDrives = UI.NewPanel(Form)
  PanelDrives.Common.SetRect objSpace + PanelWidth + objSpace, objSpace + Label.Common.Height + objSpace, PanelWidth, PanelHeight
  
  'Add DriveLetters
  BtnTop = 0
  cntDrives = 0
  Dim Drive
  For Each Drive In FSO.Drives
    If Drive.IsReady Then
      Caption = Drive.DriveLetter & ":"
      Caption = Caption & " - " & Drive.VolumeName
    
      Set RadioBtn = UI.NewRadioButton(PanelDrives)
      RadioBtn.Common.Top = BtnTop
      RadioBtn.Common.Width = PanelWidth
      BtnTop = BtnTop + RadioBtn.Common.Height + 3
      PanelDrives.Common.ClientHeight = BtnTop
      RadioBtn.Caption = Caption
	  RadioBtn.Common.Hint = CStr(Drive.SerialNumber) 'TotalSize / 1024 / 1024 / 1024
    
      cntDrives = cntDrives + 1
      ReDim Preserve arrRadioDrive(cntDrives)
      ReDim Preserve arrRadioDriveLetter(cntDrives)
      ReDim Preserve arrRadioDriveSN(cntDrives)
      ReDim Preserve arrRadioDriveTypes(cntDrives)
      Set arrRadioDrive(cntDrives) = RadioBtn
      arrRadioDriveLetter(cntDrives) = Drive.SerialNumber
      arrRadioDriveSN(cntDrives) = Drive.SerialNumber
      arrRadioDriveTypes(cntDrives) = Drive.DriveType + 1
    End If
  Next
  
  If PanelDrives.Common.Height > PanelMedia.Common.Height Then
    BtnTop = PanelDrives.Common.Height
  Else
    BtnTop = PanelMedia.Common.Height
  End If
  
  Set Label = UI.NewLabel(Form)
  Label.Caption = "Only the Database-Entries are updates. The Files aren't moved physically on the Harddisk!"
  Label.Common.Top = objSpace + Label.Common.Height + objSpace + BtnTop + objSpace
  Label.Common.Left = objSpace
  Label.Common.Height = Label.Common.Height * 2
  Label.Common.Width = Form.Common.ClientWidth - objSpace - objSpace
  Label.MultiLine = True
  
  Dim Btn
  Set Btn = UI.NewButton(Form)
  
  BtnTop = Label.Common.Top + Label.Common.Height + objSpace
  
  Btn.Caption = SDB.Localize("&Ok")
  Btn.Common.SetRect objSpace, BtnTop, PanelWidth, 25
  Btn.ModalResult = 1
  Btn.Default = True

  Set Btn = UI.NewButton(Form)
  Btn.Caption = SDB.Localize("&Cancel")
  Btn.Common.SetRect objSpace + PanelWidth + objSpace, BtnTop, PanelWidth, 25
  Btn.ModalResult = 2
  Btn.Cancel = True
  
  Form.Common.ClientHeight = BtnTop + 25 + objSpace
  
  If Form.ShowModal = 1 Then 'OK
    Dim SelMedia     'Media-ID
    Dim SelDrive     'Drive Letter
    Dim selDriveSN   'SerialNumber
    Dim SelDriveType 'Drive Type
    SelMedia = ""
    SelDrive = ""
    
    Dim intTemp
    For intTemp = 1 To cntMedias
      If arrRadioMedia(intTemp).Checked Then SelMedia = arrRadioMediaID(intTemp)
    Next
    For intTemp = 1 To cntDrives
      If arrRadioDrive(intTemp).Checked Then
        SelDrive = arrRadioDriveLetter(intTemp)
        selDriveSN = arrRadioDriveSN(intTemp)
        SelDriveType = arrRadioDriveTypes(intTemp)
      End If
    Next
    
    If (SelDrive <> "") And (SelMedia <> "") Then
      If SDB.MessageBox("Are you really sure?", 0, Array(0, 2)) = 6 Then
        Set ds = SDB.DataBase.OpenSQL("SELECT * FROM Medias WHERE SerialNumber = " & selDriveSN)
        If Not ds.EOF Then
          SDB.DataBase.ExecSQL ("Update Songs set IDMedia = " & ds.StringByName("IDMedia") & " WHERE IDMedia = " & SelMedia)
        Else
          SDB.DataBase.ExecSQL ("Update Medias set SerialNumber = " & selDriveSN & ", DriveType = " & SelDriveType & " WHERE IDMedia = " & SelMedia)
        End If
		SDB.MessageBox "Please restart MediaMonkey", 2, Array(4)
      End If
    End If
  End If
End Sub
PS: Maybe someone else whith english as mother tongue could discribe it a little better.
Last edited by onkel_enno on Mon Mar 16, 2009 9:41 am, edited 4 times in total.
DiddeLeeDoo
Posts: 1017
Joined: Wed Mar 01, 2006 1:09 am
Location: In a jungle down under
Contact:

Post by DiddeLeeDoo »

Wish I knew about this one before. I upgraded the Music HDD to a larger one for some weeks back, and had to do the numbers manually.

Beautiful script, and now I know that it exist here for next time...

BTW, maybe it should just be a 'Double Click' script instead of a Menu script...
Image
Nebbin
Posts: 316
Joined: Mon May 30, 2005 4:52 am
Location: Australia

Post by Nebbin »

I had similar issue a while back. Fixed it simply by changing one entry (the serial number) in the database Media table. Didn't need to do it per track since all tracks were already mapped to the one media ID. (Of course you need to get the new HD's serial number first.)

Regardless, it's a great script that should make the upgrade experience a lot easier. Also, this way you don't need to edit the DB manually (which can be dangerous for a new user).
DiddeLeeDoo
Posts: 1017
Joined: Wed Mar 01, 2006 1:09 am
Location: In a jungle down under
Contact:

Post by DiddeLeeDoo »

I changed drive letter too, and had to learn the Chr(65+... thingy to do it. Went from D to M.. :)
Image
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

DiddeLeeDoo wrote:I changed drive letter too, and had to learn the Chr(65+... thingy to do it. Went from D to M.. :)
MM should find it too, if the SerialNumber is correct!
pbparker
Posts: 41
Joined: Thu Dec 22, 2005 6:41 pm

Post by pbparker »

Thanks for the script.. just used it to move the library to a new larger drive.
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Post by Teknojnky »

Great script, it definately should be included in the default MM installation.
toxboy
Posts: 12
Joined: Wed Oct 18, 2006 12:16 pm

Post by toxboy »

I have a question about this script, that I have not seen any comment about.
Should this script work for moving a music library from a standard drive, like USB drive E: to a network drive, such as //WORK/JUKE BOX/ ? I can not seem to get it to recognize my network drives? Also, I am trying to avoid letter-mapping the drive as advised for the use of MM.

I am not a scripter, so I don't know how to assess the capabilities of the script by looking at the code.

I do use a number of scripts sucessfully, so I have some knowledge of setting up and executing scripts, both auto and regular.

Anyone?

Greg
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

toxboy wrote:Should this script work for moving a music library from a standard drive, like USB drive E: to a network drive, such as //WORK/JUKE BOX/ ?
No Sorry, the script isn't able to do that.
Netwaork drives and Local Drives are managed different within mediamonkey.
Tylast
Posts: 130
Joined: Sun Jan 29, 2006 12:54 pm
Location: US
Contact:

Post by Tylast »

This script should definitely be included in the initial setup...saved my database! :D
Image
Jaymis
Posts: 6
Joined: Mon Jul 03, 2006 10:51 pm
Contact:

Post by Jaymis »

Fantastic script. Thanks! This is definitely a useful functionality to be included with MM.
thefaceman
Posts: 367
Joined: Sun Aug 28, 2005 10:43 pm

How do I do Step 4?

Post by thefaceman »

4. Make sure every Device (harddrive) has a Label (Archive -> Location)

How Do I do this step in the instructions below? Is it a MediaMonkey function or a Explorer thing I have to do?

-thanks
-thefaceman

onkel_enno wrote: ...

Code: Select all

...
'4. Make sure every Device (harddrive) has a Label (Archive -> Location)
...
Edited by onkel enno
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

Please no Full Quotes.

In MediaMonkey:
Archive -> Locations -> Drive -> Properties -> Label
thefaceman
Posts: 367
Joined: Sun Aug 28, 2005 10:43 pm

OK... getting closer to understanding

Post by thefaceman »

OK. Now I see why I could not understand step #4. My "Archive" does not say archive it says "Library".

I can see where I can change the "label" field for each drive.

A few questions.

I have a label on a few of my drives that do not show up in the label field in mediamonkey, how can I 'refresh' the hierarchy to update so that the label is shown correctly. Do I have to reboot? cause I only restarted mediamonkey and it still does not update?

I have 2 "H" drives. Near one is correctly matching the name of my "H" drive. How should this be fixed?

If neither of the above matters. When I update the label field, what "label" should I use? Is it the one that matches the file link that I want to rescan to"?

Thanks again for your assistance in advance
-later
-thefaceman
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Re: OK... getting closer to understanding

Post by onkel_enno »

thefaceman wrote:OK. Now I see why I could not understand step #4. My "Archive" does not say archive it says "Library".
Ups, that was german :lol:

Settings Labels for every Drive is only for you to differ the drives from each other in the Dialog
Post Reply