nixgates / plugin.video.seren

Repository for Seren Development
311 stars 95 forks source link

[BUG] Seren 2.0 SmartPlay issues #308

Closed henryjfry closed 3 years ago

henryjfry commented 3 years ago

Seren 2.0 has issues with my Smart Play json players for tmdbhelper/wako as actionArgs is now action_args and also "smartplay" doesn't appear to be picked up in router.py

I have installed seren 2.0.0.8 and have been able to resolve the issue with the following modifications in this gist: https://gist.github.com/henryjfry/da363a29571e7c7ab143bd47d09da76f

So in router.py it will set "smart_url_arg" as True when the action is smartPlay (which it should have already been doing but didn't appear to work for me) It will also populate the action_args from action_args or actionArgs. And then it will route to the smart play via "elif action == "getSources" or action == 'smartPlay':"

In smartplay.py I had to fix the "playlist_uris" variable with some replacements which weren't being picked up correctly eg: ".replace('?action=getSources&','/?action=smartPlay&').replace('&actionArgs=','&action_args=').replace('trakt_id','trakt_show_id')" As well as additional url decoding.

And in globals.py I've added an additional "REQUEST_PARAMS" part to make sure the actionArgs are captured correctly eg: "if "actionArgs" in self.REQUEST_PARAMS:"

Once I got that working I have also found that playing the next file in the playlist will flash back to the last kodi window and then display the resolver window, which seems unnecessary and slower to resolve the next file than the old version of Seren. So I've modified the playing_next.py so that it will hide the resolver window and force the fullscreenvideo dialog to stay active:

        if control_id == 3001:
            #self.seekTime(self.getTotalTime())
            #xbmc.executebuiltin('PlayerControl(Next)')
            xbmc.executebuiltin('PlayerControl(BigSkipForward)')
            xbmc.sleep(500)
            xbmc.executebuiltin('ActivateWindow(fullscreenvideo)')
            xbmc.executebuiltin('Dialog.Close(ResolverWindow, True)')
            self.close()
            xbmc.executebuiltin('Dialog.Close(ResolverWindow, True)')
            xbmc.sleep(500)
            xbmc.executebuiltin('Dialog.Close(ResolverWindow, True)')
            xbmc.executebuiltin('ActivateWindow(fullscreenvideo)')
            xbmc.executebuiltin('Dialog.Close(ResolverWindow, True)')
            xbmc.sleep(500)
            xbmc.executebuiltin('Dialog.Close(ResolverWindow, True)')
            xbmc.executebuiltin('ActivateWindow(fullscreenvideo)')
            xbmc.executebuiltin('Dialog.Close(ResolverWindow, True)')
            xbmc.sleep(500)
            xbmc.executebuiltin('Dialog.Close(ResolverWindow, True)')
            xbmc.executebuiltin('ActivateWindow(fullscreenvideo)')
            xbmc.executebuiltin('Dialog.Close(ResolverWindow, True)')

Which is still kind of slow but at least it wont flash back to a different container in between playing files.

So would there be any benefit in the prescrape step to add the next playlist item as a resolved debrid url rather than a Seren url?

henryjfry commented 3 years ago

Further to smartPlay seemingly not working, v2.0.8 does not seem to respect "seren_reload=true" and will always load whatever items are in the cache. Its also very quick to pre-empetively terminate, which means that even if it were actually rescraping when you tell it to, it doenst pick up items it should be because it terminates too early. My settings havent changed from before and it should only terminate when it finds 5 2160p files, but it seems to be terminating with 5 of any file, so therefore not picking up the best sources.

So ive gone back to the previous version of seren for now until the initial bugs are sorted out and the previous functionality is restored.

Also not a fan of the new source select window, the old one displays more information in a more aesthetically pleasing manner.

nixgates commented 3 years ago

We have a legacy params converter in the globals module it was just missed that the smart play module would require it.

Issue should be fixed and will be available next update

nixgates commented 3 years ago

@henryjfry

Update has been released, please let me know if this fixes your issue!

henryjfry commented 3 years ago

Version 2.0.9 fixes the smart play issue, however it still doesnt appear to respect other URL settings like "seren_reload=true"

In helpers.py: def get_sources(self, action_args, overwrite_cache=None):

Overwrite_cache therefore always comes back as none for get_sources, irrespective of whether or not the url contains "seren_reload=true" and Overwrite_cache should be True?

I tried to make a modification that used get_sources2 like: def get_sources2(self, action_args, overwrite_cache=True):

But that didnt seem to work, and I couldnt figure out how to pass a correct overwrite_cache status to it.

nixgates commented 3 years ago

@henryjfry the rescrape option from the context menu uses the same url changes so Seren is definetely respecting the argument.

Perhaps it might help to throw an example url from tmdbhelper here for me to look at.

In regards to the playlist building, we no longer have seperate endpoints for each type. This is due to the playlist building in the background during playback instead of the user having to wait for it to build before playback.

Edit: sorry so this means the playlist building is fully dependent on the Seren settings.

henryjfry commented 3 years ago

I think you are right, I think it's actually a preemptive termination problem and not a rescrape problem.

I've been watching Star Trek, so Wrath of Khan and Search for Spok.

And there is 1 cached 4k rip for each of those which wasn't being returned. I changed my TV preemptive termination to be 4k rather than 5 1080p sources, and it returns the 4k option when I rescrape.

So you are right, it does appear to work, it just happens so quickly it's hard to tell.

But the preemptive termination does appear to have a problem. As I've had to scrape it twice to get the 4k sources to show up.

nixgates commented 3 years ago

@henryjfry

Ah I did look at this earlier was able to se the issue once but then completely lost it while debugging.

If you wouldn't mind letting me know your two pre-term resolutions and your maximum resolution settings.

With those I can diagnose the issue :)

