-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathignore.js
85 lines (69 loc) · 1.76 KB
/
ignore.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
/*
ignore multiple pids by adding them to the download cache
*/
var http = require('http');
var fs = require('fs');
var giUtils = require('./giUtils');
var getopt = require('node-getopt');
var download_history = [];
var newstr = [];
var options = {};
var dlh_locn;
var add_entry = function(ep) {
if (giUtils.binarySearch(download_history,ep.pid)<0) {
entry = ep.pid+'|';
if (newstr.indexOf(entry)<0) {
entry+=ep.title+'|';
if ((ep.programme) && (ep.programme.title)) {
entry += ep.programme.title+'|';
}
newstr.push(entry);
}
}
};
//-----------------------------------------------------------------------------
function update(pid,quick) {
obj = [];
obj.pid = pid; // create a programme object stub
obj.type = 'toplevel';
obj.title = '';
add_entry(obj);
}
//-----------------------------------------------------------------------------
function append_newstr() {
if (newstr.length>0) {
console.log('Writing '+newstr.length+' entries');
entry_str = '';
for (var i in newstr) {
entry_str += newstr[i]+'\n';
}
dlh_fh = fs.openSync(dlh_locn,'a');
fs.appendFileSync(dlh_locn, entry_str, 'utf8');
fs.closeSync(dlh_fh);
}
}
//-----------------------------------------------------------------------------
var quick = true;
options = getopt.create([
['q','quick','Add pid without looking it up. Now always true'],
['h','help','Display this help']
]);
options.bindHelp();
options.on('quick',function(){
quick = true;
});
var o = options.parseSystem();
var config = require('./config.json');
dlh_locn = config.download_history;
download_history = giUtils.downloadHistory(dlh_locn);
if (o.argv.length>0) {
for (var i in o.argv) {
update(o.argv[i],quick);
}
}
else {
options.showHelp();
}
process.on('exit', function(code) {
append_newstr();
});