Skip to content

Commit

Permalink
Merge pull request #117 from cs-education/fix_wlv
Browse files Browse the repository at this point in the history
Fix wlv
  • Loading branch information
chirantan31 authored Feb 14, 2019
2 parents e265ec1 + 0e0e064 commit f03bb58
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 95 deletions.
24 changes: 18 additions & 6 deletions db/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ async function doesEchoMediaExist(echoMediaId) {
WHERE echoMediaId = ? \
GROUP BY id; ",
{ replacements: [echoMediaId], type: sequelize.QueryTypes.SELECT }).catch(err => perror(err)); /* raw query */
var count = query.count;
console.log(query);
console.log(count);
var count = 0;
if (query.length > 0) {
count = query[0].count;
} else {
count = 0;
}
console.log("EchoMediaid count:" + count);
return count > 0 ? true : false;
}

Expand All @@ -107,7 +111,13 @@ async function doesYoutubeMediaExist(playlistId, title) {
WHERE playlistId = ? and title = ? \
GROUP BY id",
{ replacements: [playlistId, title], type: sequelize.QueryTypes.SELECT }).catch(err => perror(err)); /* raw query */
var count = query.count;
var count = 0;
if (query.length > 0) {
count = query[0].count;
} else {
count = 0;
}
console.log("EchoMediaid count:" + count);
return count > 0 ? true : false;
}

Expand Down Expand Up @@ -161,11 +171,13 @@ async function addMSTranscriptionTask(mediaId, taskId, videoHashsum, videoLocalL
fileName = path.resolve(fileName);
fs.copyFileSync(videoLocalLocation, fileName);
fs.unlinkSync(videoLocalLocation);
task = await MSTranscriptionTask.create({ id: id, videoHashsum: videoHashsum, videoLocalLocation: fileName});
task = await MSTranscriptionTask.create({ id: id, videoHashsum: videoHashsum, videoLocalLocation: fileName });
} else {
task = await getTask(taskId);
}
await TaskMedia.create({ taskId: task.id, mediaId: mediaId });
await TaskMedia.findOrCreate({
where: { taskId: task.id, mediaId: mediaId }
});
return task;
}

Expand Down
4 changes: 3 additions & 1 deletion modules/auto_update.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ async function processCourseOfferingId(courseOfferingId) {
}

(async () => {
await addJobs();
await getJobs();
// await processCourseOfferingId('c48ca8d2-a7a7-40b2-86c5-14bfa0630e0e');
// await scraper_utils.reprocessIncompleteMedias('c48ca8d2-a7a7-40b2-86c5-14bfa0630e0e');
// await scraper_utils.reprocessIncompleteTaskIdsForCourseOfferingId('c48ca8d2-a7a7-40b2-86c5-14bfa0630e0e', false);
})();


Expand Down
9 changes: 7 additions & 2 deletions modules/scraper_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,22 @@ async function processTasks(mediaIds) {
var outputFile = await download_lecture(media);
var videoHashsum = await conversion_utils.hash_file(outputFile);
var taskId = await db.getTaskIdIfNotUnique(videoHashsum);
var duplicate = false;
if (taskId != null) {
duplicate = true;
console.log("Duplicate: " + taskId);
try {
console.log("Deleting:" + outputFile);
fs.unlinkSync(path.resolve(outputFile));
} catch (err) {
console.log(err);
}
}
}

var task = await db.addMSTranscriptionTask(mediaId, taskId, videoHashsum, path.resolve(outputFile));
tasks.push(task);
if(!duplicate) {
tasks.push(task);
}
});
await wavAndSrt(tasks);
}
Expand Down Expand Up @@ -187,6 +191,7 @@ async function reprocessIncompleteMedias(courseOfferingId) {

async function reprocessIncompleteTaskIdsForCourseOfferingId(courseOfferingId, parallel) {
var taskIds = await db.getIncompleteTaskIdsForCourseOfferingId(courseOfferingId);
console.log(taskIds);
var tasks = [];
for (var taskId in taskIds) {
tasks.push(await db.getTask(taskIds[taskId]));
Expand Down
153 changes: 68 additions & 85 deletions public/javascripts/controllers/watchLectureVideos.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var player;
var jslinqData;
var currentVideoTranscriptions;
var timeUpdateLastEnd = 0;
var timeUpdateLastStart = 0;
var fullCourseSearch = false;
var autoScroll = true;
var live_transcriptions_div = $('#live_transcriptions');
Expand Down Expand Up @@ -34,32 +35,36 @@ function navigateToVideo(video, startTime) {
player.play();
}

// Update live_transcriptions_div with items in list
function updateLiveTranscriptionsDiv(list) {
console.log("Total Transcriptions for video: " + list.length);
//// Update live_transcriptions_div with items in list
//function updateLiveTranscriptionsDiv(list) {
// console.log("Total Transcriptions for video: " + list.length);

// live_transcriptions_div.children().css('display', 'none');
// // Show the dummy transcriptions (with negative ids)
// for (let i = 0; i < dummy_transcriptions_count; i++) {
// $("#" + (-i - 1)).css('display', 'block');
// }
// if (list.length !== 0) {
// // Show results
// for (var item in list) {
// var listItemId = list[item].id;
// $("#" + (listItemId)).css('display', 'initial');
// }
// }
//}

live_transcriptions_div.children().css('display', 'none');
// Show the dummy transcriptions (with negative ids)
for (let i = 0; i < dummy_transcriptions_count; i++) {
$("#" + (-i - 1)).css('display', 'block');
}
if (list.length !== 0) {
// Show results
for (var item in list) {
var listItemId = list[item].id;
$("#" + (listItemId)).css('display', 'initial');
}
}
}
function updateCurrentVideoTranscriptions() {
timeUpdateLastEnd = timeUpdateLastStart = 0;
var video = player.currentSrc();
currentVideoTranscriptions = jslinqData.where(function (item) {
// filter out results to currentVideo
return video === item.video;
});
var currentList = currentVideoTranscriptions.toList();
// Output it
updateLiveTranscriptionsDiv(currentList);
// updateLiveTranscriptionsDiv(currentList);
addTranscriptionsToDiv(currentList);
updateDownloadVttButton(video);
}

function attachTranscriptionItemListeners() {
Expand Down Expand Up @@ -108,8 +113,7 @@ function generateShareLink(video, startTime) {
utils.copyTextToClipboard(shareLink);
}

function addAllTranscriptionsToList() {
var currentList = jslinqData.toList();
function addTranscriptionsToDiv(currentList) {
// Output it
if (currentList.length === 0) {
// Hide results
Expand All @@ -134,9 +138,9 @@ function addAllTranscriptionsToList() {
}
attachTranscriptionItemListeners();
}

function generateItemHTML(id, start, video, part) {
return "<div class='list-group-item transcription-item' style='display:none;' id='" + id + "'>" +
return "<div class='list-group-item transcription-item' style='display:initial;' id='" + id + "'>" +
"<div class= 'row'>" +
"<div class='col-sm-3'><tt>" +
utils.msToTime(start) +
Expand Down Expand Up @@ -167,15 +171,15 @@ function generateItemHTML(id, start, video, part) {
}

function updateDownloadVttButton(srcid) {
currentVideoTranscriptions = jslinqData.where(function (item) {
// filter out results to currentVideo
return srcid === item.video;
});
var currentList = currentVideoTranscriptions.toList();
var filePath = currentList[0].subFile;
var buttonItem = generateDownloadVttButtonHTML(filePath);
download_transcriptions_div.append(buttonItem);
live_transcriptions_div.show();
currentVideoTranscriptions = jslinqData.where(function (item) {
// filter out results to currentVideo
return srcid === item.video;
});
var currentList = currentVideoTranscriptions.toList();
var filePath = currentList[0].subFile;
var buttonItem = generateDownloadVttButtonHTML(filePath);
download_transcriptions_div.empty()
download_transcriptions_div.append(buttonItem);
}

function generateDownloadVttButtonHTML(srcid) {
Expand All @@ -195,7 +199,6 @@ function scrollToListItem(listItemId) {
function updateTranscriptionsData(data) {
idx = getLunrObj(data);
jslinqData = jslinq(data);
addAllTranscriptionsToList();
}

function linkSrcAndTitle(playlist) {
Expand All @@ -204,6 +207,35 @@ function linkSrcAndTitle(playlist) {
}
}

function update_search_results() {
// Get query
var query = $("#search").val();
results = idx.search(query);
filteredSubs = []
results.forEach(function (result) {
index = parseInt(result.ref);
filteredSubs.push(data[index]);
});
var queryObj = jslinq(filteredSubs);
var res;
if (fullCourseSearch) {
res = queryObj.toList();
} else {
res = queryObj.where(function (item) {
return item.video === player.currentSrc();
}).toList();
}
console.log("Total Search Results" + res.length);
addTranscriptionsToDiv(res)
if (fullCourseSearch) {
if ($("#search").val()) {
$('.video-name-for-vtt').css('display', 'initial');
}
} else {
$('.video-name-for-vtt').css('display', 'none');
}
}

(async () => {
var playlist = await $.when($.getJSON(getPlaylistUrl))
linkSrcAndTitle(playlist)
Expand All @@ -225,11 +257,9 @@ function linkSrcAndTitle(playlist) {
nextButton: true
});
data = await $.when($.getJSON(getSrtUrl));
var srcid = player.currentSrc()
updateTranscriptionsData(data);
updateCurrentVideoTranscriptions();
updateDownloadVttButton(srcid);


var queryParams = utils.getUrlVars();
if (queryParams.hasOwnProperty('video')) {
if (queryParams.hasOwnProperty('startTime')) {
Expand All @@ -238,51 +268,9 @@ function linkSrcAndTitle(playlist) {
navigateToVideo(queryParams['video'], 0);
}
}


function update_search_results() {
// Get query
var query = $("#search").val();
results = idx.search(query);
filteredSubs = []
results.forEach(function (result) {
index = parseInt(result.ref);
filteredSubs.push(data[index]);
});
var queryObj = jslinq(filteredSubs);
var res;
if (fullCourseSearch) {
res = queryObj.toList();
} else {
res = queryObj.where(function (item) {
return item.video === player.currentSrc();
}).toList();
}
console.log("Total Search Results" + res.length);
if (res.length === 0) {
// Hide results
live_transcriptions_div.children().css('display', 'initial');
} else {
// Show results
if (fullCourseSearch) {
if ($("#search").val()){
$('.video-name-for-vtt').css('display', 'initial');
}
} else {
$('.video-name-for-vtt').css('display', 'none');
}
live_transcriptions_div.children().css('display', 'none');
for (var item in res) {
var listItemId = res[item].id;
$("#" + (listItemId)).css('display', 'initial');
}
}
updateLiveTranscriptionsDiv(res);
}

$('#search').on('keyup', update_search_results);


$('#full_course_search').change(function () {
if (this.checked) {
fullCourseSearch = true;
Expand All @@ -305,24 +293,20 @@ function linkSrcAndTitle(playlist) {

player.on('playlistitem', function () {
updateCurrentVideoTranscriptions();
srcid = player.currentSrc();
download_transcriptions_div.empty()
updateDownloadVttButton(srcid);
});
player.on('timeupdate', function () {
var currentTimeinMillis = player.currentTime() * 1000;
if (currentTimeinMillis > timeUpdateLastEnd) {
var res = currentVideoTranscriptions.where(function (item) {
// find the appropriate subtitle
return (currentTimeinMillis >= item.start) && currentTimeinMillis <= item.end;
}).toList();
if (currentTimeinMillis > timeUpdateLastEnd || currentTimeinMillis < timeUpdateLastStart) {
console.log(currentTimeinMillis);
var res = currentVideoTranscriptions.where(function (item) {
// find the appropriate subtitle
return (item.start <= currentTimeinMillis);
}).orderByDescending(function (item) { return item.start; }).take(1).toList();

for (var item in res) {
scrollToListItem(res[item].id);
timeUpdateLastEnd = res[item].end;
timeUpdateLastStart = res[item].start;
}
}
});
Expand All @@ -334,6 +318,5 @@ function linkSrcAndTitle(playlist) {
$('.vjs-up-next').click();
}
})

});
})();
4 changes: 3 additions & 1 deletion router/routes/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ router.get('/login', function (request, response) {
var redirectPath;
if (typeof request.query.redirectPath != "undefined") {
redirectPath = request.query.redirectPath;
}
} else {
redirectPath = '/courses';
}
if (request.isAuthenticated()) {
response.redirect('../courses');
} else {
Expand Down

0 comments on commit f03bb58

Please sign in to comment.