Help me with Custom Fields

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

eljay05

Help me with Custom Fields

Post by eljay05 » Fri Feb 03, 2006 10:05 am

Help me with Custom Fields... i want to have a field named "Date Created" or "Date Modified" Field... which you know sorts my mp3 on the date which is created... thankx

Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm
Location: Belgium
Contact:

Post by Steegy » Fri Feb 03, 2006 10:23 am

Hello

Here's some code if you want "Date Created". If you want "Date Modified", you don't need this script because this functionality is already in MediaMonkey (right-click the column headers and check "Last Modified"):

Add the following lines to the Scripts.ini file (normally C:\Program Files\MediaMonkey\Scripts\Scripts.ini):

Code: Select all

[SelectedFilesStoreDate]
FileName=SelectedFilesStoreDate.vbs
ProcName=SelectedFilesStoreDate
Order=5
DisplayName=SelectedFilesStoreDate
Description=SelectedFilesStoreDate
Language=VBScript
ScriptType=0
This will add the script to MediaMonkey's Scripts menu: menu Tools > Scripts > SelectedFilesStoreDate

The script will save the date and time when the file was created to the field Custom3 for the selected files.

You can change the field where the information is written to (e.g. change Custom3 to DateAdded), and you can also save the DateLastModified instead.

Save the following code as a text file called SelectedFilesStoreDate.vbs in MediaMonkey's Scripts folder (the same folder where you edited the Scripts.ini file)

SelectedFilesStoreDate.vbs

Code: Select all

'To store the DateCreated of a file to field Custom3, use:
'    mySong.Custom3 = GetFileDateCreated(mySong.Path)

'To store the DateLastModified of a file to field Custom3, use:
'    mySong.Custom3 = GetFileDateLastModified(mySong.Path)

'Change the line with "CHANGE HERE" according to what you want from the above possibilities


Sub SelectedFilesStoreDate
    Dim mySongList : Set mySongList = SDB.CurrentSongList

    If mySongList.Count = 0 Then
        SDB.MessageBox "Nothing selected!", mtError, Array(mbOK)
        Exit Sub
    End If

    Dim i, mySong
    For i = 0 To mySongList.Count - 1
        Set mySong = mySongList.Item(i)
        mySong.Custom3 = GetFileDateCreated(mySong.Path)   'CHANGE HERE
        mySong.UpdateDB
    Next
End Sub

Function GetFileDateCreated(FilePath)
    Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
    Dim File : Set File = FSO.GetFile(FilePath)
    GetFileDateCreated = File.DateCreated
End Function

Function GetFileDateLastModified(FilePath)
    Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
    Dim File : Set File = FSO.GetFile(FilePath)
    GetFileDateLastModified = File.DateLastModified
End Function
Cheers
Steegy
Last edited by Steegy on Thu Jun 14, 2007 8:42 am, edited 1 time in total.
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).

eljay05

Re:

Post by eljay05 » Fri Feb 03, 2006 11:05 am

well nyways did what you said... but nuttin happens the Date Created Field I Made comes out Empty

Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm
Location: Belgium
Contact:

Post by Steegy » Fri Feb 03, 2006 11:27 am

Did you select songs and then started the script using menu Tools > Scripts > SelectedFilesStoreDate ?

Are your "Custom 3" fields still empty then? (I suppose you renamed them to "Date Created")

(Obviously the script only works on files that exist, that are accessible)
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).

Franque

Post by Franque » Wed Oct 11, 2006 8:59 pm

I also think that the file creation date is much more important then the database addition date. This script is almost perfect. The only problem is that, being a text field, sorting doesn’t give you the correct order with this formatting (dd/mm/yyyy hh:mm:ss).

I backuped up the Data base e change the field to numeric and the sort function, in Access, worked fine. However, I couldn’t access data anymore from MediaMonkey, so I return to the backup file.

Wouldn’t the sort function give the correct order if the format were yyyy/mm/dd, instead? If so, how can this be done? (I suppose that this would be easier than change the type of the custom field, because that flexibility would have implications in other scripts, etc).

Thanks.

Guest

Post by Guest » Wed Jan 03, 2007 11:17 pm

