INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: merge main library with an added library.  (Read 3666 times)

pluto7

  • Junior Woodchuck
  • **
  • Posts: 92
merge main library with an added library.
« on: March 04, 2013, 02:38:49 pm »

I have a problem in finding the best way to join or merge two libraries together. I have one library with a large amount of audio cd’s, and another with newly added files of audio data. I do this because I want to make the necessary correction to the data before adding them to the main library, it would be nearly impossible “very time consuming” to find the problem files in the large main library. Any help will be appreciated.
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: merge main library with an added library.
« Reply #1 on: March 04, 2013, 04:07:23 pm »

Merging separate libraries is not a simple task.  The Library is MC's main database, and contains not only just the file metadata, but the entire view system within MC.  There are not built-in tools to merge two databases.

A better method would be to:

1. Use your current methodology, and then simply import the files into your main MC Library fresh once they're ready.  Auto-Import will pick up and use the tags you changed in the files, so long as the tagging changes are saved to the files (they are by default).

-OR-

2. Change your system to use one Library with a "tagging area" and specialized views that assist with this process.  Preventing the files from "intermingling" with your "deployed" files is a simple task that has been covered many times in other threads.  You can create views within one Library that make the process you said was "very time consuming" or "impossible" not only possible, but simple to deal with.

Which you choose would depend on your specific needs, but most power users here (myself included) would urge you to consider #2 as it will be the simplest to manage and won't require you to constantly switch Libraries (and try to keep the views in sync).  Most of us use some variation on this method.  If you want help setting up such a system, just ask (though try searching the forum first).
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

Mr. Odd

  • World Citizen
  • ***
  • Posts: 137
Re: merge main library with an added library.
« Reply #2 on: April 04, 2013, 02:56:39 pm »

I currently have two libraries, one of which is a subset of the other. I'd like to put them together, any suggestions for merging two libraries which maintains and merges their play stats?
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: merge main library with an added library.
« Reply #3 on: April 04, 2013, 04:24:36 pm »

I currently have two libraries, one of which is a subset of the other. I'd like to put them together, any suggestions for merging two libraries which maintains and merges their play stats?

There is no simple way to merge two libraries.

If you simply import the files in one of the Libraries into the other Library, they will maintain most of their metadata.  Any normal tags you've changed ([Artist], [Notes], [Lyrics], [Series], etc) will automatically transfer over when you import them into the other library (the one you're going to keep).  Just make sure the tags have been applied to all the files first by selecting them all and doing Right Click > Library Tools > Update Tags (from Library).  Then, switch to the other Library and import them.

However, you mention one of the main things they'll "lose".  When you import them into MC, it will not preserve the Play Stats ([Date Imported], [Last Played], [Number of Plays], etc).  They will start from scratch.  There is not, that I know of, a simple way to retain that data.

If you are both:

(A) A reasonably adept programmer or proficient with MySQL.
(B) Crazy

There is a way to do it through the automation interface or prod's SQL plugin with two separate instances of MC.  It would not be for the feint of heart at all though.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: merge main library with an added library.
« Reply #4 on: April 04, 2013, 07:02:27 pm »

if it would  be useful, I'll write a quick perl script to accept multiple MPL playlists, combine them, combine the stats, or out the latest value for things like Last Played, etc.  Then, the output MPL could be imported, which would a) update existing stats, and b) import files in the other (non-current) library.
Logged
The opinions I express represent my own folly.

Mr. Odd

  • World Citizen
  • ***
  • Posts: 137
Re: merge main library with an added library.
« Reply #5 on: April 04, 2013, 07:54:20 pm »

Yes, please, that sounds like exactly what I need, thanks!
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: merge main library with an added library.
« Reply #6 on: April 04, 2013, 07:59:12 pm »

How do you want to handle collisions?  That is, when the same media file has different values for a tag in the exported MPLs, which one should win?
Logged
The opinions I express represent my own folly.

Mr. Odd

  • World Citizen
  • ***
  • Posts: 137
Re: merge main library with an added library.
« Reply #7 on: April 04, 2013, 08:00:30 pm »

Hmm, whatever has the most recent modified date should win, I think.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: merge main library with an added library.
« Reply #8 on: April 08, 2013, 10:26:33 pm »

I have the library merger done.  So now it is time for you to test.  Here's what you need:

1. Download and install the appropriate version of ActivePerl for your system (or Cygwin tools - include perl.  If you are on a Mac, you already have perl installed.)

