Friday, July 21, 2017

Netflix to Trakt.tv Sync

There used to be a nice Chrome plugin to synchronize by Netflix history with Trakt.tv but it had been unreliable and doesn't seam to be working now.  I wrote this code to solve my own need but it does the same thing and I am posting it here for others to use.

Note that this is not 100% perfect as some show names aren't exactly the same and some Netflix show's don't use episode names at all. This code it not using any Netflix API calls but rather just scraping your Viewing Activity page and then making API calls to your Trakt.tv account to post the item's it finds.

You may need to manually select some episodes or shows on the Tract.tv side if they aren't matched and it is possible that duplicates could get synced if the names cause issues though I tried to prevent this. In short I'm not out to make this 100% perfect but it should get you 90% of the way and it shows all the changes it will post for confirmation before posting.

Usage

  • Drag this link, Sync to Trakt.tv, to your bookmark bar or bookmerks menu.
    • This is a bit of Javascript that will inject the Sync tool into your Netflix activity page.
  • Open Netflix in your browser and log in.
    • This is tested and working in Safari and Chrome.
  • Go here https://www.netflix.com/viewingactivity to see your history or click on your name in the top right, then on Account, and finally on Viewing Activity.
  • Netflix will not load your entire history so you will need to scroll down to get it to load more.  Keep doing this until all the history you want to sync has been loaded.
    • You don't have to do everything, if you are doing this regularly then the first screen or two will be sufficient.
  • Now for the magic click the bookmarklet you added while looking at the history page.
    • Note: The first tim you do this you will need to log in to Trakt.tv and click the bookmark again.
  • The script will scrape the Netflix page, they check each item in Trakt.tv and build a list of already synced items, items not found, and items scheduled to sync.
    • If re-running the tool past plays will be greyed out, new plays to by synced will be green,  items that could not be cached will remain white, and duplicate plays that are being ignored will be orange.
  • When you are satisfied just click Sync Now to post the changes.  You can then check Trakt.tv or reload the page and run the script again to see the results.

How It Works

This solution is a simple bit of javascript that scans your Netflix history page and sync's plays over to Trakt.tv. It also needs to read your list of past plays in Trakt.tv along with the history it reads from the Netflix page.

None of this data is saved or sent to any other servers in any way. As the script runs a listing of all the changes that will be posted to Trakt.tv is show with a confirmation option. No passwords or logins are prompted or recorded in any way. You are logging in yourself to Netflix and Trakt.tv, though you do have to grant this application API access to your account. The only bit that is saved is the Trakt.tv access token so that you don't have to log in on every use of the tool. You can even remove this by clearing the cookies for the www.netflix.com domain.

You can view the entire script here first if you wish. The bookmarklet code is an easy way to inject this code into your netflix page, you could also run this code manually in your browser console.

function load(filename){
 if(filename.endsWith('.js')){
  var fileref=document.createElement('script');
  fileref.setAttribute('type','text/javascript');
  fileref.setAttribute('src',filename);
 }
 else if (filename.endsWith('.css')){
  var fileref=document.createElement('link');
  fileref.setAttribute('rel','stylesheet');
  fileref.setAttribute('type','text/css');
  fileref.setAttribute('href',filename);
 }
 document.getElementsByTagName('head')[0].appendChild(fileref);
}
load('https://code.jquery.com/ui/1.12.1/jquery-ui.js', 'js');
load('https://www.inkonit.com/netflix/netflix-sync.js','js');
load('https://www.inkonit.com/netflix/netflix-sync.css','css');

5 comments:

Odin Hauge Mo said...

Thank you so much for making this!

But, I'm not able to use it. It won't scan titles that's not available in my region. It just gives me this error:

[Error] TypeError: null is not an object (evaluating 'title.replace')
clean_title (netflix-sync.js:116)
(anonymous function) (netflix-sync.js:309)
filter
(anonymous function) (netflix-sync.js:308)
c (none:2:5841)
add (none:2:6143)
(anonymous function) (netflix-sync.js:293)
c (none:2:5841)
add (none:2:6143)
(anonymous function) (netflix-sync.js:275)
each (none:1:57534)
each (none:1:55386)
do_sync (netflix-sync.js:254)
(anonymous function) (netflix-sync.js:239)
c (none:2:5841)
fireWith (none:2:6649)
n (none:3:20507)
t (none:3:26832)

If I remove that title from the activity history, I get this error on another title (which is also not available in my region):

[Error] TypeError: undefined is not an object (evaluating 'data[0].show')
ajax (none:3:23126)
(anonymous function) (none:3:23402)
(anonymous function) (netflix-sync.js:268)
each (none:1:57534)
each (none:1:55386)
do_sync (netflix-sync.js:254)
(anonymous function) (netflix-sync.js:239)
c (none:2:5841)
fireWith (none:2:6649)
n (none:3:20507)
t (none:3:26832)

Unknown said...

Mine gets stuck at the red circle going around and around forever. I let it run for almost 24 hours and it never synced.

Odin Hauge Mo said...

You should check the chrome console, if there's any useful error messages. Right click the page > Inspect > Console.

Ryan Casler said...

Failed to load resource: the server responded with a status of 404 ()

Failed to load resource: net::ERR_BLOCKED_BY_CLIENT
none:3 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

Odin Hauge Mo said...

That most likely means you are using adblock, and it's blocking something on the page. It that the only thing you see in the console? Run the netflix-sync script, while you have the console open. You can see at the right side of the console, which process that's reporting the entry. It should be 'netflix-sync-js'.