Kometa-Team / Kometa

Python script to update metadata information for items in plex as well as automatically build collections and playlists. The Wiki Documentation is linked below.
https://kometa.wiki
MIT License
2.44k stars 304 forks source link

Items sometimes missing from Tautulli builder if they exist in multiple libraries. #887

Closed CaffeineJunkie closed 1 year ago

CaffeineJunkie commented 2 years ago

Version Number

1.16.5

What branch are you on?

master

Describe the Bug

Where there are two "Show" libraries (ie. Normal and 4K) counts are aggregated together within the Tautulli dashboard. If clicking on a show within Tautulli it takes you to the 4K library then the Tautulli builder will not include that show in the server popular collection.

image image [2022-05-23 13:48:21,480] [builder.py:1892] [INFO] | | [2022-05-23 13:48:21,482] [builder.py:1893] [INFO] |========================== Adding to NotFlix Popular TV Shows Collection ===========================| [2022-05-23 13:48:21,485] [builder.py:1894] [INFO] | | [2022-05-23 13:48:21,487] [builder.py:1908] [INFO] | 1/14 | NotFlix Popular TV Shows Collection | = | Barry | [2022-05-23 13:48:21,490] [builder.py:1908] [INFO] | 2/14 | NotFlix Popular TV Shows Collection | = | Moon Knight | [2022-05-23 13:48:21,492] [builder.py:1908] [INFO] | 3/14 | NotFlix Popular TV Shows Collection | = | Star Trek: Picard | [2022-05-23 13:48:21,494] [builder.py:1908] [INFO] | 4/14 | NotFlix Popular TV Shows Collection | = | Chernobyl | [2022-05-23 13:48:21,497] [builder.py:1908] [INFO] | 5/14 | NotFlix Popular TV Shows Collection | + | Castle (2009) | [2022-05-23 13:48:21,720] [builder.py:1908] [INFO] | 6/14 | NotFlix Popular TV Shows Collection | + | Bridgerton | [2022-05-23 13:48:21,924] [builder.py:1908] [INFO] | 7/14 | NotFlix Popular TV Shows Collection | + | Last Week Tonight with John Oliver | [2022-05-23 13:48:21,962] [builder.py:1908] [INFO] | 8/14 | NotFlix Popular TV Shows Collection | + | Ozark | [2022-05-23 13:48:22,176] [builder.py:1908] [INFO] | 9/14 | NotFlix Popular TV Shows Collection | + | Peacemaker | [2022-05-23 13:48:22,409] [builder.py:1908] [INFO] | 10/14 | NotFlix Popular TV Shows Collection | + | The Blacklist | [2022-05-23 13:48:22,845] [builder.py:1908] [INFO] | 11/14 | NotFlix Popular TV Shows Collection | + | Doctor Who (2005) | [2022-05-23 13:48:23,174] [builder.py:1908] [INFO] | 12/14 | NotFlix Popular TV Shows Collection | + | Reacher | [2022-05-23 13:48:23,451] [builder.py:1908] [INFO] | 13/14 | NotFlix Popular TV Shows Collection | + | Game of Thrones | [2022-05-23 13:48:23,534] [builder.py:1908] [INFO] | 14/14 | NotFlix Popular TV Shows Collection | + | That Mitchell and Webb Look | [2022-05-23 13:48:23,725] [builder.py:1933] [INFO] | | [2022-05-23 13:48:23,728] [builder.py:1934] [INFO] | 14 Shows Processed | [2022-05-23 13:48:23,742] [builder.py:2410] [INFO] | |

Both Strange New Worlds and HALO are identifying as 4K, though both exist in both libraries and are watched in both.

Relevant Collection/Playlist Definition

NotFlix Popular TV Shows:
    template: { name: Chart, num: 1 }
    tautulli_popular:
      list_days: 60
      list_size: 20
      list_buffer: 40
      list_minimum: 2
    sync_mode: sync
    collection_order: custom
    summary: Shows Popular on NotFlix over the last 60 days

Logs

https://gist.github.com/CaffeineJunkie/00d8f607252e83879dddebfae15ad158

CaffeineJunkie commented 2 years ago

Further info: Where an item exists in two libraries (TV Shows, TV Shows 4K) whether it is picked up by the Tautulli builder depends on which library the item was viewed from last. I just played Strange New Worlds from TV Shows and this time it is picked up and populated in the collection.

