Jump to content

Can't find a way to get ProviderIds


Recommended Posts

smallfrenchy
Posted

I am new to Emby SDK, and I am trying to get a simple list of movies with some infos. Here's my code:

public MediaIndexResponse Get(GetMediaIndex request)
        {
            var query = new InternalItemsQuery
            {
                IncludeItemTypes = new[] { "Movie" },
                IsVirtualItem = false,
                Recursive = true
            };

            var movies = _libraryManager.GetItemList(query);

            var mediaList = movies.Select(movie =>
            {
                
                var fullItem = _itemRepository.GetItemByGuid(movie.Id) as Movie;

                if (fullItem == null)
                    return null;
                
                return new
                {
                    Id = fullItem.Id,
                    Name = fullItem.Name,
                    OriginalTitle = fullItem.OriginalTitle ?? fullItem.Name,
                    ProviderIds = fullItem.ProviderIds, 
                    ProductionYear = fullItem.ProductionYear,
                    MediaStreams = fullItem.GetMediaStreams()?.Select(m => new
                    {
                        Type = m.Type.ToString(),
                        Codec = m.Codec,
                        Language = m.Language,
                        BitRate = m.BitRate
                    }).ToList(),
                };
            }).Where(x => x != null).ToList();

            return new MediaIndexResponse { Items = mediaList };
        }

My problem is ProviderIds in the object I am creating is always emtpy, wathever I did. Can someone explain how to get it?

Regards

mickle026
Posted

looks to me like you are getting an array type back from the movie query.

this will be a tuple type, and will need expanding out of the tuple.

 ProviderIds = fullItem.ProviderIds, 

The provider ids can be queried for each movie id

string IMDB = movie.GetProviderId(MetadataProviders.Imdb);

or
  
  
movie.ProviderIds.TryGetValue("Imdb", out id);


 

 

smallfrenchy
Posted (edited)

Hi,

 

thanks for reply. I try both, but both return null. When I use the Emby API (by using Fields in query), I got it, but via Emby SDK, no way to get these values. I really don't understand why.

Edited by smallfrenchy
Posted
22 hours ago, smallfrenchy said:

Hi,

 

thanks for reply. I try both, but both return null. When I use the Emby API (by using Fields in query), I got it, but via Emby SDK, no way to get these values. I really don't understand why.

var allEpisodes = _libraryManager.GetItemList(new InternalItemsQuery
                                                          {
                                                              IsVirtualItem = false,
                                                              Recursive     = true,
                                                              IncludeItemTypes = new[]
                                                                  {
                                                                      nameof(Episode)
                                                                  }
                                                          })
                                             .OfType<Episode>()
                                             .ToList();

matchedEpisode =
                            allEpisodes.FirstOrDefault(episode => episode.ParentIndexNumber == introData.Season  &&
                                                                  episode.IndexNumber       == introData.Episode &&
                                                                  // Match at least one provider ID
                                                                  introData.ProviderIds.Any(providerPair =>
                                                                      episode.ProviderIds
                                                                             .TryGetValue(providerPair.Key,
                                                                              out var value) &&
                                                                      value.Equals(providerPair.Value,
                                                                       StringComparison
                                                                           .OrdinalIgnoreCase)));

Works fine for me.

smallfrenchy
Posted

Hmm, I have'nt find a way to do it. What I don't understand is even with these simple sample, I have a strange result:

        public MediaIndexResponse Get(GetMediaIndex request)
        {
            var movies = _libraryManager.GetItemList(new InternalItemsQuery
                {
                    IsVirtualItem = false,
                    Recursive     = true,
                    IncludeItemTypes = new[]
                    {
                        nameof(Movie)
                    }
                })
                .OfType<Movie>()
                .ToList();


            
            return new MediaIndexResponse { Items = movies };
        }

This code give me a JSON response like this:

{
    "Items": [
        {
            "IsNameParsedFromFolder": false,
            "DateCreated": "2024-09-10T22:24:57.0000000Z"
        }
    ]
}

