Stanford has a lot of their lectures online. To access them, you’ve got to have… access! That means you need to already have an SUNet ID with proper permissions. The standard way to get those permissions is to apply to Stanford, get accepted, and start paying Stanford lots of $$$.

Stanford doesn’t want these lectures to get out on the open internet. So they do a few things to try to ensure that doesn’t happen. First, part of Stanford’s terms of use is that you will not redistribute their lectures. Note that the concepts and code I’m showing you here in this post could be used to help you illegally redistribute their lectures. I do not condone any such illegal use. By using the the concepts and code in this post in any way whatsoever (including just reading this post), you agree to follow Stanford’s terms of use.. If you don’t agree to these terms, please leave now.

In addition to their terms of use, Stanford places a more practical barrier in the way of illegal redistribution of their lectures – they only distribute their lectures as streaming WMV and Sliverlight. Now this sucks for me, the legal end-user, for a number of reasons. Most importantly, this means I need a high-bandwidth connection to watch my lectures. I can’t watch them offline.

Enter MEncoder and Greasemonkey.

MEncoder is a tool to save streaming video to disk. Greasemonkey is a Firefox browser extension that allows you to run custom javascript for any particular page displayed in the browser.

To save a lecture to disk for offline viewing, the basic command you want to run is:

mencoder mms://the-streaming-video.wmv -ovc copy -oac copy -O filename_out.avi

Now the ‘path-to-streaming-video.wmv’ you need to use will be unique for your authenticated SUNet session with Stanford’s servers. You can manually find this unique path by navigating with your browser to the lecture you’re interested in, viewing the source of the page, and manually scanning for the path. Or you can install the following small and simple Greasemonkey script.

// ==UserScript==
// @name          Stanford Video MMS Path Retriever
// @copyright     2010, Mike Fogel, http://fogel.ca
// @license       This SW may not be used to violate Stanford's terms of use.
// @namespace     http://fogel.ca/greasemonkey
// @description   Adds a header containing mms path to Stanford player page.
// @include       https://myvideosu.stanford.edu/player/slplayer.aspx*
// ==/UserScript==

function get_mms_path() {
  var o = document.getElementById('WMPlayer');
  return 'mms' +  o.data.substring('http'.length);
}

function add_header(message) {
var elem = document.createElement('div');
  elem.id = 'GM_mms_path';
  elem.style.color = 'green';
  elem.innerHTML = '<h2>'+message+'</h2>';
  document.body.insertBefore(elem, document.body.firstChild);
  return elem;
}

function set_selection(hdr) {
  var range = document.createRange();
  range.selectNodeContents(hdr.firstChild);
  selection = window.getSelection();
  selection.removeAllRanges();
  selection.addRange(range);
}

function main() {
  var mms = get_mms_path();
  var hdr = add_header(mms);
  set_selection(hdr);
}

main();

The Greasemonkey script scrapes the page, finds the ‘path-to-streaming-video.wmv’, adds it in large, bright green text to the top of the page, and selects it so you can just hit ‘cntrl-c’ to copy it to your clipboard. Then over in a terminal, you can paste that path into your MEncoder command. Running the command will take a long time – in fact, as long as the lecture is. This is because MEncoder simulates a regular streaming video player to the Stanford servers. MEncoder will convert and save the streaming video according the the suffix of the output filename you specify (eg. ‘.avi’ in my above example).

Leave a Reply