trakt / script.trakt

Trakt.tv movie and TV show scrobbler for Kodi
GNU General Public License v2.0
324 stars 149 forks source link

No sync via unique id #88

Closed Toddy69 closed 10 years ago

Toddy69 commented 11 years ago

I just started to use the new uniqueid feature in order to use my own order of episodes. When scrobbling, the plugin maps to the right episode on trakt.tv. When I sync my collection or watched status, the log says everything is up to date.

Some information about one of those episodes:

filename: Columbo - S13E05 - Die letzte Party.{avi, nfo} nfo-content (reduced)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<episodedetails>
    <title>Die letzte Party</title>
    <showtitle>Columbo</showtitle>
    <season>13</season>
    <episode>5</episode>
    <uniqueid>2334461</uniqueid>
</episodedetails>

These details are imported correctly. I have checked this directly in the database. The episode should map to S00E08 (Specials) on trakt.tv (http://trakt.tv/show/columbo/specials/episode/8).

While watching the episode, the scrobbling produces following log:

04:10:53 T:78260  NOTICE: [trakt] [traktPlayer] onPlayBackStarted() - {u'item': {u'type': u'episode', u'id': 2560, u'label': u'05. Die letzte Party'}}
04:10:53 T:78260  NOTICE: [trakt] checkScrobblingExclusion(): Checking exclusion settings for 'I:\Columbo\Season 13\Columbo - S13E05 - Die letzte Party.avi'
04:10:53 T:78260  NOTICE: [trakt] [traktPlayer] onPlayBackStarted() - Doing multi-part episode check.
04:10:53 T:78260  NOTICE: [trakt] [traktPlayer] onPlayBackStarted() - {u'episodedetails': {u'season': 13, u'tvshowid': 164, u'episode': 5, u'episodeid': 2560, u'label': u'Die letzte Party'}}
04:10:53 T:78260  NOTICE: [trakt] [traktPlayer] onPlayBackStarted() - {u'episodes': [{u'episode': 1, u'episodeid': 2556, u'file': u'I:\\Columbo\\Season 13\\Columbo - S13E01 - Seltsame Bettgenossen.avi', u'label': u'13x01. Strange Bedfellows'}, {u'episode': 2, u'episodeid': 2557, u'file': u'I:\\Columbo\\Season 13\\Columbo - S13E02 - Keine Spur ist sicher.avi', u'label': u'13x02. Keine Spur ist sicher'}, {u'episode': 3, u'episodeid': 2558, u'file': u'I:\\Columbo\\Season 13\\Columbo - S13E03 - Das Aschenpuzzle.avi', u'label': u'13x03. Das Aschenpuzzle'}, {u'episode': 4, u'episodeid': 2559, u'file': u'I:\\Columbo\\Season 13\\Columbo - S13E04 - Mord nach Takten.avi', u'label': u'13x04. Mord nach Takten'}, {u'episode': 5, u'episodeid': 2560, u'file': u'I:\\Columbo\\Season 13\\Columbo - S13E05 - Die letzte Party.avi', u'label': u'13x05. Die letzte Party'}], u'limits': {u'start': 0, u'total': 5, u'end': 5}}
04:10:53 T:78260  NOTICE: [trakt] [Notification] Dispatch: {'action': 'started', 'type': u'episode', 'id': 2560}
04:10:54 T:78260  NOTICE: [trakt] [Scrobbler] playbackStarted(data: {'item': {'type': u'episode', 'id': 2560}})
04:10:54 T:78260  NOTICE: [trakt] [Scrobbler] Watching: episode
04:10:55 T:78260  NOTICE: [trakt] [Scrobbler] watching()
04:10:55 T:78260  NOTICE: [trakt] [VideoLibrary.GetEpisodeDetails] {"id":1,"jsonrpc":"2.0","result":{"episodedetails":{"episode":5,"episodeid":2560,"label":"Die letzte Party","season":13,"showtitle":"Columbo","tvshowid":164,"uniqueid":{"unknown":"2334461"}}}}
04:10:55 T:78260  NOTICE: [trakt] [VideoLibrary.GetTVShowDetails] {"id":1,"jsonrpc":"2.0","result":{"tvshowdetails":{"imdbnumber":"70369","label":"Columbo","tvshowid":164,"year":0}}}
04:10:55 T:78260  NOTICE: [trakt] [traktAPI] watching(url: https://api.trakt.tv/show/watching/b6135e0f7510a44021fac8c03c36c81a17be35d9, data: {'episode': 5, 'episode_tvdb_id': u'2334461', 'progress': 19.0, 'title': u'Columbo', 'duration': 85.0, 'season': 13, 'tvdb_id': u'70369', 'year': 0})
04:10:55 T:78260  NOTICE: [trakt] [traktAPI] traktRequest(): Request data: '{"episode": 5, "episode_tvdb_id": "2334461", "progress": 19.0, "title": "Columbo", "duration": 85.0, "season": 13, "tvdb_id": "70369", "year": 0}'
04:10:55 T:78260  NOTICE: [trakt] [traktAPI] traktRequest(): Starting retry loop, maximum 5 retries.
04:10:55 T:78260  NOTICE: [trakt] [traktAPI] traktRequest(): (0) Request URL 'https://api.trakt.tv/show/watching/b6135e0f7510a44021fac8c03c36c81a17be35d9'
04:10:55 T:78260  NOTICE: [trakt] [traktAPI] __getData(): urllib2.Request(https://api.trakt.tv/show/watching/b6135e0f7510a44021fac8c03c36c81a17be35d9)
04:10:55 T:78260  NOTICE: [trakt] [traktAPI] __getData(): urllib2.urlopen()
04:11:02 T:78260  NOTICE: [trakt] [traktAPI] __getData(): response.read()
04:11:02 T:78260  NOTICE: [trakt] [traktAPI] __getData(): Response Code: 200
04:11:02 T:78260  NOTICE: [trakt] [traktAPI] __getData(): Response Time: 7239.00 ms
04:11:02 T:78260  NOTICE: [trakt] [traktAPI] __getData(): Response Headers: {'content-length': '259', 'x-powered-by': 'PHP/5.3.18-1~dotdeb.0', 'vary': 'Accept-Encoding', 'server': 'nginx/1.2.7', 'connection': 'Close', 'date': 'Fri, 29 Mar 2013 03:10:41 GMT', 'content-type': 'application/json'}
04:11:02 T:78260  NOTICE: [trakt] [traktAPI] traktRequest(): (0) JSON response: '{u'status': u'success', u'episode': {u'number': u'8', u'title': u'Columbo Likes the Nightlife'}, u'show': {u'tvdb_id': u'70369', u'year': u'1968', u'imdb_id': u'tt1466074', u'title': u'Columbo'}, u'season': u'0', u'twitter': False, u'tumblr': False, u'facebook': False, u'message': u'watching Columbo 0x08'}'
04:11:02 T:78260  NOTICE: [trakt] [traktAPI] traktRequest(): JSON request was successful.
04:11:02 T:78260  NOTICE: [trakt] [Scrobbler] Watch response: {u'status': u'success', u'episode': {u'number': u'8', u'title': u'Columbo Likes the Nightlife'}, u'show': {u'tvdb_id': u'70369', u'year': u'1968', u'imdb_id': u'tt1466074', u'title': u'Columbo'}, u'season': u'0', u'twitter': False, u'tumblr': False, u'facebook': False, u'message': u'watching Columbo 0x08'}
04:11:38 T:50220  NOTICE: Thread CFileCache start, auto delete: false

Since scrobbling works, it can be assumed, the library entry and uniqueid are correct. When syncing, the mapping via id is broken. I do not know python very well (I'm into C/C++/Java), but I could narrow it down to the function compare_show(xbmc_show, trakt_show). I have enhanced the function with further debuginformation:

def compare_show(xbmc_show, trakt_show):
    missing = []
    trakt_seasons = [x['season'] for x in trakt_show['seasons']]

    for xbmc_episode in xbmc_show['episodes']:
        Debug("[Episodes Sync] xbmc_episode: '%s'" % str(xbmc_episode))
        if xbmc_episode['season'] not in trakt_seasons:
            Debug("[Episodes Sync]   missing")
            missing.append(xbmc_episode)
        else:
            Debug("[Episodes Sync]   not missing")
            for trakt_season in trakt_show['seasons']:
                Debug("[Episodes Sync]     trakt_season: '%s'" % str(trakt_season))
                if xbmc_episode['season'] == trakt_season['season']:
                    Debug("[Episodes Sync]       first if")
                    if xbmc_episode['episode'] not in trakt_season['episodes']:
                        Debug("[Episodes Sync]       second if --> append")
                        missing.append(xbmc_episode)

    return missing

and the result is

04:31:36 T:78260  NOTICE: [trakt] [Episodes Sync] xbmc_episode: '{u'episode': 5, u'season': 13, u'episodeid': 2560, u'label': u'13x05. Die letzte Party', u'uniqueid': {u'unknown': u'2334461'}, u'playcount': 1}'
04:31:36 T:78260  NOTICE: [trakt] [Episodes Sync]   not missing
04:31:36 T:78260  NOTICE: [trakt] [Episodes Sync] xbmc_episode: '{u'episode': 1, u'season': 1, u'episodeid': 1048, u'label': u'1x01. Die Kugel der Macht (Pilot)', u'uniqueid': {u'unknown': u''}, u'playcount': 1}'

So it takes the else branch, but doesn't enter the for loop and the episode is not registered in missing. I think this method should first compare by unique id if available and by season/episode if not.

If you need a better debug log, provide a snippet with logging instruction, I will run it then.

nate1280 commented 11 years ago

Unfortunately uniqueIDs aren't used for sync, they aren't submitted to the APIs or returned from API calls when obtaining collection/watched information. Syncs are done by the shows tvdb_id, then season/episode arrays.

Only the watching/scrobble APIs use it, and even then its optional (but its used)

If that episode is S00E08, then the season should be 0 and episode 8, instead of season 13 and episode 5.

Toddy69 commented 11 years ago

Oh, ok. I thought that scrobbling, watched and collected can all be transmitted with the same attributes.