2. Download and unzip the attached mergelib zip file and save it somewhere convenient.

3. You'll need MPL exports of the libraries you want merged.  One library at a time, load the library, and export it using File > Export Playlist.  Select options MPL Playlist (Media Center only) and Output Range: All.  Provide an appropriate Filename (and perhaps Title) indicating to which library this export belongs, and save the file somewhere convenient for accessing via command line.

4. Open a command window and run the command.  The command syntax is:

   perl.exe mergelib.pl  mclib1.mpl mclib2.mpl [...] > merged.mpl

where mclib1.mpl, etc. are paths to your two or more MPL files, and merged.mpl is a filename path where the merged MPLs output will be placed.  If you are on a Mac or other unix/linux system, either use perl instead of perl.exe (or eliminate the need to use state the perl interpreter by making the script executable).

You can examine the contents of merged.mpl.  When you are ready to import, use File > Import Playlist and import the merged.mpl file.

I would advise that you test importing to a new library first.  And certainly backup your library before doing an import (File > Library > Back Up Library), so that if anything goes wrong, you can Restore Library.

You can also export only the selected items to the MPL files if you wanted to test something smaller.  Just select the items you want exported, and choose the Output Range: Selection export option (instead of All).

For each file entry in the MPLs (keyed off Filename), the field values are handled accordingly:

The following field values are summed:
   - Number Plays
   - Skip Count

The greatest value (i.e. oldest date) is selected for the following fields:
   - Last Played
   - Last Skipped
   - Date Created
   - Date Modified
   - Date Imported

For all other fields, the value used will be from the file with the most recent Date Modified.

If a field exists in any MPL, it will be added to the output MPL.

If you have Custom fields you'll want summed, it is easy enough to modify the code to catch these cases.

Let me know how it works out.
Logged
The opinions I express represent my own folly.

Mr. Odd

  • World Citizen
  • ***
  • Posts: 137
Re: merge main library with an added library.
« Reply #9 on: April 09, 2013, 06:13:39 am »

The greatest value (i.e. oldest date) is selected for the following fields:
   - Last Played
   - Last Skipped
   - Date Created
   - Date Modified
   - Date Imported


Wow, this is fantastic, thanks for your help! One thing I'm not clear on: shouldn't Last Played/Last Skipped/Date Modified be the most recent date whereas the Date Created should be the oldest date?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: merge main library with an added library.
« Reply #10 on: April 09, 2013, 11:21:49 am »

Currently the value chosen is the largest value (which means the most recent).

Can you see a case where Date Created across MPL files would be different for the same media file?  I'm thinking they would be the same.

Note that Windows is strange with regards to Date Created and Date Modified wrt. copied files.
Logged
The opinions I express represent my own folly.

lise

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 946
Re: merge main library with an added library.
« Reply #11 on: April 10, 2013, 05:37:41 pm »

Mr C, I don't need to merge libraries, but I did want to say that I am astounded at your generosity and contributions in this forum. What you did here, creating a script to help someone out of a jam, that was above and beyond and I just wanted to let you know that it was very much appreciated even by people like me who don't require the script!
Logged
A wise man once said don't count your years, but make your years count. Or was it beers?

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: merge main library with an added library.
« Reply #12 on: April 10, 2013, 06:46:04 pm »

Thanks for the kinds words.
Logged
The opinions I express represent my own folly.

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: merge main library with an added library.
« Reply #13 on: April 11, 2013, 10:41:31 am »

I'm reasonably sure that one of these days MrC is going to replace me with a very small Perl script.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: merge main library with an added library.
« Reply #14 on: April 11, 2013, 11:17:01 am »

You've been silent for several days here.  I was afraid one of my scripts ran out of control...
Logged
The opinions I express represent my own folly.

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: merge main library with an added library.
« Reply #15 on: April 11, 2013, 11:57:55 am »

You've been silent for several days here.  I was afraid one of my scripts ran out of control...

My wife was away, and I was solo-Dad with a sick kid.

Work is also quite busy.  I'm lurking though.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

Mr. Odd

  • World Citizen
  • ***
  • Posts: 137
Re: merge main library with an added library.
« Reply #16 on: April 27, 2013, 08:08:14 am »

Aside from a few spot-checks that didn't seem to work, it looks like your script accomplished most of what I wanted. Bravo! Thanks so much for the help!
Logged
Pages: [1]   Go Up