Skip to content
This repository has been archived by the owner on Jul 8, 2021. It is now read-only.

Commit

Permalink
Choose subtitle language
Browse files Browse the repository at this point in the history
  • Loading branch information
FaisalUmair committed May 29, 2018
1 parent 40d40e2 commit ce19c0a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 8 deletions.
64 changes: 56 additions & 8 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ var skipSubtitles = settingsCached.download.skipSubtitles;
var lectureindex = -1;
var remaining = response.count;
coursedata['totallectures'] = 0;
var availableSubs = [];

if(response.results[0]._class=="lecture"){
chapterindex++;
Expand All @@ -298,7 +299,12 @@ var skipSubtitles = settingsCached.download.skipSubtitles;
if(v.asset.asset_type!="Video"&&skipAttachments){
remaining--;
if(!remaining){
initDownload($course,coursedata);
if(Object.keys(availableSubs).length){
askforSubtile(availableSubs,initDownload,$course,coursedata);
}else{
initDownload($course,coursedata);
}

}
return;
}
Expand Down Expand Up @@ -350,7 +356,11 @@ var skipSubtitles = settingsCached.download.skipSubtitles;
}
coursedata['chapters'][chapterindex]['lectures'][lectureindex] = {src:src,name:lecturename,quality:videoQuality,type:type};
if(!skipSubtitles&&response.asset.captions.length){
coursedata['chapters'][chapterindex]['lectures'][lectureindex].caption = response.asset.captions[0].url;
coursedata['chapters'][chapterindex]['lectures'][lectureindex].caption = [];
response.asset.captions.forEach(function(caption){
caption.video_label in availableSubs ? availableSubs[caption.video_label] = availableSubs[caption.video_label]+1 : availableSubs[caption.video_label] = 1;
coursedata['chapters'][chapterindex]['lectures'][lectureindex].caption[caption.video_label] = caption.url;
});
}
if(response.supplementary_assets.length&&!skipAttachments){
coursedata['chapters'][chapterindex]['lectures'][lectureindex]['supplementary_assets'] = [];
Expand All @@ -371,7 +381,12 @@ var skipSubtitles = settingsCached.download.skipSubtitles;
remaining--;
coursedata['totallectures']+=1;
if(!remaining){
initDownload($course,coursedata);
if(Object.keys(availableSubs).length){
askforSubtile(availableSubs,initDownload,$course,coursedata);
}else{
initDownload($course,coursedata);
}

}
}
}
Expand All @@ -381,7 +396,11 @@ var skipSubtitles = settingsCached.download.skipSubtitles;
remaining--;
coursedata['totallectures']+=1;
if(!remaining){
initDownload($course,coursedata);
if(Object.keys(availableSubs).length){
askforSubtile(availableSubs,initDownload,$course,coursedata);
}else{
initDownload($course,coursedata);
}
}
}
}
Expand All @@ -394,13 +413,21 @@ var skipSubtitles = settingsCached.download.skipSubtitles;
remaining--;
coursedata['totallectures']+=1;
if(!remaining){
initDownload($course,coursedata);
if(Object.keys(availableSubs).length){
askforSubtile(availableSubs,initDownload,$course,coursedata);
}else{
initDownload($course,coursedata);
}
}
lectureindex++;
}else{
remaining--;
if(!remaining){
initDownload($course,coursedata);
if(Object.keys(availableSubs).length){
askforSubtile(availableSubs,initDownload,$course,coursedata);
}else{
initDownload($course,coursedata);
}
}
}

Expand All @@ -416,7 +443,7 @@ var skipSubtitles = settingsCached.download.skipSubtitles;
});


function initDownload($course,coursedata){
function initDownload($course,coursedata,subtitle=false){
var $clone = $course.clone();
var $downloads = $('.ui.downloads.section .ui.courses.items');
var $courses = $('.ui.courses.section .ui.courses.items');
Expand Down Expand Up @@ -689,7 +716,7 @@ function downloadLecture(chapterindex,lectureindex,num_lectures,chapter_name){
var file = fs.createWriteStream(download_directory+'/'+course_name+'/'+chapter_name+'/'+lecture_name).on('finish', function(){
checkAttachment();
});
var request = https.get(coursedata['chapters'][chapterindex]['lectures'][lectureindex]['caption'], function(response) {
var request = https.get(coursedata['chapters'][chapterindex]['lectures'][lectureindex]['caption'][subtitle] ? coursedata['chapters'][chapterindex]['lectures'][lectureindex]['caption'][subtitle] : coursedata['chapters'][chapterindex]['lectures'][lectureindex]['caption'][Object.keys(coursedata['chapters'][chapterindex]['lectures'][lectureindex]['caption'])[0]], function(response) {
response.pipe(file);
});
}
Expand Down Expand Up @@ -1081,4 +1108,25 @@ function loadDefaults(){

if(!settings.get('general')){
loadDefaults();
}

function askforSubtile(availableSubs,initDownload,$course,coursedata){
var $subtitleModal = $('.ui.subtitle.modal');
var $subtitleDropdown = $subtitleModal.find('.ui.dropdown');
var subtitleLanguages = [];
for(var key in availableSubs){
subtitleLanguages.push({
name: `<b>${key}</b> <i>${availableSubs[key]} Lectures</i>`,
value: key
})
}
$subtitleModal.modal({closable: false}).modal('show');
$subtitleDropdown.dropdown({
values: subtitleLanguages,
onChange: function(subtitle){
$subtitleModal.modal('hide');
$subtitleDropdown.dropdown({values:[]});
initDownload($course,coursedata,subtitle);
}
});
}
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<div class="ui basic subtitle modal">
<div class="ui icon header">
<i class="closed captioning icon"></i>
Select Subtitle
</div>
<div class="content">
<div class="ui fluid selection dropdown">
<input type="hidden" name="subtitle">
<i class="dropdown icon"></i>
<div class="default text">Subtitle Language</div>
</div>
</div>
</div>
<div class="ui basic update-available modal">
<div class="ui icon header">
<i class="gift icon"></i>
Expand Down

0 comments on commit ce19c0a

Please sign in to comment.