Jump to content

C# - updating metadata (NotImplementedException)


PlutoIsAPlanet

Recommended Posts

PlutoIsAPlanet

Greetings all!

Be nice, I'm new here :)

During a recent upgrade of my Emby server, some of my songs had their Album Artist tags replaced with the path of the song on my Raspberry Pi: /home/pi/Music/_Lost And Found
Affected were songs which didn't belong to an album, instead they sit in a folder like "80's", "90's" etc. These folders contains a lot of songs.

I obviously don't want to manually update every single song affected through the web interface, so I thought I'd see if I could use the API to update this data.

So I'm iterating through those songs and modifying as follows:

  • Replacing the AlbumArtist property with "Various Artists"
  • Replacing the Name property of each entry in its AlbumArtists collection with "Various Artists"

and was hoping to update the BaseItemDto object by invoking the UpdateItem method. Unfortunately, I'm getting an exception here: NotImplementedException.

It would seem like the method hasn't been implemented yet so my questions are:

  1. Is it indeed implemented and I'm doing something wrong?
  2. If not, is there any other way I could update the metadata in C#?

Here's my code - have a great weekend!

// [snip]
const string VARIOUS_ARTISTS = "Various Artists";

foreach (var item in everything.Items.Where(x => !string.IsNullOrEmpty(x.AlbumArtist) && x.AlbumArtist.Contains("Lost")))
{
   item.AlbumArtist = VARIOUS_ARTISTS;

   if (item.AlbumArtists.Count() > 0)
   {
      foreach (var albumArtist in item.AlbumArtists)
      {
         albumArtist.Name = VARIOUS_ARTISTS;
      }
   }

   await client.UpdateItem(item);
}
// [snip]

 

Link to comment
Share on other sites

PlutoIsAPlanet

Ok, so I found this post from @Lukefrom back in 2017

grafik.png.f533b48b98259b7a8d4c2762fc8513a2.png

 

After heeding this advice, I went and looked at the code of the current API from the end of 2018.
As the error pointed out, the method isn't implemented:

grafik.png.58a97aa7b79281cde1ec1ccf4526d313.png

I'm able to grab the item, update its properties but not able to save the changes.

Any ideas?

Link to comment
Share on other sites

Hi, yes that c# apiclient is out of date at this point because we are no longer using it ourselves in our own apps. Your best bet will probably be to take the source for the library into your app and then implement the method:

https://github.com/MediaBrowser/Emby.ApiClient.Javascript/blob/master/apiclient.js#L3377

Link to comment
Share on other sites

PlutoIsAPlanet

Thank you @Luke for your assistance - may your beer tonight be a cold one.
Unfortunately, I have no idea about JS so I'm guessing a tad here with my C#

// Grab the song
var song = await client.GetItemAsync("43789", client.CurrentUserId);

// Update metadata
// [...]

// Grab the URL (this is from the web interface)
var url = "http://[IP_ADDRESS]:8096/web/index.html#!/item?id=12345&serverId=[SERVER_GUID]";
// The URL equivalent of the JS method: getUrl()
//url = "http://[IP_ADDRESS]:8096/emby/Items/12345";

// Post json using the http client
HttpClient httpClient = new HttpClient();
var json = JsonConvert.SerializeObject(song);
var data = new StringContent(json, Encoding.UTF8, "application/json");

var response = await httpClient.PostAsync(url, data);

The content what I'm looking to post looks good.

