Skip to content

Instantly share code, notes, and snippets.

@happyzleaf
Last active July 2, 2020 14:55
Show Gist options
  • Save happyzleaf/0d4a906904a3fadca2e1089dbd3e83b7 to your computer and use it in GitHub Desktop.
Save happyzleaf/0d4a906904a3fadca2e1089dbd3e83b7 to your computer and use it in GitHub Desktop.
Polito Video Clipboard

English

This addon lets you copy entire courses from PoliTO's website to your clipboard. You can then paste the content to JDownloader 2 to download each and every desired video. To install this script, download Greasemonkey or Tampermonkey (depending on your browser), then, click here and follow the GUI. Once installed, you can browse any video-lesson and copy the entire course in a single click.

Italiano

Questo script permette di copiare nella clipboard interi corsi dal sito del PoliTO. Una volta copiati, possono essere incollati nel LinkGrabber di JDownloader 2 per scaricare tutti i video. Per installare questo script, scarica Greasemonkey o Tampermonkey (a seconda del tuo browser), poi, click here e segui la GUI. Una volta installato, puoi andare su qualunque video-lezione per copiare l'intero corso in un click.

screenshot

Warning

This script has only been tested with Greasemonkey for Firefox.

// ==UserScript==
// @name Polito Video Clipboard
// @version 3
// @author Marco Montanari (happyzleaf)
// @namespace https://happyzleaf.com/
// @description Copies all the video urls from the selected course. Makes downloading entire courses easier with JDownloader 2.
// @include https://didattica.polito.it/portal/pls/portal/*
// @grant GM.xmlHttpRequest
// @grant GM.setClipboard
// ==/UserScript==
var box = document.getElementsByClassName("video-js-box")[0];
// The script does not support BigBlueBox players yet, therefore they're exluded here.
if (box == null) {
//box = document.getElementsByClassName("col-md-8")[0];
return;
}
function findVideo(data) {
var match = data.match(/https:\/\/video\.polito\.it\/dl\/.*\.mp4/gi);
return match.length > 0 ? match[0] : null;
}
var clipboardText = document.createElement("span");
clipboardText.textContent = "Clipboard: ";
var copyButton = document.createElement("button");
copyButton.innerHTML = "Copy video";
copyButton.onclick = function() {
GM.setClipboard(findVideo(document.documentElement.innerHTML));
}
var videoRegex = /href="(sviluppo\.(videolezioni.vis|pagina_corso.main|virtual_classroom.vis).*)">/gi;
var copyAllButton = document.createElement("button");
copyAllButton.innerHTML = "Copy all videos";
copyAllButton.onclick = function() {
loadingAllText.textContent = "Loading...";
// Adapted from https://github.com/lucaceriani
var baseUrl = "https://didattica.polito.it/portal/pls/portal/";
var matches, lessons = [];
while (matches = videoRegex.exec(document.documentElement.innerHTML)) {
lessons.push(matches[1].replace(new RegExp("&", 'g'), "&"));
}
if (lessons.length == 0) {
loadingAllText.textContent = "Error!";
return;
}
var count = 0;
var total = lessons.length;
var clipboard = "";
function updateStatus() {
if (count == total) {
loadingAllText.textContent = "Copied!";
GM.setClipboard(clipboard);
} else {
loadingAllText.textContent = "Loading... " + count + "/" + total;
}
}
lessons.forEach(function(item, index) {
GM.xmlHttpRequest({
method: "GET",
url: baseUrl + item,
onload: function(res) {
// Little hack cause for some reasons findVideo(res.responseText) with a BigBlueButton lesson blocks everything.
// Needs further investigation
if (res.responseText.includes("https://virtualclassroom24.polito.it/")) {
total--;
} else {
count++;
clipboard += findVideo(res.responseText) + "\n";
}
updateStatus();
},
onerror: function() {
total--;
updateStatus();
},
ontimeout: function() {
total--;
updateStatus();
}
});
});
}
var loadingAllText = document.createElement("span");
var div = document.createElement("div");
div.appendChild(clipboardText);
div.appendChild(copyButton);
div.appendChild(copyAllButton);
div.appendChild(loadingAllText);
div.appendChild(document.createElement("br"));
box.insertBefore(div, box.firstChild);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment