forked from RobK/photobox-downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphotobox-dl.js
125 lines (118 loc) · 3.58 KB
/
photobox-dl.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env node
/**
* PhotoBox Downloader
*
* MIT License (see license file)
* Copyright 2016 - Robert Kehoe
*/
"use strict";
var prompt = require('prompt');
var path = require('path');
var about = require('./package.json');
var program = require('commander');
var winston = require('winston');
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)()
],
level: 'error',
colorize: true
});
program
.version(about.version)
.option('-d, --debug', 'Output a lot of debug information', false)
.parse(process.argv);
prompt.message = ''.green;
prompt.delimiter = ':'.green;
prompt.start();
console.log('\x1b[33m===========================================================================');
if (program.debug) {
console.log(' DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG');
logger.level = 'debug';
}
console.log('\x1b[37m\x1b[1m', 'PhotoBox Downloader v' + about.version);
console.log(' Copyright 2016 - Robert Kehoe - MIT Licensed');
console.log('\x1b[0m\x1b[33m===========================================================================\n');
console.log('\x1b[0mThis tool will download all your photos from your Photobox account.');
console.log('Usage instructions at: https://github.com/RobK/photobox-downloader\n\n');
prompt.get([
{
properties : {
domain : {
description : 'Photobox domain'.green,
default : 'www.photobox.ie'
}
}
}, {
properties : {
cookie : {
description : 'Authentication Cookie'.green,
pattern: /^[a-f0-9]{32}$/,
message: 'Authentication Cookie must be only numbers, (hex) letters and be exactly 32 characters long',
required: true
}
}
}, {
properties : {
outputPath : {
description : 'Folder where to save albums'.green,
default : 'albums'
}
}
}, {
properties : {
skipExisting : {
description : 'Skip (don\'t download) existing files'.green,
type : 'boolean',
default : true
}
}
}, {
properties : {
album : {
description : 'Album name (blank for all)'.green,
default : ''
}
}
}
], function (err, result) {
//var photoBox = require('photobox-downloader');
var photoBox = require('./lib/photobox')(logger);
var config = {
'baseDomain' : result.domain,
'authCookieValue' : result.cookie
};
var showProgress = (program.debug) ? false : true // disable progress in debug mode
photoBox.login(config, function (err) {
if (err) {
logger.error('ERROR! Something went wrong logging in, check your authCookieValue!');
logger.error(err);
} else {
logger.debug('Successfully logged into photobox!')
var outputDir = '';
if (path.isAbsolute(result.outputPath)) {
outputDir = result.outputPath;
} else {
outputDir = path.join(process.cwd(), result.outputPath);
}
console.log('Logged into Photobox!');
console.log('Starting to download all albums and photos to:\x1b[37m\x1b[1m', outputDir, '\x1b[0m');
photoBox.downloadAll(
{
showProgress : showProgress,
outputDir : outputDir,
skipExisting : result.skipExisting,
album : result.album
},
function (err) {
if (err) {
logger.error('Error encountered while downloading all the photos!');
logger.error(err);
} else {
console.log('Finished, all photos have been downloaded (that was easy!)');
}
}
);
}
});
});