Skip to content

Commit d48d695

Browse files
committed
Added video URL generation and error messages.
1 parent 96c1953 commit d48d695

File tree

3 files changed

+71
-38
lines changed

3 files changed

+71
-38
lines changed

functions/paramProcessor.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('fs');
22

33
const notLast = [
4-
"--noSubs", "--noInfo", "--noBB"
4+
"--noSubs", "--noInfo", "--noBB", "--noVideo"
55
]
66

77
/**
@@ -13,7 +13,8 @@ function paramsProcess(params) {
1313
"path": params[params.length - 1],
1414
"noSubs": false,
1515
"noInfo": false,
16-
"noBB": false
16+
"noBB": false,
17+
"noVideo": false
1718
};
1819

1920
params.forEach((value, index) => {
@@ -44,6 +45,11 @@ function paramsProcess(params) {
4445
break;
4546
}
4647

48+
case "--noVideo": {
49+
keys.noVideo = true;
50+
break;
51+
}
52+
4753
default:
4854
break;
4955
}
@@ -61,7 +67,8 @@ function helpText() {
6167
"\t--license\tOutputs the license of this project. (GNU General Public License)\n",
6268
"\t--noSubs\tDisables output of subtitles.\n",
6369
"\t--noInfo\tDisables output of course information.\n",
64-
"\t--noBB\t\tDisables output of BB code.\n\n",
70+
"\t--noBB\t\tDisables output of BB code.\n",
71+
"\t--noVideo\tDisables output of video URLs.\n\n",
6572
"\rProudly presented to you by flyingdragon of BlackPearl. Licensed under the GNU General Public License v3.\n",
6673
"\rPRs welcome at https://github.com/kwongtn/CourseExtractor \n\n",
6774
"\rIf there are any issues, please open an issue at https://github.com/kwongtn/CourseExtractor/issues .",
@@ -70,6 +77,7 @@ function helpText() {
7077
process.exit();
7178
}
7279

80+
/**
7381
if (process.argv.length < 3) {
7482
helpText();
7583
process.exit();
@@ -84,13 +92,13 @@ if (process.argv.length < 3) {
8492
8593
console.log(paramsProcess(process.argv));
8694
}
95+
*/
8796

8897
/**
8998
* @param {array} params
9099
*/
91100
module.exports.parse = (params) => {
92101
if (params.length < 3) {
93-
console.log("helpText");
94102
helpText();
95103

96104
} else {

functions/videoLinks.js

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
1-
var fs = require('fs');
2-
3-
var myJSON;
4-
const EXTRACT_ALL = false;
5-
6-
try {
7-
myJSON = JSON.parse(fs.readFileSync("./app.pluralsight.com_video.har"));
8-
} catch (err) {
9-
console.log(err.message);
10-
}
11-
12-
myJSON.log.entries.forEach((element, index) => {
13-
if (element.request.url == "https://app.pluralsight.com/video/clips/v3/viewclip") {
14-
var videoJSON = JSON.parse(element.response.content.text);
15-
16-
if (!EXTRACT_ALL) {
17-
// Extract first URL
18-
console.log(videoJSON.urls[0].url);
19-
20-
} else {
21-
// Extract all possible URLs
22-
videoJSON.urls.forEach((element, index) => {
23-
console.log(element.url);
24-
});
25-
26-
}
27-
1+
/**
2+
*
3+
* @param {Object} linkJSON - JSON containing all video links.
4+
* @param {boolean} extractAll - Whether to output all possible URLs
5+
*/
6+
function getURLs(linkJSON, extractAll = false){
7+
var text = "";
8+
if(!extractAll){
9+
text += linkJSON.urls[0].url;
10+
} else {
11+
console.log("Extracting all URLs.");
12+
linkJSON.urls.forEach((element, index) => {
13+
text += element.url;
14+
})
2815
}
29-
});
3016

17+
return text;
18+
}
3119

20+
/**
21+
* @param {Object} linkJSON - JSON containing all video links.
22+
*/
23+
module.exports.urls = (videoJSON) => {
24+
return new Promise((resolve, reject) => {
25+
resolve(getURLs(videoJSON));
26+
})
27+
}

main.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const transcript = require("./functions/transcript.js");
22
const courseInfo = require("./functions/courseinfo.js");
3-
const paramProcessor = require("./functions/paramProcessor.js")
3+
const paramProcessor = require("./functions/paramProcessor.js");
4+
const videoLinks = require("./functions/videoLinks.js");
45
const fs = require("fs");
56

67
var myJSON;
@@ -41,13 +42,13 @@ if (!params.noSubs) {
4142
} catch (err) {
4243
console.log(err.message);
4344
console.log("If you see this its probably because the HAR file you provided does not have a transcript, or that the format has changed.");
44-
console.log("If you are sure that the format has changed, please open an issue here: https://github.com/kwongtn/CourseExtractor/issues");
45+
console.log("If you are sure that the format has changed, please attach your HAL file and open an issue here: https://github.com/kwongtn/CourseExtractor/issues");
4546
}
4647
}
4748

4849
// Generate and write courseInfo to output
4950
if (!params.noInfo) {
50-
const searchString = /https:\/\/app\.pluralsight\.com\/learner\/content\/courses.*/
51+
const searchString = /https:\/\/app\.pluralsight\.com\/learner\/content\/courses.*/;
5152
var obtainedCourseInfo = false;
5253
try {
5354
myJSON.log.entries.forEach((element, index) => {
@@ -71,14 +72,14 @@ if (!params.noInfo) {
7172
} catch (err){
7273
console.log(err.message);
7374
console.log("If you see this its probably because the HAR file you provided does not have course info, or that the format has changed.");
74-
console.log("If you are sure that the format has changed, please open an issue here: https://github.com/kwongtn/CourseExtractor/issues")
75+
console.log("If you are sure that the format has changed, please attach your HAL file and open an issue here: https://github.com/kwongtn/CourseExtractor/issues");
7576
}
7677

7778
}
7879

7980
// Generate and write course bb code to output
8081
if (!params.noBB) {
81-
const searchString = /https:\/\/app\.pluralsight\.com\/learner\/content\/courses.*/
82+
const searchString = /https:\/\/app\.pluralsight\.com\/learner\/content\/courses.*/;
8283
var obtainedCourseInfoBb = false;
8384
try{
8485
myJSON.log.entries.forEach((element, index) => {
@@ -102,6 +103,34 @@ if (!params.noBB) {
102103
} catch (err){
103104
console.log(err.message);
104105
console.log("If you see this its probably because the HAR file you provided does not have course info, or that the format has changed.");
105-
console.log("If you are sure that the format has changed, please open an issue here: https://github.com/kwongtn/CourseExtractor/issues")
106+
console.log("If you are sure that the format has changed, please attach your HAL file and open an issue here: https://github.com/kwongtn/CourseExtractor/issues");
106107
}
107108
}
109+
110+
// Generate and write video URLs to output
111+
if(!params.noVideo){
112+
const searchString = /https:\/\/app.pluralsight.com\/video\/clips\/v3\/viewclip.*/;
113+
try{
114+
myJSON.log.entries.forEach((element, index) => {
115+
if (searchString.test(element.request.url)) {
116+
const passedJSON = JSON.parse(element.response.content.text);
117+
videoLinks.urls(passedJSON).then((output) => {
118+
try {
119+
fs.writeFileSync("./output/urls.txt", output);
120+
console.log("Completed url output.");
121+
} catch (err) {
122+
console.log(err);
123+
return false;
124+
}
125+
126+
return true;
127+
});
128+
}
129+
})
130+
} catch (err) {
131+
console.log(err.message);
132+
console.log("If you see this its probably because the HAR file you provided does not have video URLs, or that the format has changed.");
133+
console.log("If you are sure that the format has changed, please attach your HAL file and open an issue here: https://github.com/kwongtn/CourseExtractor/issues");
134+
}
135+
136+
}

0 commit comments

Comments
 (0)