henryjfry commented 3 years ago

For movies it is set to 4k and for TV it originally was set to 1080p and minimum 5 sources, under preemptive termination. Terminate on torrents only, cloud and adaptive sources disabled.

Max resolution is 4k under sort and filter.

It seems like it's stopping at 5, 1080p files for movies while it should keep looking for more 4k sources.

For now I've disabled preemptive termination.

basicals commented 3 years ago

Is smartplay working for you at all on version 2.0.9??

Choose whatever tv episode on tmdbh or tmdbh widget. "Play with" Seren smart play (with or without source select). Nothing happens.

NOTICE: [plugin.video.themoviedb.helper] lib.player - playing path with xbmc.Player() plugin://plugin.video.seren/?action=smartPlay&forceresumecheck=true&actionArgs=%7B%22episode%22%3A%203%2C%20%22item_type%22%3A%20%22episode%22%2C%20%22season%22%3A%202%2C%20%22trakt_id%22%3A%20137178%7D

henryjfry commented 3 years ago

I havent actually tried it with an episode yet, i'll check that later, im just off out to get some shopping.

henryjfry commented 3 years ago

Ok it would appear that smartplay is not working for episodes for version 2.0.9

The issue appears to be in router.py add the following on line 118 and it works:

elif action == "getSources" or action == 'smartPlay':

So the or condition to capture smartplay in addition to getsources.

edit: So ive been testing and with that change smartplay works, and will play the next episode, but only once. After that the prescrape isnt being triggered and the 3rd episode will not start automatically, the playingnext window doesnt load and it goes back to a smart play scrape screen when playback finishes.

I think something like the previous change I made in "playlist_present_check" is required. It seems like the playlisted items are being added as "getsources" and not smartplay.

henryjfry commented 3 years ago

I think I have an idea of what is happening with the smart play only playing one episode automatically, but i havent been able to resolve it myself yet.

I think the issue is in player.py with the "self._keep_alive()" function. It runs once when the player loads the first item in the playlist and this triggers the prescrape as it should and the playing next window.

However when the next file starts playing, there is no "onPlaybackStarted" in the player.py file, nor any other way to retrigger the _keep_alive() function once it has finished. Therefore the prescrape doesnt run for the next item in the playlist.

Im trying to get the keep_alive function to start again but no joy yet.

henryjfry commented 3 years ago

Ok I think I have found a fix, it seems that _keep_alive is triggered when the 1st playlist item is loaded but it then determines that there is no playing file and returns "_is_file_playing" as false. Adding in a delay in _playback_has_stopped to wait to see if a file is resolved first seems to work:

 def _playback_has_stopped(self):
        count = 0
        while xbmc.Player().isPlaying()==1 and count < 7501:
            try:
                resume_position = xbmc.Player().getTime()
            except:
                resume_position = ''
            if resume_position <> '':
                if resume_position > 0:
                    self.playback_ended = False
                    self.playback_error = False
                    self.playback_stopped = False
                    return self.playback_stopped or self.playback_error or self.playback_ended
            else:
                xbmc.sleep(100)
                count = count + 100
        return self.playback_stopped or self.playback_error or self.playback_ended
nixgates commented 3 years ago

@henryjfry each playback request needs to start it's own keep alive. Re-using the same class for each playback will cause more issues.

Can you confirm for me if the issue is present when playing not using TMDB helper?

henryjfry commented 3 years ago

Ok so ive reinstalled version 2.0.9 so it doesnt have any extraneous modifications and reapplied the following:

