jellyfin / jellyfin-kodi

Jellyfin Plugin for Kodi
https://jellyfin.org
GNU General Public License v3.0
785 stars 105 forks source link

Jellyfin-Kodi resets "watched" status after 3-5 seconds when using External Player. #571

Open WybeBosch opened 2 years ago

WybeBosch commented 2 years ago

Describe the bug Jellyfin marks watched items as "unwatched" a few seconds after being marked as "watched" (But only after they have been marked as watched by finishing a playback using an ExternalPlayer.)

To Reproduce

Expected behavior

Logs https://drive.google.com/drive/folders/1QLiBYFdTsrTbPQhGmRs_GdfJhOk6Nbnh?usp=sharing This a drive folder with two kodi logs in it.

(Theres also a subfolder, that has the same logs but with some log spam removed for easier reading)

System (please complete the following information):

Additional context The episode being watched is "Veronica Mars" , and the keyword to search for in the files are the words "as watched" as that will lead you to the logline where the episode is marked as watched, and slightly after that you can see Jellyfin passing information causing thing to go wrong and resetting the watched status.

Using the below "playercorefactory.xml" inside "C:\Users\DEBUGUSER\AppData\Roaming\Kodi\userdata" Currently the time you need to spend inside the "external player" is set to 30 seconds, after that Kodi will mark an item as watched. (this is in seconds, its low for debugging purposes, normal would be maybe 15 minutes or something) This works great, it marks the item as watched but a few seconds after that Jellyfin for Kodi Unwatches it.

<playercorefactory>
    <players>
        <player name="MPC-HC" type="ExternalPlayer" audio="false" video="true">
            <filename>C:\Program Files\MPC-HC\mpc-hc64.exe</filename>
            <args>"{1}" /fullscreen /close</args>
            <hidexbmc>false</hidexbmc>
            <hideconsole>false</hideconsole>
            <warpcursor>none</warpcursor>
            <playcountminimumtime>30</playcountminimumtime>
        </player>
    </players>
    <rules action="prepend">
        <rule filetypes="mkv|avi|divx|ogm|mp4|mov|m4v|flv|m2v|mpeg|mpg|mts|m2ts|vob|bdmv|iso" player="MPC-HC">
        <rule protocols="http|https" player="MPC-HC"/>
        <rule protocols="daap|rtv|rtsp|rtmp|rtmpe|rtsp|mms|rtp|pvr" player="VideoPlayer"/>
        </rule>
    </rules>
</playercorefactory>

Hopefully there's just an extra If statement needed somewhere, since it seems to be working correctly using the internal player. Also I double checked, the issue doesn't occur if Jellyfin for Kodi is disabled,

mcarlton00 commented 2 years ago

The only code I see from a glance is that if Kodi is using an external player then it won't report playback at all.

https://github.com/jellyfin/jellyfin-kodi/blob/0fb103852af4d3c15d812cf75d304189ad8c4063/jellyfin_kodi/player.py#L310-L323

To be honest, I'm not sure when this will be looked at. It's an incredibly niche thing and as far as I'm aware has little to no benefit when paired with Jellyfin, so there's a good chance it might sit for a while until somebody feels like digging. It sounds like a race condition of some kind, but I can't imagine where it's coming from.

WybeBosch commented 2 years ago

Hmm perhaps the solution for the problem isnt proper support for External Players (since its so niche) but rather an option to disable "watched status" sync between "Jellyfin for Kodi" and Jellyfin?

(I didnt even know it was a thing btw, i thought the recommended way was to use external addons such as installing Trakt on both Kodi and Jellyfin to sync watched status was the way to go.

Even the option to disable the watched status sync is probably quite a bit of work, Perhaps you could point me in the right direction on what lines i could comment/delete to just "break" the watched sync on only my Kodi install (which would reset if i update "Jellyfin for Kodi" but thats fine)

On my local install Is deleting player.py an option? Or making its queries return Null or something?

mcarlton00 commented 2 years ago

Disabling the watched status between Kodi and Jellyfin defeats most of the purpose of the addon. Jellyfin for Kodi is designed to stay in sync with the upstream Jellyfin server for all media. This means metadata, watched status, in progress media, etc. It doesn't need any other addons to accomplish any of that, and honestly seems to work best if it's the only addon installed. There's genuinely no reason to have Trakt running on both Kodi and Jellyfin, and imo it's highly likely that it's the root of your problem and toggling watched status when it shouldn't be. The Trakt plugin in the server receives updates from all clients and updates your Trakt account from there. Having it try to do the same thing in multiple places doesn't make sense. Why it's an issue on the external player and not the internal player, I couldn't tell you, but right now you're 3 for 3 out of things that nobody on the dev team uses. Going to make it hard to track down (if it's actually a bug).

WybeBosch commented 2 years ago

Ah i understand, i mostly used Jellyfin for Kodi to inject the library into Kodi (Not really to keep watched status / progress synced), and i like the native way because that way if my Jellyfin server is turned off i still have acces to the files. (Plus it seemed closer to the normal way kodi works)

I checked out the issue aswell with all trakt addon things disabled (in both jellyfin and in kodi) it it still happened.

The main "culprit" i think is the fact that i use an external player, not native mode or trakt. Using an external player indeed do things differently, because it cant return info. So kodi just checks "have you been in the external app for x amount of seconds" if so, then things get marked as watched.

I understand if the issue has very low priority, but who knows maybe someday someone will have time to look into it. (Or if other people run into the same Niche issue i have)

In the meantime perhaps il check out "Addon" mode :)

SoSJames commented 1 year ago

Although I'm sure this would bring the issue no closer to a resolution, I can confirm this issue is present without Trakt or native mode enabled. I see the same behavior with the Jellyfin Kodi plugin operating in addon mode, with multiple different external player options (MPV, MPC-HC, VLC). It seems like the plugin gets the signal from KODI that a library item opened in an external player and passes the play time threshold to be marked watched, but when the plugin goes to report that back to the Jellyfin server, it reverts the status. I have also occasionally seen this result in an episode or movie showing as partially watched in the Jellyfin web interface after this happens in KODI.

SoSJames commented 1 year ago

As a follow up - it looks like this issue dates back to at least to late 2017 in the original Emby Kodi plugin as referenced here: https://github.com/MediaBrowser/plugin.video.emby/pull/112 It also appears to me that they found some kind of workaround/solution that may not have made it into the Jellyfin codebase when it split off from Emby. Perhaps the answer is somewhere in the above referenced issue.