Even if I have all meta data of the only movie I have in my collection. Is that normal?

bakes82
Posted

IDK what the question is, but youre not going to see the providers in the json as I dont believe they are marked to be exposed so you would need to create a new dto if youre expecting to see them.

smallfrenchy
Posted

I just expect to have all infos regarding movies including ProviderIds

bakes82
Posted

And you probably do but its not going to write it to JSON using the base entities, you would need to create new ones like I said above, at this point your issues are just youre a novice and not really related to the SDK.

smallfrenchy
Posted

Yes for sure, I am new to the SDK :) So you mean I need to create a new Movie objcet from the base entities? .OfType<Movie>().ToList(); doesn't do this job?

bakes82
Posted

If you want to see them in JSON then yes, if you look at any of the bases you can see they ignore multiple fields, the ignored field wont get serialized. Otherwise they exist and are usable via code.

Heres a quick look at episode most of the fields are ignored and wont be serialized.
image.png.018302343f81ce2554449093004c04ea.png

smallfrenchy
Posted

Ok, so I now create a new object (crappy way, I know) for each BAseItem like this:

public MediaIndexResponse Get(GetMediaIndex request)
        {
            var movies = _libraryManager.GetItemList(new InternalItemsQuery
                {
                    IsVirtualItem = false,
                    Recursive     = true,
                    IncludeItemTypes = new[]
                    {
                        nameof(Movie)
                    }
                })
                .OfType<Movie>()
                .ToList();
            
            return new MediaIndexResponse { Items = movies.Select(m => new 
            {
                Id = m.Id,
                OriginalTitle = m.OriginalTitle,
                Name = m.Name,
                Genres = m.Genres.Select(g => g),
                ProviderIds = m.ProviderIds.Select(p => p.Value),
                MediaStreams = m.MediaStreams?.Select(s => new { Codec = s.Codec, Type = s.Type })
            }) };
        }

So I have some properties, but not everything works, here's what I have as output:

{
    "Items": [
        {
            "Id": "e6e0de3eabf0d5d74e7227fbd3eef61d",
            "Name": "Alpha Dog",
            "Genres": [],
            "ProviderIds": []
        }
    ]
}

OriginalTitle, Name, Genres, ProviderIds and MediaStreams are either null or empty. And I don't see why :)

 

bakes82
Posted

Then I would assume your items dont have those things set, or whatever the return of MediaIndexResponse is doing something else because if you just use the logger and json serializer you can get the items to return when you use a new object
My test works fine:

2025-03-03 04:26:26.531 Debug SqliteItemRepository: GetitemById Season 197 Season 1
2025-03-03 04:26:26.533 Info Miscellaneous Utilities: {
    "Genres": [
        "Test"
    ],
    "GenresString": "Test"
}
2025-03-03 04:26:26.535 Info Miscellaneous Utilities: {
    "Genres2": [
        "Test"
    ]
}
var mediaItems = _libraryManager.GetItemList(query)
                                        .OfType<Episode>()
                                        .ToList();
        _logger.Info(_jsonSerializer.SerializeToString(mediaItems, new JsonSerializerOptions{Indent = true}));

        foreach (var mediaItem in mediaItems)
        {
            var t = new newEpisode
                    {
                        SortIndexNumber = mediaItem.SortIndexNumber,
                        Genres          = mediaItem.Genres,
                        GenresString = string.Join(", ", mediaItem.Genres.Select(x => x.ToString())),
                    };
            _logger.Info(_jsonSerializer.SerializeToString(t, new JsonSerializerOptions
                                                              {
                                                                  Indent = true
                                                              }));
            
            _logger.Info(_jsonSerializer.SerializeToString(new {Genres2 = mediaItem.Genres}, new JsonSerializerOptions
                                                              {
                                                                  Indent = true
                                                              }));
        }

image.png.b4784e88c6f0f66a025c6f44eb2e19e9.png

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...