Last active
December 19, 2015 21:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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