INTERACT FORUM

Please login or register.

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

Author Topic: Help with MCWS - Files/Search -- save to file  (Read 4290 times)

DoubtingThomas

  • Citizen of the Universe
  • *****
  • Posts: 564
Help with MCWS - Files/Search -- save to file
« on: June 06, 2015, 02:20:05 pm »

I'm trying to get MC to basically export my entire library using MCWS.  I'd like the output to be csv but I can deal with mpl.

When I run the example

localhost:52199/MCWS/v1/Files/Search?Action=mpl&ActiveFile=-1&Zone=-1&ZoneType=ID

Windows prompts me for a filename, I'd like to have the command automatically write/overwrite to my hard drive without prompting.  I've tried many things, but either it won't do what I want or I don't understand the parm list.

Or, is there another way to export my library (or a named playlist) to a file without having to click any buttons?

  Files

      Search
         Perform a database search for files.
         Parameters:
            Query: The search string (empty returns full library) (default: )
            Action: The action to perform with the files (MPL: return MPL playlist; Play: plays files; Save: saves the files (as a playlist in the library, etc.); Serialize: return serialized file array (basically a list of file keys)). (default: mpl)
            Shuffle: Set to 1 to shuffle the files. (default: )
            ActiveFile: A file key to set as active (used as the file that playback starts with, etc.). (default: -1)
            ActiveFileOnly: Set to 1 to trim the returned files to only contain the active file. (default: )
            PlayMode: Play mode flags delimited by commas (Add: adds to end of playlist; NextToPlay: adds files in the next to play position). (default: )
            Fields: The fields to include in an MPL (use empty to include all fields). (default: )
            NoLocalFilenames: Set to 1 to filter out local filenames from MPL output (since they might be meaningless to a server). (default: )
            PlayDoctor: Set to 1 to change the files to a Play Doctor generated playlist using these files as a seed. (default: )
            SaveMode: Playlist: playlist (overwrites existing; returns ID) (default: )
            SaveName: A backslash delimited path used with the action 'Save'. (default: )
            NoUI: Set to one to put the player in no UI mode. (default: )
            Zone: The zone the command is targetted for. (default: -1)
            ZoneType: The type of value provided in 'Zone' (ID: zone id; Index: zone index; Name: zone name). (default: ID)
Logged

tiberiuspv

  • Recent member
  • *
  • Posts: 49
Re: Help with MCWS - Files/Search -- save to file
« Reply #1 on: June 12, 2015, 02:25:30 pm »

Multiple options:

1. You can export the entire library directly to XML. Open the 'Manage library' page (left pane, Playing from > {Library name}). The last button under Tools is Export to XML.
2. You an export in MPL format (which is XML) the contents of any playlist. This is very useful to get a selected subset, like all pieces composed by Bach. Create a smartlist which describes the subset (left pane, right-click on Playlists, fill-in the form). Once that's done, right-click on the smartlist in the left pane and select Export playlist. This will export every track included in the smartlist.

BTW, if you have a large library, XML format is hard to digest for most applications. I have about 60k tracks. Trying to import the full library in XML into a browser or Excel gives you time for lunch...
Logged

DoubtingThomas

  • Citizen of the Universe
  • *****
  • Posts: 564
Re: Help with MCWS - Files/Search -- save to file
« Reply #2 on: June 12, 2015, 02:36:21 pm »

Thank you for the reply.  I am aware of how to do it using the menu system.  I was hoping for a way to automate the export without having to use the gui or click any buttons.
Logged

tiberiuspv

  • Recent member
  • *
  • Posts: 49
Re: Help with MCWS - Files/Search -- save to file
« Reply #3 on: June 12, 2015, 04:39:02 pm »

Sorry, I had missed the no-gui/no-button part...

Repeating your experiment in Chrome (your URL is perfectly correct) gives me a no-button-required download. Except of course for the button to access that URL (bookmark or the like).

When I do it in IE 8, it does not work at all.

Which browser are you using? MCWS returns a 'store to file'-style reply, what the browser decides to do with it depends on the browser only.
Logged

DoubtingThomas

  • Citizen of the Universe
  • *****
  • Posts: 564
Re: Help with MCWS - Files/Search -- save to file
« Reply #4 on: June 12, 2015, 07:24:54 pm »

Sorry, I had missed the no-gui/no-button part...

Repeating your experiment in Chrome (your URL is perfectly correct) gives me a no-button-required download. Except of course for the button to access that URL (bookmark or the like).

When I do it in IE 8, it does not work at all.

Which browser are you using? MCWS returns a 'store to file'-style reply, what the browser decides to do with it depends on the browser only.

I'm using Firefox.  But I'd be using wget to call MCWS.  I currently use an MC20.exe command, but it brings up the dialog for me to select options and the filename to write to.
Logged

tiberiuspv

  • Recent member
  • *
  • Posts: 49
Re: Help with MCWS - Files/Search -- save to file
« Reply #5 on: June 12, 2015, 09:58:33 pm »

wget should work just fine. But I can't help you there since I'm not running Linux at home, and not running MC at the office.
Logged

