Created
February 27, 2018 18:35
-
-
Save RaphaelMeudec/2ac744d6cf2e649b9247a7177e261a37 to your computer and use it in GitHub Desktop.
Extract all videos from Workplace and download it as csv
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
// Add replaceAll method to string to remove new line | |
String.prototype.replaceAll = function(search, replacement) { | |
var target = this; | |
return target.replace(new RegExp(search, 'g'), replacement); | |
}; | |
// Add a console.save function | |
(function(console){ | |
console.save = function(data, filename){ | |
if(!data) { | |
console.error('Console.save: No data') | |
return; | |
} | |
if(!filename) filename = 'console.json' | |
if(typeof data === "object"){ | |
data = JSON.stringify(data, undefined, 4) | |
} | |
var blob = new Blob([data], {type: 'text/json'}), | |
e = document.createEvent('MouseEvents'), | |
a = document.createElement('a') | |
a.download = filename | |
a.href = window.URL.createObjectURL(blob) | |
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':') | |
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) | |
a.dispatchEvent(e) | |
} | |
})(console) | |
// Extract all video names and url in videoTitles | |
var videoElements = document.getElementsByClassName('uiVideoLink'); | |
var videoTitles = [['title', 'href']]; | |
for ( var i=0; i<videoElements.length; i++ ) { | |
let title = videoElements[i].title.replaceAll('\r', '').replaceAll('\n', ''); | |
let url = videoElements[i].href; | |
videoTitles.push([title, url]) | |
} | |
// Generate csv from all videoTitles | |
var csv = ""; | |
videoTitles.forEach(row => csv += row.join(";") + "\r\n"); | |
// Save csv | |
console.save(csv, 'videos.csv'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment