Jump to content

API incorrectly reports number of files instead of number of movie entries as movie count


Go to solution Solved by Luke,

Recommended Posts

JohnMason1
Posted

I use the Homepage dashboard. One of its widgets uses Emby's API to display counts for Movies, TV shows etc.

It appears that Emby's API reports the number of movie files as the number of movies. This is incorrect; it should report the movie count as shown on the web/app UI. If one has multiple versions for a lot of movies (most common reason is having a 4K and an HD version as separate files), Emby's API reports each one of these as two movies instead of one, making the movie/TV show/episode count the API reports completely wrong.

Could there be a fix for this please?

JohnMason1
Posted

Hi @Luke, yes I should have provided more details.

Here is my movie count: image.png.0d07155c00887972926df6b1ef4a32e1.png

And here is what the API reports to Homepage: image.png.ed90d5753789f7c8df6030d6c03cab9a.png

Similarly for TV shows, and the total episode count.

Every time I add two movie files that are different versions of the same movie, the movie count inside Emby goes up by one (as it should), but the API movie count goes up by two.

Here is what I believe is the relevant Homepage code showing they are just getting the movie etc count numbers from the Emby API without any further processing (indicating that the counts are wrong from Emby).

Posted

The total that you see next to the play button is just for one library. What homepage is getting is for all libraries.

JohnMason1
Posted

Yes you are right, I have more movie libraries. However, the count is still wrong, as it does count multiple versions as separate movies.

Posted
15 hours ago, JohnMason1 said:

Yes you are right, I have more movie libraries. However, the count is still wrong, as it does count multiple versions as separate movies.

I don't believe this is true. I think it does accurately handle multiple versions. Can you please provide an example of why you think this isn't the case?

JohnMason1
Posted
On 16/04/2025 at 00:11, Luke said:

Can you please provide an example of why you think this isn't the case?

The first reason is because when I add up all the movies from all the 'movie'-type libraries I have the total is less than what the API reports to Homepage. The second reason is that I can see it happening live: if I add a new movie that has two versions (HD and 4K, adding both files to the directory before rescanning the library), the movie count reported to Homepage by the API goes up by two.

adminExitium
Posted

You need an example. I suggest creating a new library with just a single multi-version movie and provide the screenshots or API responses of the different counts.

JohnMason1
Posted

Is there an 'easy' way to query the API for specific libraries?

Homepage only displays the total count of movies. I have added a new movie library actually, and the counter keeps going up by two for every multi version movie I add. If someone could point out a way I could query the API specifically for the new library, I will do that, however for the developers it should be an equally, if not easier, task to check the relevant parts of the code to see if it reports it the way I describe (i.e. to try and reproduce the problem which is standard practice when a bug is reported, right?).

JohnMason1
Posted

I found out how to query the API, so here is a test.

This is a test library I have created with some movies in it:

Test_Library_Before_Adding.thumb.png.01252fa18e516e8ef373531fc938b814.png

I ran this query:

curl -X GET "https://emby-domain.com/emby/Items?IncludeItemTypes=Movie&Recursive=true" -H "X-Emby-Token: api-token"

I got this result:

Total_Movies_Before_Adding_-_API.png.7e644186a45bd53f7c27ba2bf781ee65.png

Homepage reports the same:

Total_Movies_Before_Adding_-_Homepage.png.bdf1792db12e1f78e3bc4204850698f6.png

 

I then added a movie ("The Greatest Showman") that has two versions (HD and 4K) in two separate files.

Here is the library after adding the movie:

Test_Library_After_Adding.thumb.png.bdd283a1f1549ac5ab148ba7ebc8aef8.png

Here is the API count after adding that movie (same query as before):

Total_Movies_After_Adding_-_API.png.df22685ca06e559b2aa38ca7853c2bc3.png

Homepage reports the same:

Total_Movies_After_Adding_-_Homepage.png.3e7eea6d619f81c1d0f163fae03f40dc.png

If there is any relevant log content I can provide, please do let me know.

bakes82
Posted

You just posted screen shots of correct numbers.. whats the issue.  number before 1628, added 2 files, 1630.

seanbuff
Posted
12 minutes ago, bakes82 said:

You just posted screen shots of correct numbers.. whats the issue.  number before 1628, added 2 files, 1630.

The argument being that OP only added "1" movie (2 versions of a single movie)

The Emby movie library UI shows this incrementing by only one, which is correct:

image.png.d518dfbfce521782318321c461ac0e34.png > image.png.1c5dbe95f3718deabde00827554b1bf6.png

Yet the underlying API is returning the number of "records" or "files", therefore it is incrementing by "2"

Homepage is using this endpoint to report the count of "Movies" which is somewhat misleading.

  • Like 1
JohnMason1
Posted (edited)
3 hours ago, bakes82 said:

number before 1628, added 2 files, 1630

As @seanbuffsaid, the API is meant (I believe) to count "movies" not "movie vesions" or "files". So, if I add one movie that has two versions (hence two files), the count should go up by one, not two.

Quote

Homepage is using this endpoint to report the count of "Movies" which is somewhat misleading.

Is there another endpoint that reports the movie count as opposed to the 'record' count?

Edited by JohnMason1
bakes82
Posted

Youre calling the "Items" endpoint why would that only show top level aggregates? Whos to say that number also isnt being dynamically calculated based of the items payload and just grouped via the UI code?  Did you look at the GroupItemsIntoCollections option?

seanbuff
Posted
36 minutes ago, bakes82 said:

Did you look at the GroupItemsIntoCollections option?

This has no bearing on 'versions' as that is for boxsets only.

Since the current beta server now has a filter for 'Duplicates' which when toggled, includes only movies that contain multiple "versions" (and of course legit dupes)
image.png.e8229692601a93956963b4272a89df1b.png

An appropriate API filter like 'IsDuplicate' or 'ExcludeDuplicates' should in theory return the correct result that OP is looking for, but would require an update on the Homepage side for that widget to adopt.

  • Solution
Posted
Quote

curl -X GET "https://emby-domain.com/emby/Items?IncludeItemTypes=Movie&Recursive=true" -H "X-Emby-Token: api-token"

There's a couple things going on. This is a user-less query. Based on the way the api currently works, you should use /emby/users/userid/items/xxx

This means that wherever you configure your api_key for this app, they should also have a user selection box so that all queries of this nature will be based on a user library. I realize that is inconvenient as this will require development, but that's just how the api was built way back when. It was designed so that queries could be made with and without a user id depending on context. Usually things that display will be based on a user library, and things that are background operations will not.

So why are the results so different when querying with and without a user id? This is an Emby issue however I can't give you a timeline for changing this behavior. The majority of things that use user-less queries are things that operate on files, and they don't care about things like multi-version, so this is why the results come back ungrouped. We should change this, however it will be highly disruptive for a little while due to all of the places that have written code based on the current behavior.

So therefore, the easiest short term solution is to have Homepage use user queries.

  • Like 2
JohnMason1
Posted (edited)
4 hours ago, Luke said:

you should use /emby/users/userid/items/xxx

Thank you! This works as expected (gives me a total count of 1408, which sounds about right).

Hopefully the Homepage devs can fix it on their end.

Is there an API endpoint or way to obtain the GUID needed for this endpoint (as it's not the actual user id it needs)?

Edited by JohnMason1
Posted
8 hours ago, JohnMason1 said:

Thank you! This works as expected (gives me a total count of 1408, which sounds about right).

Hopefully the Homepage devs can fix it on their end.

Is there an API endpoint or way to obtain the GUID needed for this endpoint (as it's not the actual user id it needs)?

In their config UI they should pull down the list of users. Then you select one and they can store the user id from that.

seanbuff
Posted
3 hours ago, Luke said:

In their config UI they should pull down the list of users. Then you select one and they can store the user id from that.

they don't have a config UI, it's all done via YAML, so the user will need to enter this manually.

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