성준영

한글화

1 +
2 +> # **IN-DEVELOPING**
3 +
1 # klas-file-downloader 4 # klas-file-downloader
2 -Project that download lecture reference files from Klas 5 +
6 +경희대학교 클라스의 강의실 페이지에서 강의자료를 다운받는 npm 패키지입니다.
3 7
4 8
5 ## INSTALL 9 ## INSTALL
6 10
7 ``` 11 ```
8 -npm install -g klasFileDownloader 12 +npm install -g klasFileDownloader
9 ``` 13 ```
10 14
11 ## USAGE 15 ## USAGE
12 16
13 -> **WARNING!!** If your KLAS password include Exclamation mark, You must write your password like `\!`. for example, 17 +> **WARNING!!** 패스워드가 @ 이외의 특수문자를 포함하고 있다면, 패스워드 앞에 \ 를 붙여주어야 합니다.
14 - 18 +
19 +```
20 +klasFileDownloader -i 2012104095 -p \!123123\*123
15 ``` 21 ```
16 -klasFileDownloader -i 2012104095 -p \!123123\!123
17 -```
...\ No newline at end of file ...\ No newline at end of file
22 +
......
...@@ -11,7 +11,6 @@ var querystring = require('querystring'); ...@@ -11,7 +11,6 @@ var querystring = require('querystring');
11 var fs = require('fs'); 11 var fs = require('fs');
12 12
13 13
14 -
15 var j = request.jar(); 14 var j = request.jar();
16 request = request.defaults({jar: j}); 15 request = request.defaults({jar: j});
17 16
...@@ -147,7 +146,6 @@ exports.findFiles = function (classPageBody) { ...@@ -147,7 +146,6 @@ exports.findFiles = function (classPageBody) {
147 var tempFileArr = []; 146 var tempFileArr = [];
148 $(this).find('.mycl_veiw_learnig').find('.file-downbox-list').find('a').each(function (j) { 147 $(this).find('.mycl_veiw_learnig').find('.file-downbox-list').find('a').each(function (j) {
149 var link = 'https://klas.khu.ac.kr' + $(this).attr('href').split('..')[1]; 148 var link = 'https://klas.khu.ac.kr' + $(this).attr('href').split('..')[1];
150 -
151 tempFileArr.push(link); 149 tempFileArr.push(link);
152 }); 150 });
153 fileArr.push(tempFileArr); 151 fileArr.push(tempFileArr);
...@@ -157,8 +155,17 @@ exports.findFiles = function (classPageBody) { ...@@ -157,8 +155,17 @@ exports.findFiles = function (classPageBody) {
157 }) 155 })
158 }; 156 };
159 157
160 -exports.getSelectedFiles = function (fileArr, lectureBefore) { 158 +exports.getSelectedFiles = function (fileArr, lb) {
159 +
161 return new Promise(function (resolve, reject) { 160 return new Promise(function (resolve, reject) {
161 +
162 + var lectureBefore = 0;
163 + if(!lb || lb === ''){
164 + lectureBefore = 0;
165 + } else {
166 + lectureBefore = lb;
167 + }
168 +
162 var downloadIndex = fileArr.length - lectureBefore - 1; 169 var downloadIndex = fileArr.length - lectureBefore - 1;
163 170
164 if (downloadIndex < 0) { 171 if (downloadIndex < 0) {
...@@ -173,15 +180,29 @@ exports.downloadSelectedFile = function (selectedFile, path) { ...@@ -173,15 +180,29 @@ exports.downloadSelectedFile = function (selectedFile, path) {
173 180
174 return new Promise(function (resolve, reject) { 181 return new Promise(function (resolve, reject) {
175 182
183 + var downloadPath;
184 + if(!path || path === ''){
185 + downloadPath = '';
186 + //TODO Default Path 설정하기
187 + } else {
188 + downloadPath = path;
189 + //TODO 사용자가 지정한 path 리포맷하기
190 + }
191 +
192 + var count = 0;
176 selectedFile.forEach(function (value, index) { 193 selectedFile.forEach(function (value, index) {
194 +
177 request = https.get(value, function (response) { 195 request = https.get(value, function (response) {
178 - // console.log(response); 196 + count ++;
179 var file = fs.createWriteStream("./file_" + index + ".pdf"); 197 var file = fs.createWriteStream("./file_" + index + ".pdf");
180 response.pipe(file); 198 response.pipe(file);
199 +
200 + if (index === count) {
201 + resolve('done');
202 + }
203 +
181 }); 204 });
182 - if (index === count - 1) { 205 +
183 - resolve('done');
184 - }
185 }) 206 })
186 }) 207 })
187 }; 208 };
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -5,10 +5,10 @@ var functions = require('./functions'); ...@@ -5,10 +5,10 @@ var functions = require('./functions');
5 var os = require('os'); 5 var os = require('os');
6 6
7 args 7 args
8 - .option('id', 'Your Student ID of KHU, Required') 8 + .option('id', '[필수] 학번을 입력합니다.')
9 - .option('pw', 'Your Password of KHU, It is never exploited, Required') 9 + .option('pw', '[필수] 비밀번호를 입력합니다. 절대 악용되지 않습니다.')
10 - .option('lectureBefore', '0 is default, 1 2 .. wil download past lecture reference files') 10 + .option('lectureBefore', '[선택] 몇번째 전 강좌의 자료를 다운받을지 선택합니다. Default 는 0 입니다.')
11 - .option('downloadPath', 'default ~/Downlaod/Klas, will determine download location') 11 + .option('downloadPath', '[선택] 자료를 다운받을 경로를 선택합니다.');
12 12
13 const flags = args.parse(process.argv); 13 const flags = args.parse(process.argv);
14 14
...@@ -28,29 +28,10 @@ functions.login(flags.id, flags.pw) ...@@ -28,29 +28,10 @@ functions.login(flags.id, flags.pw)
28 .then(functions.getClassPageBody) 28 .then(functions.getClassPageBody)
29 .then(functions.findFiles) 29 .then(functions.findFiles)
30 .then(function (fileArr) { 30 .then(function (fileArr) {
31 - var lectureBefore; 31 + return functions.getSelectedFiles(fileArr, flags.lectureBefore);
32 - if (!flags.lectureBefore) {
33 - lectureBefore = 0;
34 - } else {
35 - lectureBefore = flags.lectureBefore;
36 - }
37 - return functions.getSelectedFiles(fileArr, lectureBefore);
38 }) 32 })
39 .then(function (selectedFile) { 33 .then(function (selectedFile) {
40 - 34 + functions.downloadSelectedFile(selectedFile, flags.downloadPath);
41 - var path;
42 - if (!flags.downloadPath) {
43 - path = os.homedir() + '/downloads/klasFileDownloader'
44 - } else {
45 - path = flags.downloadPath;
46 - }
47 - //
48 - // if (path[path.length - 1] === '/') {
49 - // path = path.substr(0, path.length - 1);
50 - // }
51 -
52 -
53 - functions.downloadSelectedFile(selectedFile, path)
54 }) 35 })
55 .catch(function (err) { 36 .catch(function (err) {
56 console.log(err); 37 console.log(err);
......