jellyfin / jellyfin-kodi

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

External SRT subtitles are only shown on the first playback of a session #541

Closed Summon528 closed 3 years ago

Summon528 commented 3 years ago

Describe the bug

External SRT subtitles are only shown on the first playback of a session. When viewing the second video, external subtitles are detected, but selecting them does not make them visible. After restarting Kodi, the subtitle works again (for the first playback)

To Reproduce

  1. Play a video in the movie menu and select an external SRT in the subtitles menu
  2. Select a different video and select an external SRT in the subtitles menu

Expected behavior

The subtitle should be visible in the second video

Logs

I see multiple ERROR <general>: CVideoPlayerSubtitle::OpenStream - Unable to create subtitle parser but no further detail

System (please complete the following information):

mcarlton00 commented 3 years ago

I'm running 19.1 on Arch and can't replicate this. I just started and stopped 3 different movies that have external srt subtitles and they all displayed fine and showed no errors in the logs.

Summon528 commented 3 years ago

Hmm weird. Do your subtitle work if you play the second movie without stopping/pausing the first one?

Kidswiss commented 3 years ago

An confirm, have the same issue with libreelec 10 beta with kodi 19.1.

Works for one episode and won't for the next. Only after a reboot.

mcarlton00 commented 3 years ago

Still can't replicate. I played episode 1 of a series that has external srt subs, it played fine. Once that played all the way through, I started episode 2 and it also played with no issues, including subtitles. I'm not sure what the issue is here, but posting full logs will probably be helpful.

Summon528 commented 3 years ago

Can you try doing this?

  1. Start playing a movie and enable subs
  2. Press ESC to go back to the library view (The movie should still be playing in the background)
  3. Start playing another movie with external subs

Seems that step 2 is the key to producing this bug

Kidswiss commented 3 years ago

For me it happens if I play the next episode via upnext. Once I've done that it's broken until a restart...

Here's a log of yesterday's test:

subtitle.log

Also I'm a bit confused about the certificate errors from urllib. My server serves valid LE certificates for the domain.

mcarlton00 commented 3 years ago

Alright, I can replicate it now. It seems if item B starts playing before item A finishes or officially "stops", we run into issues.

@Kidswiss for your urllib question, maybe check in your settings and see if you have "Verify Connection" turned on. You may have accidentally toggled it to be off, so none of your api calls are being verified.

Kidswiss commented 3 years ago

Great news! Thanks for looking into this.

About the urllib issue: the "Verify Connection" setting is enabled. So that should work. But I guess I'll open a separate issue if it bothers me too much.

mcarlton00 commented 3 years ago

So it's a race condition. What's happening is that when you hit play, the external subs are immediately downloaded here and stored at KODI_HOME/.userdata/addons/plugin.video.jellyfin/temp/Stream.eng.srt (assuming english), but when the monitor is picking up that a new playback session has started, it clears the cache. There's just enough of a delay that it's clearing the cached file that's being used at that moment.

As a temporary workaround until someone has time to work through a better solution, if you comment out these two lines it mostly solves the problem. The caveat is that if you play something that doesn't have external subs, it might try to play that cached sub file anyway.

https://github.com/jellyfin/jellyfin-kodi/blob/master/jellyfin_kodi/player.py#L428-L429

What might be the best option for dealing with this would be to name that file with the item ID instead of just a generic Stream.eng.srt, and then having the cache clearing later only remove what isn't currently playing. I don't have enough time to dig into that today, but if anybody wants to do some experimenting this will hopefully give you a good starting point.