-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (73 loc) · 2.31 KB
/
index.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
// @ts-check
const fs = require('fs');
const path = require('path');
const request = require('request-promise-native');
const Addic7ed = require('./src/addic7ed');
const Shows = require('./src/shows');
const folders = {
config: '/config'
};
let config = {
media: '.',
language: 'fr',
notifications: {}
};
(async () => {
if (!fs.existsSync(folders.config)) folders.config = '.';
const configpath = path.join(folders.config, 'config.json');
const json = await fs.promises.readFile(configpath, 'utf8');
config = JSON.parse(json);
config.path = folders.config;
const videos = await Shows.getMissing(config.media);
console.log(`${videos.length} videos without subtitles`);
// await fs.promises.writeFile('dev-videos.json', JSON.stringify(videos), 'utf8');
const downloaded = [];
if (videos.length > 0) {
const addic7ed = new Addic7ed(config);
const available = await addic7ed.getShows();
console.log(`${available.length} shows found on Addic7ed.`);
if (available.length === 0) {
console.log('No show found on Addic7ed, exiting.');
return;
}
// await fs.promises.writeFile('dev-shows.json', JSON.stringify(available), 'utf8');
for (const video of videos) {
console.log(`Finding subtitle for ${video.name}`);
const found = addic7ed.findShow(video);
if (found) {
if (await addic7ed.findMatchingEpisode(video, found)) {
if (video.parsed) {
const info = video.parsed;
downloaded.push(`${info.name} S${info.season}E${info.episode}`);
} else {
downloaded.push(video.parsedvideo.name);
}
}
} else {
console.log(` --> TV Show not found`);
}
}
}
const nb = downloaded.length;
console.log(`${nb} file${nb > 1 ? 's' : ''} downloaded.`);
if (nb > 0 && config.notifications.pushbullet) {
console.log('Sending notification');
try {
await request.post({
url: 'https://api.pushbullet.com/v2/pushes',
headers: {
'Access-Token': config.notifications.pushbullet
},
json: true,
body: {
type: 'note',
title: 'Addic7edler',
body: `${nb} file(s) downloaded.\n` + downloaded.join('\n')
}
});
} catch (e) {
console.error(e);
}
}
console.log('Done.');
})();