cxii-dev / script.tvtime

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

Error in post episode sync #65

Open the-lazy-fox opened 6 years ago

the-lazy-fox commented 6 years ago

Hi,

The synchronization is KO for me also but it seems a different reason. response.get('item') or response seems to be null/empty. Any ideas?

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 "/home/osmc/.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<--
detourbr commented 6 years ago

If you have this error it could mean that:

  1. response = None because onNotification function is called with data = "" which is strange
  2. response does not have the key item so response.get('item') return None and the next get fails... (see here) Could you print and paste here the content of response ?
the-lazy-fox commented 6 years ago

Hi @detourbr,

This is basically what happens at the end of the episode.

14:09:02.716 T:1112535808   DEBUG: ### [TV Time] - onNotification
14:09:02.716 T:1112535808   DEBUG: ### [TV Time] - method=VideoLibrary.OnUpdate
14:09:02.717 T:1112535808   DEBUG: ### [TV Time] - VideoLibrary.OnUpdate
14:09:02.717 T:1112535808   DEBUG: ### [TV Time] - The Response is: {u'item': {u'type': u'episode', u'id': 5149}, u'playcount': 1}
14:09:02.717 T:1112535808   DEBUG: ### [TV Time] - The Response get item is: {u'type': u'episode', u'id': 5149}
14:09:02.717 T:1112535808   DEBUG: ### [TV Time] - The Response get item get type is: episode
14:09:02.718 T:1112535808   DEBUG: ### [TV Time] - playcount=1
14:09:02.757 T:1112535808   DEBUG: ### [TV Time] - result={u'jsonrpc': u'2.0', u'id': 1, u'result': {u'episodedetails': {u'tvshowid': 33, u'episode': 18, u'season': 13, u'episodeid': 5149, u'label': u'The Dance of Love', u'uniqueid': {u'tvdb': u'6515255', u'imdb': u'tt7912274'}, u'showtitle': u'Criminal Minds'}}}
14:09:02.758 T:1112535808   DEBUG: ### [TV Time] - episode_id=6515255
14:09:02.758 T:1112535808   DEBUG: ### [TV Time] - showtitle=Criminal Minds
14:09:02.758 T:1112535808   DEBUG: ### [TV Time] - season=13
14:09:02.758 T:1112535808   DEBUG: ### [TV Time] - episode=18
14:09:02.758 T:1112535808   DEBUG: ### [TV Time] - episode_id=6515255
14:09:02.758 T:1112535808   DEBUG: ### [TV Time] - playcount=1
14:09:02.758 T:1112535808   DEBUG: ### [TV Time] - tvshowtitle=Criminal.Minds.S13E18
14:09:03.026 T:1112535808   DEBUG: ### [TV Time] - episode.is_found=True
14:09:03.026 T:1112535808   DEBUG: ### [TV Time] - MarkAsWatched(*, Criminal.Minds.S13E18, false, false)
14:09:03.338 T:1112535808   DEBUG: ### [TV Time] - checkin.is_marked:=True
14:09:03.338 T:1112535808   DEBUG: ### [TV Time] - onNotification
14:09:03.338 T:1112535808   DEBUG: ### [TV Time] - method=VideoLibrary.OnUpdate
14:09:03.338 T:1112535808   DEBUG: ### [TV Time] - VideoLibrary.OnUpdate
14:09:03.339 T:1112535808   DEBUG: ### [TV Time] - The Response is: {u'type': u'episode', u'id': 5149}
14:09:03.339 T:1112535808   DEBUG: ### [TV Time] - The Response get item is: None
14:09:03.341 T:1112535808   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 "/home/osmc/.kodi/addons/script.tvtime/default.py", line 199, in onNotification
                                                log('The Response get item get type is: %s' % response.get('item').get('type'))
                                            AttributeError: 'NoneType' object has no attribute 'get'
                                            -->End of Python script error report<--

I don't really get why it gets lost as he can find the right information the first time but not the second.

detourbr commented 6 years ago

I agree on the fact that it is strange... Sometimes you have: The Response is: {u'item': {u'type': u'episode', u'id': 5149}, u'playcount': 1} And when the error occurs: The Response is: {u'type': u'episode', u'id': 5149}

It seems that, for an unknown reason, that sometimes the response is encapsulated in a dict under the item key, and sometimes it's not... To resolve the issue you should replace this (line 106):

                response = json.loads(data) 
                log('%s' % response)
if response.get('item').get('type') == 'episode':

By something like that:

                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':

The playcount can be replaced by whatever you want (maybe 0 will mark the item as unread in TVShowtime, in that case try with 1).

the-lazy-fox commented 6 years ago

I will test!

the-lazy-fox commented 6 years ago

So yes, it's going of course through by this tricky trick but it seems that the getEpisodeTVDB function which fails after:

Code:

    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)
        if 'unknown' in result['result']['episodedetails']['uniqueid']:
            episode_id = result['result']['episodedetails']['uniqueid']['unknown']
        if 'imdb' in result['result']['episodedetails']['uniqueid']:
            episode_id = result['result']['episodedetails']['uniqueid']['imdb']
        if 'tvdb' in result['result']['episodedetails']['uniqueid']:
            episode_id = result['result']['episodedetails']['uniqueid']['tvdb']
        else:
            return False
        log('episode_id=%s' % episode_id)

        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'] = episode_id
            return item
        except:
            return False

Error:

DEBUG: ### [TV Time] - onNotification
DEBUG: ### [TV Time] - method=VideoLibrary.OnUpdate
DEBUG: ### [TV Time] - VideoLibrary.OnUpdate
DEBUG: ### [TV Time] - {u'item': {u'type': u'episode', u'id': 5844}, u'playcount': 1}
DEBUG: ### [TV Time] - playcount=1
DEBUG: ### [TV Time] - result={u'jsonrpc': u'2.0', u'id': 1, u'result': {u'episodedetails': {u'tvshowid': 68, u'episode': 6, u'season': 1, u'episodeid': 5844, u'label': u"The Queen's Husband", u'uniqueid': {u'unknown': u''}, u'showtitle': u'Victoria'}}}
ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
 - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.TypeError'>
Error Contents: 'bool' object has no attribute '__getitem__'
Traceback (most recent call last):
  File "/home/osmc/.kodi/addons/script.tvtime/default.py", line 204, in onNotification
    log('showtitle=%s' % item['showtitle'])
TypeError: 'bool' object has no attribute '__getitem__'
-->End of Python script error report<--
DEBUG: ### [TV Time] - onNotification
DEBUG: ### [TV Time] - method=VideoLibrary.OnUpdate
DEBUG: ### [TV Time] - VideoLibrary.OnUpdate
DEBUG: ### [TV Time] - {u'type': u'episode', u'id': 5844}
DEBUG: ### [TV Time] - playcount=1
DEBUG: Skin Helper Service --> Kodi_Monitor: sender xbmc - method: VideoLibrary.OnUpdate  - data: {"id":5844,"type":"episode"}
DEBUG: ### [TV Time] - result={u'jsonrpc': u'2.0', u'id': 1, u'result': {u'episodedetails': {u'tvshowid': 68, u'episode': 6, u'season': 1, u'episodeid': 5844, u'label': u"The Queen's Husband", u'uniqueid': {u'unknown': u''}, u'showtitle': u'Victoria'}}}
ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
 - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.TypeError'>
Error Contents: 'bool' object has no attribute '__getitem__'
Traceback (most recent call last):
  File "/home/osmc/.kodi/addons/script.tvtime/default.py", line 204, in onNotification
    log('showtitle=%s' % item['showtitle'])
TypeError: 'bool' object has no attribute '__getitem__'
-->End of Python script error report<--

As you can see, the unknown option is there... but empty. Is this related to the fact that for TVShow, I'm using NFO and not TVDB scrapper?

the-lazy-fox commented 6 years ago

any idea @detourbr ?