With the first URL (from the web interface, where I can actually see the song in its entirety) I'm getting a 404 (not found).
With the second URL (which I believe is what I could get from the JS method: getUrl() I'm getting a 401 (Unauthorized).

With a bit of luck the only issue is with my URL (and I'm building it wrong).
If I'm missing something else, I'd appreciate any tips.

Link to comment
Share on other sites

28 minutes ago, PlutoIsAPlanet said:

With the second URL (which I believe is what I could get from the JS method: getUrl() I'm getting a 401 (Unauthorized).

Hi.  See the "Authentication" section of the wiki you linked to before.

Link to comment
Share on other sites

PenkethBoy

Why not updae the files using Mp3Tag by adding/amending the incorrect metadata?

You can do multiple files at the same time or folders of songs at the same time etc etc

advantage is its quick and permanent - emby will update itself via RTM or the next full lib scan depending how you have it setup

Link to comment
Share on other sites

PlutoIsAPlanet
14 hours ago, ebr said:

Hi.  See the "Authentication" section of the wiki you linked to before.

Hi @ebr, thank you for the information.
I believed that as the client was already authenticated, I wouldn't have had to pass on the credentials but seeing as I was using a different HttpClient to emulate the JS code, this makes sense.

I went with the API key option, works like a treat: I'm getting a 204 and the item is refreshed.
There is one exception: The name (Title) of the song isn't getting updated but I believe this has to do with me pulling the song in with GetItemAsync, which might not be pulling in the whole object (even though I can see all of its properties). I believe @Lukehad mentioned this elsewhere, that you have to pull in the whole object.

If I use the GetAsync method on the HttpClient and modify that, I think this might update the title as well - I'll have a look when I get home.

Thank you both!

 

Link to comment
Share on other sites

PlutoIsAPlanet
53 minutes ago, PenkethBoy said:

Why not updae the files using Mp3Tag by adding/amending the incorrect metadata?

You can do multiple files at the same time or folders of songs at the same time etc etc

advantage is its quick and permanent - emby will update itself via RTM or the next full lib scan depending how you have it setup

Hi there,

I have used Mp3Tag in the past, as well as Picard but the properties which were getting overwritten were sporadic and I couldn't make out why certain ones were overwritten whilst others were left as they were.

Uploading to my Pi takes a lot of time - there's a lot of music - and if I were to replace a song with an updated version (and this was in a playlist) then it would no longer be in the playlist once overwritten. This is what I have seen until now at least - not good when your loved one has hand-picked songs and you overwrite them ;)

I was looking for a way to target specific songs and update as required, maintaining a possible playlist dependency and saving time. This works fine.

Link to comment
Share on other sites

PlutoIsAPlanet
On 9/28/2021 at 9:13 AM, PlutoIsAPlanet said:

There is one exception: The name (Title) of the song isn't getting updated but I believe this has to do with me pulling the song in with GetItemAsync, which might not be pulling in the whole object (even though I can see all of its properties). I believe @Lukehad mentioned this elsewhere, that you have to pull in the whole object.

If I use the GetAsync method on the HttpClient and modify that, I think this might update the title as well - I'll have a look when I get home.

Just to let you all know - it was an error on my part, the title was indeed getting changed.

What I in fact meant was that the Artist property wasn't getting updated but this was due to me modifying the item incorrectly.
I simply needed to add a NamedPairID to the items ArtistItems array, the rest was done automatically.

Thanks for your time!

Link to comment
Share on other sites

  • 1 month later...

@Luke

Hello Luke;

I`m not sure where should I ask this question but I write it down here, may be you can help me ;

 

I`m opening the Emby web page under the unity app (webview) and the issue I have is,

When I hide the view , the movie is keep playing in background, I want to ask if you know any javascript command that I can send to webpage to pause the video when is hided in my  unity app, and something after to play it again.

I know there is an API for play,pause,.... but I`m not familiar with integrating of API in my app, also ,I don`t know which user (user id) is playing a video , so I `m thinking about general command to video player that can pause it no mater who and what is watching.

 

Thank you very very much.

Link to comment
Share on other sites

On 11/10/2021 at 11:41 AM, HossHey said:

@Luke

Hello Luke;

I`m not sure where should I ask this question but I write it down here, may be you can help me ;

 

I`m opening the Emby web page under the unity app (webview) and the issue I have is,

When I hide the view , the movie is keep playing in background, I want to ask if you know any javascript command that I can send to webpage to pause the video when is hided in my  unity app, and something after to play it again.

I know there is an API for play,pause,.... but I`m not familiar with integrating of API in my app, also ,I don`t know which user (user id) is playing a video , so I `m thinking about general command to video player that can pause it no mater who and what is watching.

 

Thank you very very much.

maybe try something like

require(['playbackManager'], function(playbackManager){playbackManager.pause();});

 

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...