Here is my attempt at modifying the script to use YYYYMMDD HH:MM format for improved sorting. I'm learning as I go, so it might be a little clumsy. It also borrows from other examples I found on the net. If the formatting disappears when I post this (as it does in my preview), I apologize. This would be saved as an alternate version of SelectedFilesStoreDate.vbs:

Code: Select all

'Modified 1/3/06 to save date in Custom3 as YYYYMMDD HH:MM format for improved sorting by date created

'To store the DateCreated of a file to field Custom3:
'    mySong.Custom3 = GetFileDateCreated(mySong.Path)

'To store the DateLastModified of a file to field Custom3:
'    mySong.Custom3 = GetFileDateLastModified(mySong.Path)

'Change the line with "CHANGE HERE IF YOU WANT" according to what you want (from the above possibilities)

Function pd(n, totalDigits) 
        if totalDigits > len(n) then 
            pd = String(totalDigits-len(n),"0") & n 
        else 
            pd = n 
        end if 
End Function 

Sub SelectedFilesStoreDate

  Dim mySongList
      Set mySongList = SDB.SelectedSongList

  If mySongList.Count = 0 Then
    Set mySongList = SDB.AllVisibleSongList
    If mySongList.Count = 0 Then
      SDB.MessageBox "Nothing selected!", mtError, Array(mbOK)
      Exit Sub
    End If
  End If

  Dim i, mySong, fd, fdt,fdtyyyymmd
  For i = 0 To mySongList.Count - 1
    Set mySong = mySongList.Item(i)
    fdt = GetFileDatecreated(mysong.path)   'CHANGE HERE IF YOU WANT
    if isdate(fdt) then
      fd = cDate(fdt)
      fdtyyyymmdd=Year(fd)&pd(month(fd),2)&pd(day(fd),2)&" "&formatdatetime(fd,vbShortTime)
    '  msgbox(fdtyyyymmdd)
      mySong.Custom3 = fdtyyyymmdd
      mySong.UpdateDB
    end if
  Next

End Sub



Function GetFileDateCreated(FilePath)

  Dim FSO
      Set FSO = CreateObject("Scripting.FileSystemObject")

  Dim File
      Set File = FSO.GetFile(FilePath)

  GetFileDateCreated = File.DateCreated

End Function



Function GetFileDateLastModified(FilePath)

  Dim FSO
      Set FSO = CreateObject("Scripting.FileSystemObject")

  Dim File
      Set File = FSO.GetFile(FilePath)

  GetFileDateLastModified = File.DateLastModified

End Function
EDIT Peke: Just made it look better.

Daniel

sorting by "date created"

Post by Daniel » Mon Mar 26, 2007 5:18 pm

Hello!

I also think, that the "Date created" option is more important than "last modified" or "added to library". If you tag an old file, it suddenly appears at the top of your time-sorted library-list, what is really confusing. So I tried the new script and it really works fine, but unfortunately the results of the sorting procedure are not saved. When I restart MM, I have to sort everything again!

Apart from this problem, the script-solution seems not be very elegant anyway, because you have to run the scrpit everytime you add a new mp3-file to your hard-disk. Is it possible, to implement this sorting functionality into MM, so that it works instantly, just like in the windows explorer?

thx for your reply!

Guest

Re: Help me with Custom Fields

Post by Guest » Fri Nov 16, 2007 5:38 am

eljay05 wrote:Help me with Custom Fields... i want to have a field named "Date Created" or "Date Modified" Field... which you know sorts my mp3 on the date which is created... thankx

Another Drunk NPC
Posts: 1
Joined: Mon Feb 21, 2011 1:34 am

Re: Help me with Custom Fields

Post by Another Drunk NPC » Mon Feb 21, 2011 1:39 am

Thanks for the script! It's indispensable. :D
I added a line of code that sets the "Date Added To Library" time to the filetime. In my opinion this makes "Recently Added" playlists 100% more useful.
Cheers.

Code: Select all

'To store the DateCreated of a file to field Custom3, use:
'    mySong.Custom3 = GetFileDateCreated(mySong.Path)

'To store the DateLastModified of a file to field Custom3, use:
'    mySong.Custom3 = GetFileDateLastModified(mySong.Path)

'Change the line with "CHANGE HERE" according to what you want from the above possibilities