/plugin.video.seren/resources/lib/modules/router.py elif action == "getSources" or action == "smartPlay":

/plugin.video.seren/resources/lib/modules/player.py

    def _playback_has_stopped(self):
        count = 0
        while xbmc.Player().isPlaying()==1 and count < 7501:
            try:
                resume_position = xbmc.Player().getTime()
            except:
                resume_position = ''
            if resume_position <> '':
                if resume_position > 0:
                    self.playback_ended = False
                    self.playback_error = False
                    self.playback_stopped = False
                    return self.playback_stopped or self.playback_error or self.playback_ended
            else:
                xbmc.sleep(100)
                count = count + 100
        return self.playback_stopped or self.playback_error or self.playback_ended

And playing via tmdbhelper, smart play now works correctly.

I then went into seren and played the same few episodes and smart play is still working So I'm pretty confident that putting a delay in "_playback_has_stopped" so that when it restarts the keep alive it isnt automatically closing it before the file actually has a chance to start.

My previous comments about restarting the keep_alive, I thought it wasnt starting again for each new file which plays, but when I tracked the code execution I found it was starting but then stopping immediately because it was checking the file before it had actually started playing and then exiting.

henryjfry commented 3 years ago

Just FYI I did get an error when I manually went searching for the show in seren with the resumeshow(). This show is something ive been re-watching on Trakt but isn't in my collection, I had to "Browse Show" before it wouldnt give an error:

` 2021-01-05 10:31:00.037 T:2358530272 ERROR: SEREN: Failed to receive JSON from Trakt response - response: <Response [401]> - error - No JSON object could be decoded 2021-01-05 10:31:00.085 T:2358530272 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--

`

My Trakt account is logged in, in Seren. And I have my own Trakt script which can play the next episode after the last episode watched on Trakt so I know that the episodes have been scrobbled to Trakt correctly. However it is fully watched on Trakt so that could be why it cant find the resume point? If thats why it comes back with an exception (its fully watched, therefore no resume point) then it should probably default to "Browse Season"?

nixgates commented 3 years ago

@henryjfry ok I've been able to recreate the issue and I've got a fix ready that's in the next update. Will be pushing one today so not long.

nixgates commented 3 years ago

@henryjfry update is now released, could you please check and confirm with 2.0.10

henryjfry commented 3 years ago

Ok I can confirm that the smart play, next up screen and prescrape now works for multiple episodes on version 2.0.10.

However I still needed to add:

/plugin.video.seren/resources/lib/modules/router.py elif action == "getSources" or action == "smartPlay":

Before the smartplay url would actually play.

Navios92 commented 3 years ago

@henryjfry If this is completely fixed, is there any chance you could update OpenPlayers?

henryjfry commented 3 years ago

@henryjfry If this is completely fixed, is there any chance you could update OpenPlayers?

Its not a json player fix, purely seren.

nixgates commented 3 years ago

@henryjfry the smart play option in tmdb helper, is that the episode resume from show option?

Otherwise, I think the smart play was the old playlist building method which is no longer present in 2.0, hence the dead player.

That won't be fixed if it's the case and should be updated to reflect that on the TMDB player files :)

nixgates commented 3 years ago

Closing this issue off as the issue is fixed :)

henryjfry commented 3 years ago

@henryjfry the smart play option in tmdb helper, is that the episode resume from show option?

Otherwise, I think the smart play was the old playlist building method which is no longer present in 2.0, hence the dead player.

That won't be fixed if it's the case and should be updated to reflect that on the TMDB player files :)

Ok thats fair enough, ill probably apply a manual fix in seren myself as its the Wako players which are difficult to update (they seem to be extremely cagey with their pastebin/bitly link for the player files).

The smart play option im referring to from tmdbhelper is:

"plugin://plugin.video.seren/?action=smartPlay&actionArgs=%7B%22episode%22%3A%20{episode}%2C%20%22item_type%22%3A%20%22episode%22%2C%20%22season%22%3A%20{season}%2C%20%22trakt_id%22%3A%20{trakt}%7D"

So no resume, just smartPlay. But if you want to close it thats fine.

The resume error was when I manually searched for the show in seren and I tried to click on the show it was trying to get the episode resume point, which I think caused an exception as its fully watched in Trakt and therefore may not return a resumepoint. I think the trakt api just returns a null value for next episode when you query a fully watched show. I've got a script which iterates the show history until it gets to a last played date earlier than the preceding date and takes that to be the next episode to watch for a rewatched show.

nixgates commented 3 years ago

@henryjfry did find a bug with auto episode resume today but should be fixed by next update :)