chazlarson commented 2 years ago

What library is that collection running against?

CaffeineJunkie commented 2 years ago

It's building a collection in a library called "TV Shows". Both HALO and Strange New Worlds exist in both "TV Shows" and "TV Shows 4K". Tautulli combines statistics from every library of type Shows. If a show exists in both libraries it will be included in the collection if the last view was in "TV Shows" and not if the last view was in "TV Shows 4K".

chazlarson commented 2 years ago

The request from PMM to Tautulli includes a library parameter, which leads me to assume it's library-specific, so wouldn't expect watched shows from one library to show up in a request targeting another.

CaffeineJunkie commented 2 years ago

But Tautulli itself collates data by library type. Every library type of Show is grouped together. These shows should be in that category and are if the last viewing was from that library. This is repeatable behavior. Watch an episode in "TV Shows" and run PMM - TV show is included. Watch an episode in "TV Shows 4K" and run PMM - TV show is excluded.

If the last watched occurrence is in a different library it acts as if it doesn't exist in "TV Shows".

CaffeineJunkie commented 2 years ago

Also, it does not look like the request from PMM to Tautulli includes a library parameter. It does a for loop on the returned items and checks the section id. I'm now worried this is just a quirk of how this API functions in that the section id returned is dependent on the last viewing occurrence, even if some of those viewings were in a different section id.

chazlarson commented 2 years ago

You're correct that the API call doesn't include the library. That's my mistake; apologies.

I think it might be this line: https://github.com/meisnate12/Plex-Meta-Manager/blob/bddedc65c728b47174775821c8cd7b1725b88a17/modules/tautulli.py#L48

I imagine the "rating key" for the show in "TV Shows" is different to that for the show in "TV Shows - 4K", so when it gets the list back from Tautulli and walks it, the rating key from "TV Shows - 4K" is not present in "TV Shows", so it drops that item.

I haven't actually run it to confirm, this is just a guess.

meisnate12 commented 2 years ago

theres no way to get just one library's stats

im sending this {url}/api/v2?apikey={apikey}&cmd=get_home_stats&time_range={list_days}&stats_count={query_size}

which just gets the same list you see on your home screen. i then parse the items for ones in the library calling it matching on section ID. as you can see in the screenshot below it just gives me an item it wont tell me if this item is also in other libraries.

Also like chaz said im just using the rating key im being given from tautulli. Maybe a request should be made to the tautulli devs asking for stats on specific libraries

image

CaffeineJunkie commented 2 years ago

I was worried it might be a limitation from Tautulli. Wouldn’t guid be constant across libraries (assuming they use the same agent)?

chazlarson commented 2 years ago

The rating key is assigned by Plex when the item is added to the Plex library; it's not a GUID. Your rating ID for "Strange New Worlds" is different to mine, and the show has a different rating key in each library. So when I watch it in "TV Shows - 4K" Tautulli records rating key 2252051. If I ask for Tautulli play information while processing "TV Shows" it returns that rating key, which isn't present in "TV Shows". In "TV Shows" "Strange New Worlds" has rating key 2251984.

And so on.

CaffeineJunkie commented 2 years ago

Yes, but the Tautulli get_home_stats api also returns a field called guid containing data like "com.plexapp.agents.thetvdb://121361/6/1?lang=en"

Wouldn't this value be constant between libraries as it refers to a tvdb identifier?

I'll have a look at the PMM python code when I get home from work tonight, but I'll be honest. I'm a C# coder so while I can follow the logic, writing it is a different matter.

At this point I'm just throwing ideas out there. Maybe it isn't possible to match against that identifier in Plex (though it must be in plex).

Maybe it requires a slower iteration through the collection of items in a library, but then matching by guid instead of rating key could be enabled by a switch in the config file.

chazlarson commented 2 years ago

Yeah, it's in Plex:

image

For sure PMM could be modified to take that guid apart and match the TVDB ID, assuming that Plex API provides a way to hand TVDB ID to library.fetchItem(). It's only typing. ;)

I think PMM might cache the rating key -> TVDB ID lookup in its DB, so that could probably be leveraged as well.

meisnate12 commented 1 year ago

so now the tautulli call works per library so you should only get the top items from a specific library and with that im going to close this