Sub SelectedFilesStoreDate
    Dim mySongList : Set mySongList = SDB.CurrentSongList

    If mySongList.Count = 0 Then
        SDB.MessageBox "Nothing selected!", mtError, Array(mbOK)
        Exit Sub
    End If

    Dim i, mySong
    For i = 0 To mySongList.Count - 1
        Set mySong = mySongList.Item(i)
        mySong.Custom3 = GetFileDateCreated(mySong.Path)
        mySong.DateAdded = GetFileDateCreated(mySong.Path)  
'CHANGE HERE
        mySong.UpdateDB
    Next
End Sub

Function GetFileDateCreated(FilePath)
    Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
    Dim File : Set File = FSO.GetFile(FilePath)
    GetFileDateCreated = File.DateCreated
End Function

nohitter151
Posts: 23640
Joined: Wed Aug 09, 2006 10:20 am
Location: NJ, USA
Contact:

Re: Help me with Custom Fields

Post by nohitter151 » Mon Feb 21, 2011 11:00 am

Another Drunk NPC wrote:Thanks for the script! It's indispensable. :D
I added a line of code that sets the "Date Added To Library" time to the filetime. In my opinion this makes "Recently Added" playlists 100% more useful.
Cheers.
Are you aware that MM already keeps track of date added to library (the "Added" field)?
MediaMonkey user since 2006
Need help? Got a suggestion? Can't find something?

Please no PMs in reply to a post. Just reply in the thread.

HiFiGuy

Re: Help me with Custom Fields

Post by HiFiGuy » Tue Dec 27, 2011 1:56 pm

Hello--I used the VBS script that was posted by "Another Drunk NPC". First, thanks much for your work on this. My issue is that the dates don't sort accurately in Media Monkey. For example, files that were' created in 2010 will be followed by those created in 2011 and then back to 2010 again. Essentially, the sort function isn't working. Any thoughts how to correct this problem?

lordwasbinich
Posts: 1
Joined: Sat Nov 17, 2012 7:36 am

How to sort tracks by Date Created in Windows Explorer?

Post by lordwasbinich » Sat Nov 17, 2012 7:52 am

Hi,

first, I'm german but i think there are more answers in english forum so sorry for my bad english.
I accidentally deleted all music in MediaMonkey. Thats not bad because I already have it on my PC so I just added it again to MM. The problem is that I sorted them by Date added to MM so that I have the newest tracks at the top of the list. But now all tracks are added today. My question is: Is there a possibility to sort the tracks by Date Created like in Windows Explorer?
I think there is one with scripts and so on but i don't have any antycipation [I don't know if this is right] how this works and what to do. I think it have something to do with these custom columns.

I'm happy about all answers. I think with my english knowledges and translators I'm able to understand everything :wink:

GOT SOLUTION! FOR EVERYONE HAVING THE SAME PROBLEM: http://www.mediamonkey.com/forum/viewtopic.php?p=35656 WORKS PERFECT!
Last edited by Lowlander on Sat Nov 17, 2012 11:39 am, edited 2 times in total.
Reason: Merged with existing post

Ostrich Egg
Posts: 2
Joined: Fri May 01, 2015 7:24 pm

Re:

Post by Ostrich Egg » Fri May 01, 2015 7:54 pm

Guest wrote:Here is my attempt at modifying the script to use YYYYMMDD HH:MM format for improved sorting. I'm learning as I go, so it might be a little clumsy. It also borrows from other examples I found on the net. If the formatting disappears when I post this (as it does in my preview), I apologize. This would be saved as an alternate version of SelectedFilesStoreDate.vbs:

Code: Select all

'Modified 1/3/06 to save date in Custom3 as YYYYMMDD HH:MM format for improved sorting by date created

'To store the DateCreated of a file to field Custom3:
'    mySong.Custom3 = GetFileDateCreated(mySong.Path)

'To store the DateLastModified of a file to field Custom3:
'    mySong.Custom3 = GetFileDateLastModified(mySong.Path)

'Change the line with "CHANGE HERE IF YOU WANT" according to what you want (from the above possibilities)

Function pd(n, totalDigits) 
        if totalDigits > len(n) then 
            pd = String(totalDigits-len(n),"0") & n 
        else 
            pd = n 
        end if 
End Function 