DoubtingThomas

  • Citizen of the Universe
  • *****
  • Posts: 564
Re: Help with MCWS - Files/Search -- save to file
« Reply #6 on: June 12, 2015, 10:08:27 pm »

wget should work just fine. But I can't help you there since I'm not running Linux at home, and not running MC at the office.

wget will work.. but it will bring up the dialog.. and requires clicking.

I was hoping there was a way to specify the playlist and output format and output file name in the MCWS command.
Logged

tiberiuspv

  • Recent member
  • *
  • Posts: 49
Re: Help with MCWS - Files/Search -- save to file
« Reply #7 on: June 13, 2015, 10:51:53 am »

I'm not sure I understand. I just tried the GnuWin32 version of wget in a command tool (~shell):
    wget -O ZZZ "http://localhost:52199/MCWS/v1/Files/Search?Action=mpl&ActiveFile=-1&Zone=-1&ZoneType=ID"
and I get the result in ZZZ without any dialog.
You do need the -O <filename> option otherwise wget guesses the file name from the requested URL, and it has no clue about non-trivial URLs (wget was designed 20 years ago, and the web has changed a lot since...).
You could also use curl instead of wget, but I don't think the results would be any different.

The dialog you are getting is because you are executing at the command line:
    MC20 "/MCWS/v1/Files/Search?Action=mpl&ActiveFile=-1&Zone=-1&ZoneType=ID"

The MC20 command you are executing from the command line does the http request to the 'main' MC20, but the command-line MC20 does not know what to do with the returned file, so it puts up a dialog asking you for the result file location. The 'main' MC20 just acts like a web server, while the command-line MC20 acts like a (fairly dumb) browser. 

If you use wget directly, there is no command-line MC 20 in the middle, and no dialog.
Logged

DoubtingThomas

  • Citizen of the Universe
  • *****
  • Posts: 564
Re: Help with MCWS - Files/Search -- save to file
« Reply #8 on: June 13, 2015, 11:10:46 am »

Thanks.  I actually never tried wget with this MCWS command and I just incorrectly assumed the dialog would appear as it does if I use the url in Firefox and as it does when using the MC20.exe export command.  Of course that was a bad assumption.  Thank you for setting me straight.  I think this might work for me.  Thanks again.

I'm not sure I understand. I just tried the GnuWin32 version of wget in a command tool (~shell):
    wget -O ZZZ "http://localhost:52199/MCWS/v1/Files/Search?Action=mpl&ActiveFile=-1&Zone=-1&ZoneType=ID"
and I get the result in ZZZ without any dialog.
You do need the -O <filename> option otherwise wget guesses the file name from the requested URL, and it has no clue about non-trivial URLs (wget was designed 20 years ago, and the web has changed a lot since...).
You could also use curl instead of wget, but I don't think the results would be any different.

The dialog you are getting is because you are executing at the command line:
    MC20 "/MCWS/v1/Files/Search?Action=mpl&ActiveFile=-1&Zone=-1&ZoneType=ID"

The MC20 command you are executing from the command line does the http request to the 'main' MC20, but the command-line MC20 does not know what to do with the returned file, so it puts up a dialog asking you for the result file location. The 'main' MC20 just acts like a web server, while the command-line MC20 acts like a (fairly dumb) browser. 

If you use wget directly, there is no command-line MC 20 in the middle, and no dialog.
Logged

tiberiuspv

  • Recent member
  • *
  • Posts: 49
Re: Help with MCWS - Files/Search -- save to file
« Reply #9 on: June 13, 2015, 11:53:40 am »

No problem, happy to help.

Rereading your original message, I realized that you were running under Windows, not Linux... Which wget are you running?

You can also do this directly (i.e. without wget) using PowerShell (just google powershell get url). But this is worth it only if you already use powershell, as the learning curve is a bit steep.

In any case, you can't really avoid one interaction to start the process (for example click on a batch file for wget or powershell). Except if you just need to get the export on a regular basis (like once every night), in which case you could use the task scheduler to start the wget.

Good luck...
Logged

DoubtingThomas

  • Citizen of the Universe
  • *****
  • Posts: 564
Re: Help with MCWS - Files/Search -- save to file
« Reply #10 on: June 13, 2015, 12:19:41 pm »

No problem, happy to help.

Rereading your original message, I realized that you were running under Windows, not Linux... Which wget are you running?

You can also do this directly (i.e. without wget) using PowerShell (just google powershell get url). But this is worth it only if you already use powershell, as the learning curve is a bit steep.

In any case, you can't really avoid one interaction to start the process (for example click on a batch file for wget or powershell). Except if you just need to get the export on a regular basis (like once every night), in which case you could use the task scheduler to start the wget.

Good luck...


It took me a while to figure out how to get fields using Fields= with a space in them....   Last%20Played

I'll call the export script using WinCron (scheduler).  I'm actually running this from a UNIX korn shell using Cygwin.  DOS batch files are very limited, and PowerShell does have a learning curve, and I can do unix shell scripting in my sleep.

Thanks Again
Logged
Pages: [1]   Go Up