cxii-dev / script.tvtime

Kodi add-on for TV Time
GNU General Public License v2.0
36 stars 29 forks source link

Synchronisation broken #64

Open detourbr opened 6 years ago

detourbr commented 6 years ago

Since a few months the synchronisation between Kodi and TVShow Time was broken for an unkown reason. After a quick look at the log file (/home/osmc/.kodi/temp/kodi.log) I find out the following message when a new episode was checked :

17:35:41.397 T:1703809792   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.KeyError'>
                                            Error Contents: ('unknown',)
                                            Traceback (most recent call last):
                                              File "/home/osmc/.kodi/addons/script.tvshowtime/default.py", line 202, in onNotification
                                                item = self.getEpisodeTVDB(xbmc_id)
                                              File "/home/osmc/.kodi/addons/script.tvshowtime/default.py", line 270, in getEpisodeTVDB
                                                log('episode_id=%s' % result['result']['episodedetails']['uniqueid']['unknown'])
                                            KeyError: ('unknown',)
                                            -->End of Python script error report<--

After a quick look at the /home/osmc/.kodi/addons/script.tvshowtime/default.py file I found the following strange lines :

def getEpisodeTVDB(self, xbmc_id):
        rpccmd = {'jsonrpc': '2.0', 'method': 'VideoLibrary.GetEpisodeDetails', 'params': {"episodeid": int(xbmc_id), 'properties': ['season', 'episode', 'tvshowid', 'showtitle', 'uniqueid']}, 'id': 1}
        rpccmd = json.dumps(rpccmd)
        result = xbmc.executeJSONRPC(rpccmd)
        result = json.loads(result)        
        log('result=%s' % result)    
        log('episode_id=%s' % result['result']['episodedetails']['uniqueid']['unknown'])

        try:
            item = {}
            item['season'] = result['result']['episodedetails']['season']
            item['tvshowid'] = result['result']['episodedetails']['tvshowid']
            item['episode'] = result['result']['episodedetails']['episode']
            item['showtitle'] = result['result']['episodedetails']['showtitle']
            item['episode_id'] = result['result']['episodedetails']['uniqueid']['unknown']
            return item
        except:
return False

The strange part was the "unkown" parameter. I don't know why it was written this way at first but anyway, the result object have the following structure : result={u'jsonrpc': u'2.0', u'id': 1, u'result': {u'episodedetails': {u'tvshowid': 51, u'episode': 8, u'season': 3, u'episodeid': 3486, u'label': u'Les souvenirs effac\xe9s de Morty', u'uniqueid': {u'tvdb': u'6288260', u'imdb': u'tt5218350'}, u'showtitle': u'Rick et Morty'}}}

As we can see the 'unique_id' sub-dictionary have two values ('tvdb' and 'imdb') but no 'unkwon' key...

To fix my issue I just changed the result['result']['episodedetails']['uniqueid']['unknown'] by result['result']['episodedetails']['uniqueid']['tvdb'] in the upper function (lines 269 and 277).

And now it works !

Not sure if this 'unknown' key is a bug for everybody or just some happy few, but it's been a long time I've been looking for a fix (probably since the last TVShow time plugin update).

Serpe-Verde commented 6 years ago

Finally someone thought about it. It works properly. I am grateful for this simple solution to the problem.

Bruno

the-lazy-fox commented 6 years ago

Hi,

Yes line 269 and 277 updates might fix it. Thanks for checking that. You could also replace unknown by imdb. Did you try?

What we don't know is the purpose of this "unknown" parameter, it seems like a not achieved work from the author. May be he wanted to let the user the ability to choose from a menu settings? It would be better if we can check TVDB first and if empty, IMDb.

detourbr commented 6 years ago

I didn't try so far with IMDB. The fact that the code include that "unknown" parameter made be believe that there was a purpose or something like that... But if it's proven that the issue applies to all users I'll try to improve this fix and send a pull request

the-lazy-fox commented 6 years ago

Great thank you.

the-lazy-fox commented 6 years ago

https://github.com/cxii-dev/script.tvtime/pull/59

eraser-head commented 6 years ago

oh my god, it works!!! after years searching a fix and now is scrobbling perfectly, thanks men!

ahmed2m commented 6 years ago

My problem was it was just saying successful but nothing is synced i edited the mentioned lines and still nothing works here is my log https://pastebin.com/raw/cQWRgSs5

eraser-head commented 6 years ago

anyone is getting a 33804 error trying loggin?

EienFr commented 5 years ago

Changing lines, saying successful but nothing is synced:

14:41:13.984 T:158101030128   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.AttributeError'>
                                            Error Contents: 'NoneType' object has no attribute 'get'
                                            Traceback (most recent call last):
                                              File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.tvshowtime/default.py", line 198, in onNotification
                                                if response.get('item').get('type') == 'episode':
                                            AttributeError: 'NoneType' object has no attribute 'get'
                                            -->End of Python script error report<--
EienFr commented 5 years ago

Changing line 106 with lines below solve the problem: response = json.loads(data) log('%s' % response) if not 'item' in response : response = {u'item':response, u'playcount': 0} if response.get('item').get('type') == 'episode':

EienFr commented 5 years ago

Strange thing. On TV Time it's sync but not marked as watched

detourbr commented 5 years ago

The new TV Showtime take time to display changes... Probably some new "optimization" feature. So it's synchronizing but you need to be patient! The only bug I actually found with the new app concerns shows not watched in a while (progression is updated but it doesn't appears as recently watched on TVshow time Android widget)

EienFr commented 5 years ago

Hi detoubr

I forgot to reply to the thread with the fact that indeed it take time to display an episode as watched.

the-lazy-fox commented 5 years ago

Feel free to post the change in my fork, I will then publish a new release. Thanks.