Netflix Autoplay Bookmarklet – With Multiple Season Support!

Not content to leave well enough alone, I was hacking on my bookmarklet some more. It can now handle crossing between seasons. There is also a bit less guessing going on now, so I am more confident in it.

For the record, I want to say, I hope Netflix does not get upset about this, if they want me to remove it I will.

To use this:
1. Drag the link below on to your bookmarks bar.
2. Start watching a TV show on Netflix.
3. Click the bookmark and enter then number of episodes you want to watch.

Note: I have now tested this in IE. It does NOT work. But you wouldn’t use IE anyway, would you?

Netflix Autoplay Bookmarklet - With Multiple Season Support!
javascript:(function(netflix, undefined) {
	var seasonId = 0,
	episodeId = 0,
	numWatched = 0,	
	numToWatch = 3,
	epIdRegex = /,EpisodeMovieId=\d*,/,
	idregx = /\d+/,
	done = false,
	sl,
	init,
	currrentEpisodeId,
	currentMovieId,
	seasons,
	showData,		
	waitTimer,
	node;	

	if(!netflix || !netflix.Silverlight || !netflix.Silverlight.MoviePlayer || !netflix.Silverlight.MoviePlayer.getPlugin() || !netflix.Silverlight.MoviePlayer.getPlugin().settings.initParams) {
		alert('You do not appear to have a show playing, please start a show first');
		return;
	}
	
	//grab the things we need
	sl = netflix.Silverlight.MoviePlayer.getPlugin().getScriptInterface();
	init = netflix.Silverlight.MoviePlayer.getPlugin().settings.initParams;
	currrentEpisodeId = parseInt(idregx.exec(epIdRegex.exec(init)), 10);
	currentMovieId = parseInt(netflix.Silverlight.MoviePlayer.getPlugin().settings.movieId, 10);
	
	//Check if the user has already loded teh bookmarklet
	var autoplayElement = document.getElementById('NetflixAutoplay');
	if(autoplayElement) {
		alert('You have already loaded the autoplay bookmarklet, click the text at the botton to change number of episodes.');
		return;
	}
	
	//grab the metadata and decode it
	try {
		showData = JSON.parse(decode64(netflix.Silverlight.MoviePlayer.getPlugin().settings.metadata));
	} catch(e) {
		alert('Error processing data =(');
		return;
	}
		
	if(showData.Movie) {
		alert('This appears to be a movie not a TV show.  This bookmarklet only works on TV show.');
		return;
	}
	
	//set our pointest to match the episode we are currently on
	seasons = showData.Show.Seasons;
	for(seasonId = 0; seasonId < seasons.length; seasonId++) {
		for(episodeId = 0; episodeId < seasons[seasonId].Episodes.length; episodeId++) {
			if(seasons[seasonId].Episodes[episodeId].MovieId === currentMovieId || seasons[seasonId].Episodes[episodeId].MovieId === currrentEpisodeId) {
				done = true;
				break;
			}
		}
		if(done) {
			break;
		}		
	}
	
	//check if we were able to find the episode the user is  on
	if(seasonId === seasons.length) {
		alert('Error: Already of final episode, or episode data could not be found.');
		return;
	}	
	
	//Prompt user for number of episodes
	function getNumberOfEpisodesToWatch() {
		var newNum;
		do {
			newNum = prompt('How many episodes would you like to play?', (numToWatch - numWatched));
		} while (isNaN(newNum));
		
		numWatched = 0;
		numToWatch = parseInt(newNum, 10);
		
		//set the text
		if(numToWatch > 0) {
			autoplayElement.innerHTML = 'Netflix autoplay on, Episodes left: ' + numToWatch;
		} else {
			autoplayElement.innerHTML = 'Netflix autoplay off';
		}
	}	
	
	//create the text that shows how many episodes left & insert it
	node = document.createElement('span');
	autoplayElement = document.body.appendChild(node);
	autoplayElement.id = 'NetflixAutoplay';
	autoplayElement.innerHTML = 'Netflix autoplay on, Episodes left: ' + numToWatch;
		
	//attach a click handler so people can change number of episodes
	autoplayElement.addEventListener('click', getNumberOfEpisodesToWatch, false);

	//prompt the user for number of episodes for the first time
	getNumberOfEpisodesToWatch();
	
	//handle when the episode ends
	sl.OnMovieWatched = function() {
		if(numWatched < numToWatch && !waitTimer) {			//Check if done autoplaying
			waitTimer = setTimeout(function() {				//Set our timer so we do not end early
				var epp, numLeft;

				//move episode/season counters properly
				if(seasons[seasonId].Episodes[episodeId+1]) {
					episodeId++;
				} else {
					episodeId = 0;
					seasonId++;
				}	
				
				//if there is a next episode, grab it
				if(seasons[seasonId] && seasons[seasonId].Episodes[episodeId]) {
					epp = seasons[seasonId].Episodes[episodeId];
				}
				
				//if there is a next episode, play it and update the text
				if (epp) {
					sl.PlayMovie({movieId: epp.MovieId, episodeMovieId: 0, trackId: 0});
					numWatched++;
					numLeft = numToWatch - numWatched;
					if(numLeft > 0) {
						autoplayElement.innerHTML = 'Netflix autoplay on, Episodes left: ' + numLeft;
					} else {
						autoplayElement.innerHTML = 'Netflix autoplay completed.';
					}
				}
				
				//cleanup
				clearTimeout(waitTimer);
				waitTimer = null;
			}, 2*60*1000);
		}
	};

	//This is just a bse64 decoder
	function decode64(input) {
		var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
		output = '',
		chr1, chr2, chr3 = '',
		enc1, enc2, enc3, enc4 = '',
		i = 0,
		base64test = /[^A-Za-z0-9\+\/\=]/g;
		
		input = input.replace(base64test, '');

		do {
			enc1 = keyStr.indexOf(input.charAt(i++));
			enc2 = keyStr.indexOf(input.charAt(i++));
			enc3 = keyStr.indexOf(input.charAt(i++));
			enc4 = keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

			chr1 = chr2 = chr3 = '';
			enc1 = enc2 = enc3 = enc4 = '';

		} while (i<input.length);

		return unescape(output);
	}
})(window.netflix);

In addition to handling moving between seasons, it now also adds a little text below the movie to tell you that it is on. You can click this text to change the number of episodes it will play. Entering 0 for the number of episodes will turn this off.

About RTPMatt

I'm a Software Engineer Living in Asheville, NC. I specialize in Front-End development, currently with ReactJS. I also consult on some Vue projects.
This entry was posted in javascript, Netflix, programming. Bookmark the permalink.

47 Responses to Netflix Autoplay Bookmarklet – With Multiple Season Support!

  1. Aaron says:

    This isn’t working. (Firefox). I begin an episode of Andy Griffith, Click on the bookmark, enter “3” for episodes, skip to the end (which may be messing it up – don’t know, will try without skipping), then wait till the end. It just stays there. If it works without skipping, I’ll try and get back so you don’t waste any time.

    Thanks!

  2. Aaron says:

    Hey, tried it again with no fast forwarding, worked! Does it have to be on full screen like other ones?

    • Aaron says:

      Other ones being other programs.

      • RTPMatt says:

        There is no need for it to be full screen. Fast-forwarding can however mess it up. Actually if you had let it sit for 2 minutes it probably would have started the next episode. I have not found a good way to tell when the episode is over, Netflix has a “episode end” event I am using, but it fires about 2 minutes before the episode is actually over, so I am starting a timer that waits 2 minutes before starting the next episode.

        Glad it worked for you the next time though!

        • Aaron says:

          cool. It does end some early, but hey, it’s a great fix!

          I look forward to any tweaks, but appreciate your work either way!

  3. RTPMatt,

    I really like this. I greatly appreciate the work you have done. It does occasionally cut episodes a little short, but its usually in the credits so I don’t really care. I hope you don’t mind, but I posed this to Facebook, as many of my friends use Netflix and thought they could benefit from your hard work.

    Would you mind if I posted this on my site as one of my discoveries? I really like it and I am a major supporter of Open Source Code/Software. If you allow me, then I will gladly reference you as the author and can even send you a link when I post it to make sure you approve of the post.

    Sincerely,
    smleimberg

  4. Pingback: Autoplay Next Netflix Episode Bookmarklet! | s.m.leimberg.com

  5. Paul says:

    Hi, this looks awesome, but doesnt seem to work for me.

    I have two screens up and often have one screen showing netflix, fullscreened on the secondary screen, whilst working on the first (chrome, Windows 7).
    I assume that because the javascript window isnt the active window? if so is there any way around it?

    • RTPMatt says:

      Hmm, no, I do the same thing, I have not had any problems. I am assuming you are at least getting the dialog asking how many episodes you want to watch when you hit the bookmarklet? Can you tell me what show it is? Perhaps there is a problem with that show. Otherwise, maybe hit F12 and see if you are getting any errors? If so, send them to me and I will take a look.

  6. James says:

    I’m having an issue with the autoplay in Chrome to where it skips to the beginning of the season and starts playing there, not from the current episode. Is there a fix to this?

  7. Dave says:

    Awesome Matt, Simply brilliant. Cheers! Works like a championnnnnn

  8. Daphne says:

    You, sir, are a genius. GENIUOS!!!! Thank you so much. It works perfectly in FF.

  9. Chris says:

    Works great… *MOST* of the time. I’m still having a occasional issue where it will repeat the same episode… or go back to a certain episode (if say I click “next episode”). Wonder if I’m the only one having this issue.

    • RTPMatt says:

      Yes, this is a known bug. Unfortunately I have not found a way to get the current episode, so I have to go based on what episode it appears that you started at. It would be nice if I could fix this. Currently my advice load a new tab of Netflix, and start it playing on the first episode you want to watch. If I find a way to fix this, I will put out an update.

  10. Brandon says:

    There is a much simpler implementation of the same concept available. Next-Flik works with all browsers and supports multiple seasons. It runs in the background and only works when Netflix is open and full screen.

    http://www.next-flik.com

  11. Andrew says:

    So I tried this out and it worked perfectly. The only thing is that shows with long credits are not exact, as I must wait a few minutes. Overall this is great, and I’ve been looking for something like this because I play games while watching this. Thanks 😀

  12. Steve says:

    Am I missing something? I’m trying to follow the three steps you outlined in every variety I can think of, and it’s not that it isn’t working, it’s that nothing’s happening. I copied and pasted “the link below” (for this I tried the 174 line thing, right-clicking the hyperlink in Chrome and clicking copy link address, and even copying and pasting the hyperlink itself), into the only bar in Chrome, and the only thing that ever happened was Google telling me the URL is too big to process. I’ve tried every combination of bookmark-pressing and copying/pasting I can think of, but so far all I have is 3 apparently simple instructions that don’t actually do anything.

  13. Elle says:

    It is cutting off the end of the shows about 5 minutes early. Would this be looked into please? Thanks so much!

    • RTPMatt says:

      This seems to be a problem with some shows. The issue is that Netflix does not provide a reliable way to tell when a show ends so I am unfortunately using a timer to guess when it ends. If I find a better solution, I will post it.

  14. Daphne says:

    awwww….Netflix updated their player and the bookmarklet no longer works. 🙁 It was great while it lasted.

  15. Megan says:

    Yeah. They did an update. Crap. I was really enjoying the autoplay feature.

  16. KT says:

    raging at the fact that it no longer works. stupid netflix. the new layout is ugly.

  17. Taylor says:

    Does this work with OS X? I’ve added it to my bookmarks in safari, chrome, and firefox, and tried clicking it with an episode running and nothing happens.

  18. Seairra says:

    How long until a new update? I just discovered this and it would help me so much. I use netflix to go to sleep and with season that contain 22 minute episodes it would be amazing to not have to arise from sleep to start the next one

  19. Scott says:

    I thought you would like to know, it looks like you’ve misspelled the word “refrence” on your website. Silly mistakes can ruin your site’s credibility. In the past I’ve used a tool like SpellingScan.com to keep mistakes off my website.

    -Scott Matthews Sr.

Leave a Reply

Your email address will not be published. Required fields are marked *