Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Bugfix for Issue 14 - Unknown resolution #25

Merged
merged 1 commit into from
May 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var argv = yargs
.command( "course_url", "URL of the udemy coures to download", { alias: "url" } )
.option( "u", { alias: "username", demand: false, describe: "Username in udemy", type: "string" } )
.option( "p", { alias: "password", demand: false, describe: "Password of yor account", type: "string" } )
.option( "r", { alias: "resolution", demand: false, describe: "Download video resolution, default resolution is 360, for other video resolutions please refer to the website.", type: "number" } )
.option( "r", { alias: "resolution", demand: false, describe: "Maximum download video resolution, default resolution is 360, for other video resolutions please refer to the website.", type: "string" } )
.option( "o", { alias: "output", demand: false, describe: "Output directory where the videos will be saved, default is current directory", type: "string" } )
.help( "?" )
.alias( "?", "help" )
Expand Down Expand Up @@ -162,7 +162,11 @@ let check_course_status = function(course_id,cb){

let set_video_resolution = function (element,callback) {

if(argv.resolution) return;
if(argv.resolution)
{
callback(null);
return;
}

var resolution_choices = [];
let course_id = element.course_id;
Expand Down Expand Up @@ -220,7 +224,7 @@ let check_course_status = function(course_id,cb){
{
type: 'list',
name: 'resolution',
message: 'Select the video resolution to download:',
message: 'Select the maximum video resolution to download:',
choices:resolution_choices,
default: 0
}
Expand All @@ -229,20 +233,20 @@ let check_course_status = function(course_id,cb){

inquirer.prompt(questions).then(function(reso) {

var url = reso.resolution ? list_videos[reso.resolution] : list_videos[360];
// var url = list_videos[1080]
// console.log('selection',reso);
// console.log('choices',resolution_choices);
// console.log('video_list',list_videos);
// console.log('url',url);
if(!url)
{
console.log("Unknown video resolution");
process.exit(0);
}
//if(!url)
//{
//console.log("Unknown video resolution");
//process.exit(0);
//}

argv.resolution = reso.resolution;

callback(null);
callback(null);

});

Expand Down Expand Up @@ -314,10 +318,22 @@ let check_course_status = function(course_id,cb){


var url = argv.resolution ? list_videos[argv.resolution] : list_videos[360];
if(!url)
{
console.log("Unknown video resolution");
process.exit(0);
var r = argv.resolution ? argv.resolution : 360;

while(!url)
{
switch(r) {
case 'Auto': var r = '1080'; break;
case '1080': var r = '720'; break;
case '720': var r = '480'; break;
case '480': var r = '360'; break;
default: console.log("At least 1 video is missing valid resolution.");
process.exit(0);
};

var url = list_videos[r];

//console.log('lower res ', r, ' - ', url);
}

element.data_url = unescape(url);
Expand Down