INTERACT FORUM

Please login or register.

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

Author Topic: MCWS for bulk changes in the database (File/SetInfo is too slow)  (Read 6353 times)

Tolga

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 438

Is there a way to upload a bulk of (key, field, value) tupples to MC via MCWS efficiently?

I need this for various utilities I am writing like the one that embeddes content MD5 hash into the DB to ensure data integrity. Sending updates to MC File/SetInfo one at a time works but it is very inefficient. Is there a better method to upload bulk of data? I believe Library/Merge may have similar functionality but the format of uploaded file is not documented. An option that allows MPL files as input should do the trick.
Logged

Lasse_Lus

  • Citizen of the Universe
  • *****
  • Posts: 999
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #1 on: January 17, 2013, 08:20:15 am »

have you checked/tried prod's sqlmytunes ? http://yabb.jriver.com/interact/index.php?topic=56405.0
Logged
MT5FR

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #2 on: January 17, 2013, 11:03:34 am »

I don't know if this is an option or helps, but if you create a playlist with your tuple, replacing the file key with the full path to the file, you can import the entire thing in one shot.
Logged
The opinions I express represent my own folly.

Tolga

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 438
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #3 on: January 18, 2013, 12:57:15 am »

I don't know if this is an option or helps, but if you create a playlist with your tuple, replacing the file key with the full path to the file, you can import the entire thing in one shot.

I wonder if this can be used to overwrite existing values in the db, or filetags. I doubt it but worth trying. It is also a little hacky to to be part of a plugin code.
Logged

Tolga

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 438
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #4 on: January 18, 2013, 12:58:27 am »

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #5 on: January 18, 2013, 01:15:25 am »

I wonder if this can be used to overwrite existing values in the db, or filetags. I doubt it but worth trying. It is also a little hacky to to be part of a plugin code.

Overwrite: Yes.  Clear: No.
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #6 on: February 28, 2013, 12:16:02 pm »

If you have a proposal for MCWS function additions, just spec it out here.

If it's reasonable, we'll add it.
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #7 on: September 12, 2013, 09:11:38 pm »

Ok, old topic, but I have a need (desire) now.

I'd like to be able to set a series of file properties.  Currently SetInfo allows only one Field/Value pair:

    http://localhost:52199/MCWS/v1/File/SetInfo?FileType=Key&File=21169586&Field=Album&Value=TestAlbum

How about support multiple Field/Value pairs?

    http://localhost: ... &Field=Album&Value=TestAlbum&Field=Rating&Value=0&Field=Genre&Value=Junk

This would save me dozens of calls per track.
Logged
The opinions I express represent my own folly.

GrantDG

  • World Citizen
  • ***
  • Posts: 199
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #8 on: September 16, 2013, 06:12:53 am »

Could this be done with database Sync?

MCWS/v1/Library/Get
MCWS/v1/Library/Merge
Logged
Looking to control J River Media Center from your Windows Phone?: Look for nMedium & nMedium Play in the WP store

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #9 on: September 18, 2013, 06:34:22 pm »

How about support multiple Field/Value pairs?

    http://localhost: ... &Field=Album&Value=TestAlbum&Field=Rating&Value=0&Field=Genre&Value=Junk

I like the idea of setting multiple at once, but not the idea of using the same parameter name multiple times.  Doing that would be challenging for us with the current architecture, and I'm not sure if we should count on proxies, etc. not reordering parameters anyway.

How about accepting an MPL block (optionally as a posted parameter)? 

Or using Field1, Value1, Field2, Value2, etc.?

Another approach would be a special delimited string, but at that point, we might as well use MPL like the rest of the MCWS functions.
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #10 on: September 18, 2013, 06:40:24 pm »

I had thought about that, and figured you'd provide good feedback to better alternatives.  Either approach is fine with me; MPL seems a little excessive, but that's OK.

Since I already have MPL being output, it would be easy to convert it to a block.  I presume I'll need to turn newlines, line feeds, and question marks into HTML entities.
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #11 on: October 07, 2013, 03:42:27 pm »

A little bump on this.  Individual field updates are painfully slow.

For example, I'm updating the following 18 fields (these are keys to field names) for 18 tracks, and it is taking 35 seconds to complete:

   album, apick, artist, composer, date, genre, mediatype, moods, name, rating,
   ratingmc, review, styles, themes, tpick, tracknum, turl, url

That's 324 calls (+ 1 call per/track to get the filekey), or about .11 seconds / call.

It is far faster to output to MPL and manually import it via File > Import Playlist.

Ideally, it would be great to be able to send a multi-Item/multi-Field MPL, keyed by either Filename or Filekey to do a single bulk update.  Fields that don't exist, like when using File > Import Playlist, should be silently ignored (currently they throw a 500 server error).
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #12 on: October 07, 2013, 04:32:27 pm »

I haven't forgotten about this, I'm just not sure the best way to proceed.

Is it important to be able to do more than one file in a call, or just more than one field?

Would a generic pipe-lining system be useful (ie. MCWS/v1/Pipeline) where you post a bunch of calls all at once?  I'm not quite sure how the return values would work in that case.
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #13 on: October 07, 2013, 05:18:39 pm »

Thanks.

One multi-field file per call would be fine, assuming about 1/10 second per call, an album would take 1 to 2 seconds, and that seems reasonable.  In this case, probably the preamble is unnecessary, and only the Item contents are important.  But its easy either way.  For my needs, I'm updating one file at a time and always have the Filename.

I don't know if you saw the last sentence in my post above, which I added later.   If multiple files are possible or practical (each Item keyed by Filename or Filekey), being able to send an encoded multi-Item MPL would be a bonus.

Regarding errors, I'd like to see 500 server errors split into hard errors (e.g. protocol error, invalid syntax) and softer errors with response contents indicating the error (e.g. "Field "Foo" does not exist", for example), so that the soft errors can be detected and ignored, but hard errors could trigger an abort.

I'd have to look into how the URL package code I'm using deals with pipelining.

Edit: I thought about this some more.  I can think of at least one tool I would write that would take advantage of fast writing of  many files in a single shot.  So, I'm leaning towards thinking the number of items/fields should be arbitrary, just like a structured MPL is currently.

Edit 2:  Further investigation reveals the modules I'm using don't support pipelining, so I'm hoping you don't go this route. :-)
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #14 on: October 08, 2013, 04:13:57 pm »

Next build:
SDK: MCWS/v1/File/SetInfo supports setting multiple fields / values per call by CSV encoding a list for Field and Value parameters and also setting a parameter List=CSV.

We thought CSV was easy to deal with and reasonably well understood.  In many cases, a simple comma delimited list will work.  It only gets more complicated when there are escape characters.  RFC 4180 specifies how to handle these cases.

Here's an example call that does some escaping:
http://localhost:52199/MCWS/v1/File/SetInfo?File=1166&FileType=Key&Field=Artist,Album,Name&Value=MrC,%22Was,%22,Here&List=CSV
Logged
Matt Ashland, JRiver Media Center

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #15 on: October 08, 2013, 04:17:40 pm »

Regarding errors, I'd like to see 500 server errors split into hard errors (e.g. protocol error, invalid syntax) and softer errors with response contents indicating the error (e.g. "Field "Foo" does not exist", for example), so that the soft errors can be detected and ignored, but hard errors could trigger an abort.

At a basic level, a function either works (200) or doesn't work (500).

When it doesn't work, it often provides extra clues.  For example, if you use bad CSV and call the updated MCWS/v1/File/SetInfo, you get a 500 and this XML:
<Response Status="Failure" Information="Invalid CSV data."/>

Does that help?
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #16 on: October 08, 2013, 04:19:43 pm »

Yes, that's great.  I presume it will also yield an "Invalid Field Name" under such circumstances.
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #17 on: October 08, 2013, 04:22:42 pm »

Yes, that's great.  I presume it will also yield an "Invalid Field Name" under such circumstances.

Yes, if you do a single field / value.  When you use CSV, it's a little harder to know what to do for error handling.  Currently if the CSV looks good, it'll return success even if none of the field names are found.

If there are errors where it's not giving helpful information, just report them and we'll improve it.
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #18 on: October 08, 2013, 07:47:19 pm »

I think something is not working correctly when values contain , or ? characters.  I'm URL encoding values, and then CSV-ifying them.  The value for Name below contains both comma and question mark.

If I remove Name from the write, it works fine.  I wonder if you are doing the reverse of what I'm doing on receipt, i.e. URL decode then reading the CSV?

Code: [Select]
mcws_send_items: Filename: M%3A%5CTesting%5CAbbey%20Lincoln%5CYou%20Gotta%20Pay%20the%20Band%5C04%20Brother%20Can%20You%20Spare%20a%20Dime.mp3
mcws_send_items: Added field(name): Name -> Brother, Can You Spare a Dime?
mcws_send_items: Added field(album): Album -> You Gotta Pay the Band
mcws_send_items: Added field(mediatype): Media Type -> Audio
http://localhost:52199/MCWS/v1/File/SetInfo?List=CSV&Value=Brother%2C%20Can%20You%20Spare%20a%20Dime%3F,You%20Gotta%20Pay%20the%20Band,Audio&Field=Name,Album,Media%20Type&FileType=Filename&File=M%3A%5CTesting%5CAbbey%20Lincoln%5CYou%20Gotta%20Pay%20the%20Band%5C04%20Brother%20Can%20You%20Spare%20a%20Dime.mp3
500 Internal server error
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Response Status="Failure" Information="Invalid CSV data."/>
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #19 on: October 09, 2013, 03:10:39 pm »

I think something is not working correctly when values contain , or ? characters.  I'm URL encoding values, and then CSV-ifying them.  The value for Name below contains both comma and question mark.

I haven't tested this yet, but just thinking about it, I'd expect you to work in the other order: first make CSV, then URL encode it for use as parameters.

In the reverse, we get URL parameters and URL decode them first.  Then we're left with regular strings, or in this case, CSV.

Does that make sense?

Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #20 on: October 09, 2013, 03:38:20 pm »

Yes, it does make sense.  The first test looks good.  On to more testing...

The first album took a whole 1.2 seconds, including the external page scraping lookups.  Very nice.

Thank you.
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #21 on: October 09, 2013, 04:09:28 pm »

Testings looks good.  It is very fast and nifty.

I (and others) thank you! :-)

Time to release some code...
Logged
The opinions I express represent my own folly.

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: MCWS for bulk changes in the database (File/SetInfo is too slow)
« Reply #22 on: October 09, 2013, 04:28:06 pm »

I (and others) thank you! :-)

Indeed. And thanks for testing MrC.
Logged
Pages: [1]   Go Up