성준영

챕터 내 모든 파일 다운로드 옵션 추가

......@@ -20,14 +20,18 @@ npm install -g klas-file-downloader
> **WARNING!!** 패스워드가 @ 이외의 특수문자를 포함하고 있다면, 패스워드 앞에 \ 를 붙여주어야 합니다.
```
[DOWNLOAD SPECIPIC CHAPTER FILES]
klasFM -i 2012104095 -p \!123123\*123
[TO DOWNLOAD ALL FILES IN LECTURE]
klasFM -i 2012104095 -p \!123123\*123 --all
```
### Options
#### Global Options
0. `-h / --help` : 도움말
1. `-i / --id` : [required] 학번
2. `-p / --pw` : [required] 비밀번호
1. `-i / --id` : **[required]** 학번
2. `-p / --pw` : **[required]** 비밀번호
3. `-d / --downloadPath` : 다운로드 받을 경로
4. `-a / --all` : 추가 시 선택한 강의의 전체 강의자료 다운로드
......
......@@ -254,6 +254,7 @@ exports.selectChapter = function (chapterFilesArr) {
exports.downloadSelectedFiles = function (selectedFiles, downloadPath) {
return new Promise(function (resolve, reject) {
if (!downloadPath) {
downloadPath = os.homedir() + '/Downloads/';
} else {
......@@ -277,3 +278,44 @@ exports.downloadSelectedFiles = function (selectedFiles, downloadPath) {
});
});
};
exports.downloadAllFiles = function (chapterFilesArr,selectLecture, downloadPath) {
return new Promise(function (resolve, reject) {
if (!downloadPath) {
downloadPath = os.homedir() + '/Downloads/';
} else {
downloadPath = require('path').resolve(downloadPath) + '/';
}
fs.mkdirSync(downloadPath + selectLecture + '/');
downloadPath += selectLecture + '/';
console.log('');
let count = 0;
chapterFilesArr.forEach(function(chapterObj, index){
var asyncDownloadPath = downloadPath + chapterObj.chapter + '/';
fs.mkdirSync(asyncDownloadPath);
var subCount = 0;
chapterObj.files.forEach(function(value, index){
request = https.get(value.link, function(response){
let file = fs.createWriteStream(asyncDownloadPath + value.fileName);
response.pipe(file);
subCount ++;
if(subCount === chapterObj.files.length){
count ++;
console.log(' 다운로드중... ('+ asyncDownloadPath +')');
if(count === chapterFilesArr.length){
resolve('\n 파일이 ' + downloadPath + ' 에 저장되었어요! 열공 :)');
}
}
})
});
});
})
};
......
......@@ -7,7 +7,7 @@ var functions = require('./functions');
//TODO 예외처리
if(require.main === module){
if (require.main === module) {
// 커멘드 라인 상에서 직접적으로 불려졌을 때
args
......@@ -25,46 +25,68 @@ if(require.main === module){
console.log(' 비밀번호(pw) 가 필요해요!');
return;
} else {
functions.login(flags.id, flags.pw)
.then(functions.getLecture)
.then(functions.getLectureLink)
.then(functions.selectLecture)
.then(functions.getClassPageBody)
.then(functions.findFiles)
.then(function(chapterFilesArr){
if(flags.all){
// TODO 전체강의 다운받는 함수 구현
} else {
return functions.selectChapter(chapterFilesArr);
}
})
.then(function(selectedFiles){
return functions.downloadSelectedFiles(selectedFiles, flags.downloadPath);
})
.then(function(result){
console.log(result);
})
.catch(function (err) {
console.log(err);
});
if (!flags.all) {
functions.login(flags.id, flags.pw)
.then(functions.getLecture)
.then(functions.getLectureLink)
.then(functions.selectLecture)
.then(functions.getClassPageBody)
.then(functions.findFiles)
.then(functions.selectChapter)
.then(function (selectedFiles) {
return functions.downloadSelectedFiles(selectedFiles, flags.downloadPath);
})
.then(function (result) {
console.log(result);
process.exit();
})
.catch(function (err) {
console.log(err);
process.exit();
});
} else {
var selectLecture;
functions.login(flags.id, flags.pw)
.then(functions.getLecture)
.then(functions.getLectureLink)
.then(functions.selectLecture)
.then(function (lectureObject) {
selectLecture = lectureObject.lectureName;
return functions.getClassPageBody(lectureObject);
})
.then(functions.findFiles)
.then(function (chapterFilesArr) {
return functions.downloadAllFiles(chapterFilesArr, selectLecture, flags.downloadPath);
})
.then(function(result){
console.log(result);
process.exit();
})
.catch(function(err){
console.log(err);
process.exit();
})
}
}
} else {
// 모듈로 불려졌을때 (준비중)
// module.exports = {
//
// getLectureList: function (id, pw, callback) {
// functions.login(id, pw)
// .then(functions.getLecture)
// .then(functions.getLectureLink)
// .then(function(lectureList){
// callback(lectureList);
// })
// }
//
// };
module.exports = {
getLectures: function (id, pw, callback) {
functions.login(id, pw)
.then(functions.getLecture)
.then(functions.getLectureLink)
.then(function (lectureList) {
callback(lectureList);
})
}
};
}
......
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/7.3.0/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'publish' ]
2 info using npm@3.10.10
3 info using node@v7.3.0
4 verbose publish [ '.' ]
5 silly cache add args [ '.', null ]
6 verbose cache add spec .
7 silly cache add parsed spec Result {
7 silly cache add raw: '.',
7 silly cache add scope: null,
7 silly cache add escapedName: null,
7 silly cache add name: null,
7 silly cache add rawSpec: '.',
7 silly cache add spec: '/Users/junyoung/Library/Mobile Documents/com~apple~CloudDocs/Junyoung/Opensource/klas-file-downloader',
7 silly cache add type: 'directory' }
8 verbose addLocalDirectory /Users/junyoung/.npm/klas-file-downloader/0.0.5/package.tgz not in flight; packing
9 verbose correctMkdir /Users/junyoung/.npm correctMkdir not in flight; initializing
10 info lifecycle klas-file-downloader@0.0.5~prepublish: klas-file-downloader@0.0.5
11 silly lifecycle klas-file-downloader@0.0.5~prepublish: no script for prepublish, continuing
12 verbose tar pack [ '/Users/junyoung/.npm/klas-file-downloader/0.0.5/package.tgz',
12 verbose tar pack '/Users/junyoung/Library/Mobile Documents/com~apple~CloudDocs/Junyoung/Opensource/klas-file-downloader' ]
13 verbose tarball /Users/junyoung/.npm/klas-file-downloader/0.0.5/package.tgz
14 verbose folder /Users/junyoung/Library/Mobile Documents/com~apple~CloudDocs/Junyoung/Opensource/klas-file-downloader
15 verbose addLocalTarball adding from inside cache /Users/junyoung/.npm/klas-file-downloader/0.0.5/package.tgz
16 verbose correctMkdir /Users/junyoung/.npm correctMkdir not in flight; initializing
17 silly cache afterAdd klas-file-downloader@0.0.5
18 verbose afterAdd /Users/junyoung/.npm/klas-file-downloader/0.0.5/package/package.json not in flight; writing
19 verbose correctMkdir /Users/junyoung/.npm correctMkdir not in flight; initializing
20 verbose afterAdd /Users/junyoung/.npm/klas-file-downloader/0.0.5/package/package.json written
21 silly publish { name: 'klas-file-downloader',
21 silly publish version: '0.0.5',
21 silly publish description: 'Project that download lecture reference files from Klas',
21 silly publish main: 'index.js',
21 silly publish scripts: { test: 'echo "Error: no test specified" && exit 1' },
21 silly publish repository:
21 silly publish { type: 'git',
21 silly publish url: 'git+https://github.com/sungjunyoung/klas-file-downloader.git' },
21 silly publish keywords: [ 'klas', 'file', 'download', 'lecture' ],
21 silly publish author: { name: 'sungjunyoung' },
21 silly publish license: 'MIT',
21 silly publish bugs: { url: 'https://github.com/sungjunyoung/klas-file-downloader/issues' },
21 silly publish bin: { klasFD: './index.js' },
21 silly publish homepage: 'https://sungjunyoung.github.io',
21 silly publish dependencies:
21 silly publish { args: '^2.4.1',
21 silly publish cheerio: '^0.22.0',
21 silly publish fs: '0.0.1-security',
21 silly publish promise: '^7.1.1',
21 silly publish querystring: '^0.2.0',
21 silly publish read: '^1.0.7',
21 silly publish request: '^2.81.0' },
21 silly publish readme: '\n> # **IN-DEVELOPING**\n\n# klas-file-downloader\n\n경희대학교 클라스의 강의실 페이지에서 강의자료를 다운받는 npm 패키지입니다.\n\n## SCREENSHOT\n\n![screenshot_1](./screenshot_1.png)\n\n## INSTALL\n\n```\nnpm install -g klas-file-downloader \n```\n\n## USAGE\n\n> **WARNING!!** 패스워드가 @ 이외의 특수문자를 포함하고 있다면, 패스워드 앞에 \\ 를 붙여주어야 합니다. \n\n```\nklasFM -i 2012104095 -p \\!123123\\*123\n```\n\n### Options\n#### Global Options\n0. `-h / --help` : 도움말\n1. `-i / --id` : [required] 학번\n2. `-p / --pw` : [required] 비밀번호\n3. `-d / --downloadPath` : 다운로드 받을 경로\n4. `-a / --all` : 추가 시 선택한 강의의 전체 강의자료 다운로드\n\n\n---\nMIT License\n\nCopyright (c) 2017 Junyoung, Sung\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n',
21 silly publish readmeFilename: 'README.md',
21 silly publish gitHead: '107c874cc243910fc9f3c28f8f58fa557b0069ed',
21 silly publish _id: 'klas-file-downloader@0.0.5',
21 silly publish _shasum: '3c64bf6ddbdcfc891a0fad554f4d961d0a9c6ad5',
21 silly publish _from: '.' }
22 verbose getPublishConfig undefined
23 silly mapToRegistry name klas-file-downloader
24 silly mapToRegistry using default registry
25 silly mapToRegistry registry https://registry.npmjs.org/
26 silly mapToRegistry data Result {
26 silly mapToRegistry raw: 'klas-file-downloader',
26 silly mapToRegistry scope: null,
26 silly mapToRegistry escapedName: 'klas-file-downloader',
26 silly mapToRegistry name: 'klas-file-downloader',
26 silly mapToRegistry rawSpec: '',
26 silly mapToRegistry spec: 'latest',
26 silly mapToRegistry type: 'tag' }
27 silly mapToRegistry uri https://registry.npmjs.org/klas-file-downloader
28 verbose publish registryBase https://registry.npmjs.org/
29 silly publish uploading /Users/junyoung/.npm/klas-file-downloader/0.0.5/package.tgz
30 verbose request uri https://registry.npmjs.org/klas-file-downloader
31 verbose request sending authorization for write operation
32 info attempt registry request try #1 at 3:52:14 PM
33 verbose request using bearer token for auth
34 verbose request id c0fe05e280b6f818
35 http request PUT https://registry.npmjs.org/klas-file-downloader
36 http 403 https://registry.npmjs.org/klas-file-downloader
37 verbose headers { 'content-type': 'application/json',
37 verbose headers 'cache-control': 'max-age=300',
37 verbose headers 'content-length': '95',
37 verbose headers 'accept-ranges': 'bytes',
37 verbose headers date: 'Tue, 30 May 2017 06:52:19 GMT',
37 verbose headers via: '1.1 varnish',
37 verbose headers connection: 'keep-alive',
37 verbose headers 'x-served-by': 'cache-nrt6135-NRT',
37 verbose headers 'x-cache': 'MISS',
37 verbose headers 'x-cache-hits': '0',
37 verbose headers 'x-timer': 'S1496127136.831263,VS0,VE3712',
37 verbose headers vary: 'Accept-Encoding' }
38 verbose request invalidating /Users/junyoung/.npm/registry.npmjs.org/klas-file-downloader on PUT
39 error publish Failed PUT 403
40 verbose stack Error: "You cannot publish over the previously published version 0.0.5." : klas-file-downloader
40 verbose stack at makeError (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:302:12)
40 verbose stack at CachingRegistryClient.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:290:14)
40 verbose stack at Request._callback (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:210:14)
40 verbose stack at Request.self.callback (/usr/local/lib/node_modules/npm/node_modules/request/request.js:187:22)
40 verbose stack at emitTwo (events.js:106:13)
40 verbose stack at Request.emit (events.js:191:7)
40 verbose stack at Request.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/request/request.js:1048:10)
40 verbose stack at emitOne (events.js:96:13)
40 verbose stack at Request.emit (events.js:188:7)
40 verbose stack at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/request/request.js:969:12)
41 verbose statusCode 403
42 verbose pkgid klas-file-downloader
43 verbose cwd /Users/junyoung/Library/Mobile Documents/com~apple~CloudDocs/Junyoung/Opensource/klas-file-downloader
44 error Darwin 16.6.0
45 error argv "/usr/local/Cellar/node/7.3.0/bin/node" "/usr/local/bin/npm" "publish"
46 error node v7.3.0
47 error npm v3.10.10
48 error code E403
49 error "You cannot publish over the previously published version 0.0.5." : klas-file-downloader
50 error If you need help, you may report this error at:
50 error <https://github.com/npm/npm/issues>
51 verbose exit [ 1, true ]
{
"name": "klas-file-downloader",
"version": "0.0.5",
"version": "0.1.5",
"description": "Project that download lecture reference files from Klas",
"main": "index.js",
"scripts": {
......