Skip to content

Instantly share code, notes, and snippets.

@pjt33
Last active December 19, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjt33/6021695 to your computer and use it in GitHub Desktop.
Save pjt33/6021695 to your computer and use it in GitHub Desktop.
Coursera video list: things to run in the console 1. Generate wiki markup for the subtitles page. 2. Generate a bash script to download the resources
$('a.lecture-link').each(function(){
var $lectureLink = $(this);
var lectureId = $lectureLink.data('lecture-id');
var title = $lectureLink.text().trim().replace(/ *\([0-9]+:[0-9]+\)/, '');
console.log('* ' + title + ' [[Scigast:Subtitles:Lecture' + lectureId + ':en|English]] | [[Scigast:Subtitles:Lecture' + lectureId + ':es|Español]]');
}),null;
console.log('#!/bin/bash');
console.log('# It turns out that (at present, at least) it\'s not necessary to log in');
console.log('');
console.log('# downloadCoursera from to');
console.log('function downloadCoursera() {');
console.log(' wget -nv -c -O "$2" "$1"');
console.log('}');
var prefix = '00.', count = 0;
$("a.lecture-link").each(function() {
var $lectureLink = $(this);
var $li = $lectureLink.parent('li');
var lectureTitle = $.trim($lectureLink.text()).
// Remove trailing length of video
replace(/ *\([0-9]+:[0-9]+\)/, '').
// Use two-digit IDs
replace(/^([0-9])\./, '0$1.').replace(/\.([0-9]): /, '.0$1: ').
// Sanitise for filenames
replace(/[^a-zA-Z0-9 .-]/g, '')
;
// Assignments and other "extras" have different format
if (lectureTitle.match(/^[0-9]{2}\./)) {
if (lectureTitle.substring(0, 3) !== prefix) {
prefix = lectureTitle.substring(0, 3);
count = 0;
}
}
else {
lectureTitle = prefix + 'x' + (++count) + ' ' + lectureTitle;
}
console.log('# ' + lectureTitle);
$('a[rel="tooltip"]', $li).each(function() {
var href = $(this).attr('href');
if (href.match(/[=.]srt$/)) console.log('downloadCoursera "' + href + '" "' + lectureTitle + '.en.srt"');
else if (href.match(/[=.]pdf$/)) console.log('downloadCoursera "' + href + '" "' + lectureTitle + '.pdf"');
else if (href.match(/download\.mp4/)) console.log('downloadCoursera "' + href + '" "' + lectureTitle + '.mp4"');
});
});
'# Done';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment