MoojMidge / service.upnext

GNU General Public License v2.0
19 stars 5 forks source link

just played episode offered if no new episodes #14

Closed fl380 closed 1 year ago

fl380 commented 1 year ago

Thank you for resolving the previous issues which I reported with the Jellyfin addon.

If there is no new episode, the episode which has just played is then offered as the next episode. kodi.log

MoojMidge commented 1 year ago

Hmm strange. It just queries the Kodi library to get the next episode, using filter rules for path, file, and first aired date. Not sure why those wouldn't work. The only thing I can think of is that the episode firstaired dates are being updated by Jellyfin when played compared to how they are stored in the Kodi library.

I have added some additional logging to jellyfin_logging. Can you get a log showing the same thing happening when using this version?

Additionally you can check if any episodes are matched by the following smartplaylist in Kodi. This is a simplified version of what UpNext is doing. Save it as nextaired.xsp in C:\Users\Admin\AppData\Roaming\Kodi\userdata\playlists\video and open the playlist from within Kodi.

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<smartplaylist type="episodes">
    <name>nextaired</name>
    <match>all</match>
    <rule field="airdate" operator="after">
        <value>2022-12-11</value>
    </rule>
    <rule field="tvshow" operator="is">
        <value>The Simpsons</value>
    </rule>
    <limit>1</limit>
    <order direction="ascending">date</order>
</smartplaylist>
fl380 commented 1 year ago

here's the log with additional logging

Hope this help track done the issue?

MoojMidge commented 1 year ago

Hope this help track done the issue?

Unfortunately not. It just shows that something is very wrong with your Kodi video database. I'm unsure what part Jellyfin is playing in the problem but I can't replicate the problem in a normal Kodi installation.

  • opening the nextaired playlist in kodi showed S34E11
  • I then opened the nextaired playlist again but no episodes were shown

The nextaired smart playlist should never show S34E11.

The firstaired date for this episode, from your logs, is 2022-12-11, while the filter in the smart playlist is asking for an episode with a firstaired date that is after 2022-12-11.

This is essentially the same as what UpNext is doing when looking for a next episode. The fact that S34E11 is showing up in this smart playlist sometimes, but not all the time, indicates that your Kodi database is either damaged or incomplete in someway.

What is confusing is how the firstaired date is getting retrieved in the first place. It is showing up in the logs as 2022-12-11, which in a normal Kodi installation means that this data exists in the Kodi video database. However this should mean that the smart playlist and UpNext should never be matching S34E11 as the next episode.

Without understanding how Jellyfin works I can only speculate that it is intercepting and providing additional video information to normal JSONRPC queries to the Kodi video database, but this additional video information is not actually being synced to the Kodi video database until some other time.

Would suggest you create a Jellyfin bug report about this, as this appears to be a fundamental problem with how database information is being synced, rather anything specific to UpNext.

That being said, the UpNext specific issue may be able to be worked around by disabling the "Next special or season" option in UpNext settings > Behaviour > Next selection. This will mean that UpNext won't check the firstaired date for all episodes in a tvshow, it will instead restrict itself to checking for the next episode number in the current season instead.

fl380 commented 1 year ago

Thank you for trying to fix the issue.

That being said, the UpNext specific issue may be able to be worked around by disabling the "Next special or season" option in UpNext settings > Behaviour > Next selection.

I'll try this

MoojMidge commented 1 year ago

If you are interested I might be able to work around this problem in another way.

While Jellyfin appears to have some issues with the way it handles the firstaired data (the previous issue #12 had the firstaired data in a completely different format and data type than what is logged in this issue...), there also seems to be a secondary problem where the video database is storing the path and filename of the videos from your Jellyfin server in a non-standard way.

It is not just the firstaired data that is not being queried correctly, the path and file name checks are also failing to match when they should be.

If you are willing to make a copy of your Kodi video database and open it in a database editor I can send you a bit of SQL that will identify how Jellyfin is storing the path and filename of the videos on your server. I can then update UpNext to account for how Jellyfin stores the file details.

This way you can keep the "Next special or season" option enabled as it is quite a bit faster, and also allows shows with lots of special episodes to be played in proper order.

MoojMidge commented 1 year ago

Instructions if you want to give it a try:

  1. Repeat the same process you followed originally, when you "reset the watch status in Jellyfin, repaired the Kodi library and restarted Kodi"
  2. Open the nextaired playlist in Kodi and verify that it shows S34E11
  3. Close Kodi
  4. Navigate to C:\Users\Admin\AppData\Roaming\Kodi\userdata\Database and make a copy of MyVideos119.db
  5. Download and install DB Browser for SQLite from https://sqlitebrowser.org/dl/
  6. Open the copy of your video database in DB Browser for SQLite
  7. Navigate to the Execute SQL tab or press Alt + 4
  8. Paste the following SQL query into the blank tab:
    SELECT
    episode.idEpisode,
    episode.C18,
    episode.C05,
    files.strFileName,
    path.strPath
    FROM episode
    JOIN files ON files.idFile=episode.idFile
    JOIN path ON files.idPath=path.idPath
    WHERE episode.idEpisode is 1903
  9. Run the query by pressing F5
  10. Copy the five columns of data and paste it here.
fl380 commented 1 year ago

Thank you for following up.

I had to change episode.idEpisode to 1197 as I suppose repairing the library moved things around in the database, here's the query result

idEpisode: 1197 c18: NULL c05: 2022-12-11 00:00:00 strFilename: plugin://plugin.video.jellyfin/1edc4a7af308078381a44b0b243552be/?filename=The+Simpsons+-+S34E11+-+Top+Goon.mkv&id=130673296f4307edc81bc50ceff6df70&dbid=1197&mode=play strPath: plugin://plugin.video.jellyfin/1edc4a7af308078381a44b0b243552be/

MoojMidge commented 1 year ago

That explains why UpNext is not working properly. Something is not quite right with the way that Jellyfin does its database import/sync.

c18 is Null but it should be plugin://plugin.video.jellyfin/1edc4a7af308078381a44b0b243552be/?filename=The+Simpsons+-+S34E11+-+Top+Goon.mkv&id=130673296f4307edc81bc50ceff6df70&dbid=1197&mode=play

c05 is 2022-12-11 00:00:00 but it should be 2022-12-11

strFilename is plugin://plugin.video.jellyfin/1edc4a7af308078381a44b0b243552be/?filename=The+Simpsons+-+S34E11+-+Top+Goon.mkv&id=130673296f4307edc81bc50ceff6df70&dbid=1197&mode=play but it should be ?filename=The+Simpsons+-+S34E11+-+Top+Goon.mkv&id=130673296f4307edc81bc50ceff6df70&dbid=1197&mode=play

It should be possible to workaround these issues, try latest version from jellyfin_logging again and see if it works.

fl380 commented 1 year ago

Seems to have worked, thank you kodi.log