Sub SelectedFilesStoreDate

  Dim mySongList
      Set mySongList = SDB.SelectedSongList

  If mySongList.Count = 0 Then
    Set mySongList = SDB.AllVisibleSongList
    If mySongList.Count = 0 Then
      SDB.MessageBox "Nothing selected!", mtError, Array(mbOK)
      Exit Sub
    End If
  End If

  Dim i, mySong, fd, fdt,fdtyyyymmd
  For i = 0 To mySongList.Count - 1
    Set mySong = mySongList.Item(i)
    fdt = GetFileDatecreated(mysong.path)   'CHANGE HERE IF YOU WANT
    if isdate(fdt) then
      fd = cDate(fdt)
      fdtyyyymmdd=Year(fd)&pd(month(fd),2)&pd(day(fd),2)&" "&formatdatetime(fd,vbShortTime)
    '  msgbox(fdtyyyymmdd)
      mySong.Custom3 = fdtyyyymmdd
      mySong.UpdateDB
    end if
  Next

End Sub



Function GetFileDateCreated(FilePath)

  Dim FSO
      Set FSO = CreateObject("Scripting.FileSystemObject")

  Dim File
      Set File = FSO.GetFile(FilePath)

  GetFileDateCreated = File.DateCreated

End Function



Function GetFileDateLastModified(FilePath)

  Dim FSO
      Set FSO = CreateObject("Scripting.FileSystemObject")

  Dim File
      Set File = FSO.GetFile(FilePath)

  GetFileDateLastModified = File.DateLastModified

End Function
EDIT Peke: Just made it look better.
This is just great. Thanks a lot. Is there a way to make this script run on each file upon being imported to the library?

EDIT: Ok, I had never done MM scripting before, but I was able to get it working :D

The script below adds the file created date as Custom3 on track import.

Code: Select all

'Modified 5/1/15 to save date in Custom3 as YYYYMMDD HH:MM format on track import

'To store the DateCreated of a file to field Custom3:
'    mySong.Custom3 = GetFileDateCreated(mySong.Path)

'To store the DateLastModified of a file to field Custom3:
'    mySong.Custom3 = GetFileDateLastModified(mySong.Path)

'Change the line with "CHANGE HERE IF YOU WANT" according to what you want (from the above possibilities)
Sub onStartup
  Script.RegisterEvent SDB, "OnTrackAdded", "AddFileStoreDate"
End Sub

Function pd(n, totalDigits) 
        if totalDigits > len(n) then 
            pd = String(totalDigits-len(n),"0") & n 
        else 
            pd = n 
        end if 
End Function 

Sub AddFileStoreDate(mysong)
	Dim fd, fdt, fdtyyyymmd
	fdt = GetFileDatecreated(mysong.path)   'CHANGE HERE IF YOU WANT
	if isdate(fdt) then
		fd = cDate(fdt)
		fdtyyyymmdd=Year(fd)&pd(month(fd),2)&pd(day(fd),2)&" "&formatdatetime(fd,vbShortTime)
		'msgbox(fdtyyyymmdd)
		mySong.Custom3 = fdtyyyymmdd
		mySong.UpdateDB
	end if
End Sub



Function GetFileDateCreated(FilePath)

  Dim FSO
      Set FSO = CreateObject("Scripting.FileSystemObject")

  Dim File
      Set File = FSO.GetFile(FilePath)

  GetFileDateCreated = File.DateCreated

End Function



Function GetFileDateLastModified(FilePath)

  Dim FSO
      Set FSO = CreateObject("Scripting.FileSystemObject")

  Dim File
      Set File = FSO.GetFile(FilePath)

  GetFileDateLastModified = File.DateLastModified

End Function

Peke
Posts: 11263
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Re: Help me with Custom Fields

Post by Peke » Sat May 02, 2015 8:30 pm

Hi,
Nice, I'm glad that it is still possible to make it work.
Best regards,
Pavle
MediaMonkey lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add Images to forum

kah

Re: Help me with Custom Fields

Post by kah » Mon May 18, 2015 11:33 am

How do I rename the custom3 field? For some reason it was named Creation Date until two days ago then when I re-opened mediamonkey yesterday all my previous settings were gone (skin,field name and nodes) it was like I had reinstalled mediamonkey again but my library was intact, all my files were there and their creation date were there too. I have no idea what happened.

Post Reply