Last active
January 30, 2021 19:08
-
-
Save nima-rahbar/d87a25e269893ee06906248d7fc2fd9d to your computer and use it in GitHub Desktop.
Lynda Subtitles Downloader
This file contains hidden or 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
// ==UserScript== | |
// @id nima-rahbar | |
// @name Lynda Subtitles Downloader | |
// @name:el Λήψη υποτίτλων Lynda | |
// @name:fa دانلود زیرنویس های سایت لیندا | |
// @version 1.1.3 | |
// @author Nima Rahbar | |
// @namespace https://www.github.com/nima-rahbar | |
// @description Download subtitles on Lynda.com | |
// @icon https://nimarahbar.com/wp-content/uploads/2017/07/favicon.png | |
// @match https://www.lynda.com/* | |
// @grant GM_xmlhttpRequest | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.5.0/jszip.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js | |
// @downloadURL https://raw.githubusercontent.com/nima-rahbar/Lynda-Subtitles-Downloader/main/Lynda-Subtitles-Downloader.js | |
// @updateURL https://raw.githubusercontent.com/nima-rahbar/Lynda-Subtitles-Downloader/main/Lynda-Subtitles-Downloader.js | |
// ==/UserScript== | |
this.$ = this.jQuery = jQuery.noConflict(true); | |
$(document).ready(function(){ | |
if( $('div.col-xs-11.col-md-10.video-name-cont').length != 0 ){ | |
$('<div />', { | |
id: "allsubs", | |
style: "width:100%; max-height:300px; margin:20px 0; padding: 10px 15px; background-color:rgba(51,51,51,.8); color: #fff; overflow-y: auto; border-radius: 5px;", | |
html: '<h3>Download Subtitles</h3>', | |
}).appendTo('#course-feedback'); | |
var defaultTitle = $('.default-title').text(); | |
var videoList = $('div.col-xs-11.col-md-10.video-name-cont'); | |
var courseID = $('#video-container').data('course-id'); | |
$('#allsubs').append('<ul></ul>'); | |
var subDown = $('#allsubs ul'); | |
$('<button />',{ | |
id: "srt-archive", | |
text: 'Download zip file', | |
style: 'display: block; margin: 25px 0; background-color: #fff; color: #000; border: none; padding: 7px 10px;', | |
}).appendTo('#allsubs'); | |
var zip = new JSZip(); | |
$(videoList).each(function(v_i, item){ | |
var videoData = $(item).find('a'), | |
videoID = $(videoData).data('ga-value'), | |
videoSrt = 'https://www.lynda.com/ajax/player/transcript?courseID=' + courseID + '&videoID=' + videoID, | |
rawTitle = trim($(item).find('a').html()), | |
forbidden_chars = ['?', ':', '<', '>', '*', '/'], | |
wholeTitle = (v_i + 1) + ' - ' + rawTitle.replace(/^\.{1,}(.+)$/m, '$1'); // Remove first dot (if exists) | |
for(var i = 0; i < forbidden_chars.length; i++){ | |
while(wholeTitle.indexOf(forbidden_chars[i]) != -1){ | |
wholeTitle = wholeTitle.replace(forbidden_chars[i], ""); | |
} | |
} | |
if( v_i < 9 ){ | |
wholeTitle = "0" + wholeTitle; | |
} | |
$(subDown).append( '<li style="margin: 5px 0;"><a href="' + videoSrt + '" download="' + wholeTitle + '.srt' + '" style="font-size: 1.2rem;">' + wholeTitle + '</a></li>' ); | |
$.ajax({ | |
url: 'https://www.lynda.com/ajax/player/transcript?courseID=' + courseID + '&videoID=' + videoID, | |
success: function(response) { | |
zip.file(wholeTitle + '.srt', response); | |
}, | |
dataType: 'text' | |
}); | |
}); | |
function trim(str){ | |
return str.replace(/(^\s*)|(\s*$)/g, ''); | |
} | |
$("#srt-archive").on("click", function () { | |
zip.generateAsync({type:"blob"}).then(function (blob) { | |
saveAs(blob, defaultTitle + ".zip"); | |
}, function (err) { | |
$("#srt-archive").text(err); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment