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).

I don’t have to do this every morning (thank god) but I have been doing it about once a week lately. The transit route described here is kinda the ’standard’ route – you can get creative with all the different transit agencies in between Sacramento and Palo Alto, but as far as I am able to find, no ‘creative’ route is able to beat out the ’standard’ route. Note that I’m purposefully excluding a ‘bike + transit’ option for the purposes of this DeathMatch.

All times AM, all money in USD (duh).

The Route, via Transit

  • Walk, house -> bus stop: 3 min
  • SacRT, bus: 6:35 -> 6:50, $2.50
  • Amtrak, capitol corridor, Sacramento -> Richmond: 7:00 -> 8:25, $13.60 (10-ride pass)
  • Bart, Richmond -> Mlibrae: 8:42 -> 9:51, $5.31
  • Caltrain, Milbrae -> Palo Alto: 9:55 -> 10:25, $4.25
  • Stanford Shuttle: 10:30 -> 10:40, free
  • Walk, shuttle stop -> class: 3min

Direct Monetary Cost

2.50 + 13.60 + 5.31 + 4.25 = $25.66

Time Analysis

Percent Efficiency Assumptions
  • Transfers/walking: %0, including 2 min window on each side cause it takes a while to get situated on bus/train
  • Bus/shuttle: %30
  • Bart: %50
  • Caltrain: %70
  • Amtrak: %90
Effective 100% Efficiency Time

(sacrt) + (amtrak) + (bart) + (caltrain) + (stanford shuttle) =
(15 – 2*2) * 0.3 + (85 – 2*2) * 0.9 + (69 – 2*2) * 0.5 + (30 – 2*2) * 0.7 + (10 – 2*2) * 0.3 =
11 * 0.3 + 81 * 0.9 + 65 * 0.5 + 26 * 0.7 + 6 * 0.3 =
128.7 min ~= 2 hrs 9 min

Wasted Time

Total Travel Time – 100% effective efficiency time =
(4 hrs 13 min) – (2 hrs 9 min) = 2 hrs 4 min

The Route, Driving

  • Walk to car, 3 min
  • Drive @ rush hour, Sacramento -> Stanford: 2 hrs 50 mins, 124 miles (src: google maps)
  • Park car and walk to class: 15 min, $11

Direct Monetary Cost

Assumptions
  • 30 mph
  • $3.00 per gallon for gas
  • bridge toll: $4.00
  • ignoring all other car costs – they’re not ‘direct’ (ie. you don’t pay them right then)
Calculation

124 / 30 * 3.00 + 11.00 + 4.00 = $27.40

Wasted Time

3 min + (2 hrs 50 min) + 15 min = 3 hrs 8 min

Conclusions

Taking the trip via transit rather than driving saves $1.74 (oh boy!) and 1 hour, 4 minutes of time. If we were to add in the full costs of owning an automobile (AAA estimate: ~52.2 cents/mile) then the monetary cost for driving rises to $79.73, thus implying a monetary savings of $54.07 for taking the trip via transit, rather than driving. Bam! Headshot.

Commute Mode DeathMatch Leaderboard

  • Transit: 1 (headshot)
  • Driving: 0

Coming soon: ‘biking + transit’ jumps into the rumble!