forked from riazXrazor/udemy-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (67 loc) · 2.85 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env node
var chalk = require('chalk');
var clear = require('clear');
var CLI = require('clui');
var figlet = require('figlet');
var inquirer = require('inquirer');
var Spinner = CLI.Spinner;
var fs = require('fs');
var Preferences = require('preferences');
var yargs = require('yargs');
var files = require('./lib/files');
var functions = require('./lib/functions');
var core = require('./lib/core');
var argv = yargs
.usage( "Usage: udl <course_url> [-u \"username\"] [-p \"password\"]" )
.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( "o", { alias: "output", demand: false, describe: "Output directory where the videos will be saved, default is current directory", type: "string" } )
.help( "?" )
.alias( "?", "help" )
.epilog( "By Riaz Ali Laskar" )
.argv;
// Get the URL from the first parameter
var url = argv._[ 0 ];
functions.headingMsg();
var status;
if(argv.username && argv.password)
{
status = new Spinner('Logging in, please wait... ');
status.start();
core.login(argv.username,argv.password,function(access_token,client_id){
status.stop();
if(url)
{
status = new Spinner("Checking course url... ");
status.start();
core.get_course_id(url,function(id){
let course_id = id;
core.check_course_status(id,function(){
status.stop();
core.get_data_links(course_id);
});
});
}
else
{
functions.getCourse(url,function(){
//console.log("Ok");
});
}
});
}
else
{
functions.getUdemyCredentials(function(credentials){
var status = new Spinner('Logging in, please wait... ');
status.start();
core.login(credentials.username,credentials.password,function(access_token,client_id){
status.stop();
functions.getCourse(url,function(){
//console.log("Ok");
});
});
});
}