rectifyer/script.trakt — pull request #87 by nate1280 (2013-03-28 13:46:34+00:00)
Title: Rewrite sync routines.

- Complete rewrite of sync routines.
- Added setting to simulate a sync, for testing.

I've been testing this the past 2 days before submitting.

I don't know if there's any benefit over the current implementation, I didn't do any extensive testing comparing the 2. The code base is smaller overall, it maybe slightly faster in doing the comparisons for add/remove/updates, but probably not by much.

With this rewrite, I've merged movie and episode sync into 1 class, and it gets all the data up front before doing any comparisons. The data retrieved is rebuilt into like arrays, so 1 function can easily compare the 2 and find the required differences.

Of course, needs testing, and feedback would be welcome.

Sample simulated output from my log (i've removed the traktapi lines and xbmc json lines to shrink the paste a bit):

```
13:58:08 T:4348 NOTICE: [trakt] Performing a manual sync.
13:58:08 T:5008 NOTICE: [trakt] [Sync] Sync is configured to be simulated.
13:58:08 T:5008 NOTICE: [trakt] [Sync] Starting synchronization with trakt.tv
13:58:08 T:5008 NOTICE: [trakt] [Movies Sync] Getting movie data from XBMC
13:58:08 T:5008 NOTICE: [trakt] [Movies Sync] Getting movie collection from trakt.tv
13:58:09 T:5008 NOTICE: [trakt] [Movies Sync] Getting seen movies from trakt.tv
13:58:10 T:5008 NOTICE: [trakt] [Movies Sync] trakt.tv movie collection is up to date.
13:58:10 T:5008 NOTICE: [trakt] [Movies Sync] trakt.tv movie playcount is up to date
13:58:10 T:5008 NOTICE: [trakt] [Movies Sync] 1 movie(s) playcount will be updated in XBMC
13:58:10 T:5008 NOTICE: [trakt] [Movies Sync] Movies updated: Taken 2 (tt1397280)
13:58:10 T:5008 NOTICE: [trakt] [Movies Sync] [{'params': {'playcount': 1, 'movieid': 389}, 'jsonrpc': '2.0', 'method': 'VideoLibrary.SetMovieDetails', 'id': 0}]
13:58:10 T:5008 NOTICE: [trakt] [Movies Sync] 2 movie(s) will be removed from trakt.tv collection.
13:58:10 T:5008 NOTICE: [trakt] [Movies Sync] Movies removed: 300 (tt0416449), Dawn of the Dead (tt0363547)
13:58:10 T:5008 NOTICE: [trakt] [Movies Sync] {'movies': [{'plays': 1, u'tmdb_id': u'1271', u'title': u'300', u'imdb_id': u'tt0416449', u'year': 2006}, {'plays': 0, u'tmdb_id': u'924', u'title': u'Dawn of the Dead', u'imdb_id': u'tt0363547', u'year': 2004}]}
13:58:10 T:5008 NOTICE: [trakt] [Movies Sync] Movies on trakt.tv (607), movies in XBMC (605).
13:58:10 T:5008 NOTICE: [trakt] [Movies Sync] Complete.
13:58:10 T:5008 NOTICE: [trakt] [Episodes Sync] Getting show data from XBMC
13:58:10 T:5008 NOTICE: [trakt] [Episodes Sync] Getting episode data from XBMC
13:58:16 T:5008 NOTICE: [trakt] [Episodes Sync] Getting episode collection from trakt.tv
13:58:17 T:5008 NOTICE: [trakt] [Episodes Sync] Getting watched episodes from trakt.tv
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] 7 show(s) have episodes (7) to be added to your trakt.tv collection.
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] Episodes added: Body of Proof [tvdb: 167591] - S03E06, Cracked (2013) [tvdb: 260947] - S01E10, Golden Boy (2013) [tvdb: 259093] - S01E06, Justified [tvdb: 134241] - S04E12, NCIS [tvdb: 72108] - S10E19, NCIS: Los Angeles [tvdb: 95441] - S04E19, Top Gear (US) [tvdb: 199051] - S03E15
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] {'episodes': [{'season': 3, 'episode': 6}], 'tvdb_id': u'167591', 'year': 2011, 'imdb_id': u'tt1587669', 'title': u'Body of Proof'}
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] {'episodes': [{'season': 1, 'episode': 10}], 'tvdb_id': u'260947', 'year': 2013, 'imdb_id': u'tt2078576', 'title': u'Cracked (2013)'}
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] {'episodes': [{'season': 1, 'episode': 6}], 'tvdb_id': u'259093', 'year': 2013, 'imdb_id': u'tt2229167', 'title': u'Golden Boy (2013)'}
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] {'episodes': [{'season': 4, 'episode': 12}], 'tvdb_id': u'134241', 'year': 2010, 'imdb_id': u'tt1489428', 'title': u'Justified'}
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] {'episodes': [{'season': 10, 'episode': 19}], 'tvdb_id': u'72108', 'year': 2003, 'imdb_id': u'tt0364845', 'title': u'NCIS'}
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] {'episodes': [{'season': 4, 'episode': 19}], 'tvdb_id': u'95441', 'year': 2009, 'imdb_id': u'tt1378167', 'title': u'NCIS: Los Angeles'}
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] {'episodes': [{'season': 3, 'episode': 15}], 'tvdb_id': u'199051', 'year': 2010, 'imdb_id': u'tt1657260', 'title': u'Top Gear (US)'}
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] 1 show(s) shows are missing playcounts on trakt.tv
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] Episodes updated: The Bridge (2011) [tvdb: 252019] - S01E02
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] {'episodes': [{'season': 1, 'episode': 2}], 'tvdb_id': u'252019', 'year': 2011, 'imdb_id': u'tt1733785', 'title': u'The Bridge (2011)'}
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] 7 show(s) shows are missing playcounts on XBMC
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] Episodes updated: Bones [tvdb: 75682] - S08E20, Castle (2009) [tvdb: 83462] - S05E18, The Following [tvdb: 258744] - S01E10, Hawaii Five-0 [tvdb: 164541] - S03E19, Lost Girl [tvdb: 182061] - S03E10, The Mentalist [tvdb: 82459] - S05E18, The Walking Dead [tvdb: 153021] - S03E15
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] [{'params': {'playcount': 1, 'episodeid': 12662}, 'jsonrpc': '2.0', 'method': 'VideoLibrary.SetEpisodeDetails', 'id': 0}, {'params': {'playcount': 1, 'episodeid': 12663}, 'jsonrpc': '2.0', 'method': 'VideoLibrary.SetEpisodeDetails', 'id': 1}, {'params': {'playcount': 1, 'episodeid': 12676}, 'jsonrpc': '2.0', 'method': 'VideoLibrary.SetEpisodeDetails', 'id': 2}, {'params': {'playcount': 1, 'episodeid': 12671}, 'jsonrpc': '2.0', 'method': 'VideoLibrary.SetEpisodeDetails', 'id': 3}, {'params': {'playcount': 1, 'episodeid': 12673}, 'jsonrpc': '2.0', 'method': 'VideoLibrary.SetEpisodeDetails', 'id': 4}, {'params': {'playcount': 1, 'episodeid': 12658}, 'jsonrpc': '2.0', 'method': 'VideoLibrary.SetEpisodeDetails', 'id': 5}, {'params': {'playcount': 1, 'episodeid': 12667}, 'jsonrpc': '2.0', 'method': 'VideoLibrary.SetEpisodeDetails', 'id': 6}]
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] trakt.tv episode collection is clean
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] Shows on trakt.tv (223), shows in XBMC (223).
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] Episodes on trakt.tv (10505), episodes in XBMC (10512).
13:58:18 T:5008 NOTICE: [trakt] [Episodes Sync] Complete.
13:58:18 T:5008 NOTICE: [trakt] [Sync] Finished synchronization with trakt.tv
```