Added configuration file and improved agnets on downloader.

Now working on using configuration file everywhere.
This commit is contained in:
Kylart 2017-03-26 17:45:11 +02:00
parent a496c8b9e5
commit 5b85ca4a61
4 changed files with 26 additions and 4 deletions

12
main.js
View File

@ -20,6 +20,18 @@ const template = menuFile.template(() => {
})
const menu = Menu.buildFromTemplate(template)
// Checking if that config file already exists
fs.access(path.join(os.userInfo().homedir, '.KawAnime', 'config.js'), fs.constants.R_OK | fs.constants.W_OK, (err) => {
if (err) // This means the file does not exist
{
console.log('Creating initial config file.')
// Taking the template config
fs.createReadStream(path.join(__dirname, 'resources', 'initConfig.js'))
.pipe(fs.createWriteStream(path.join(os.userInfo().homedir, '.KawAnime', 'config.js')))
}
})
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow

View File

@ -30,7 +30,7 @@
"dependencies": {
"find-remove": "^1.0.0",
"is-online": "^5.2.0",
"mal-scraper": "latest",
"mal-scraper": "^1.2.0",
"malapi": "0.0.3",
"mdi": "^1.8.36",
"node-nyaa-api": "latest",

9
resources/initConfig.js Normal file
View File

@ -0,0 +1,9 @@
const os = require('os')
module.exports = {
fansub: 'HorribleSubs',
quality: '720p',
sound: 'Nyanpasu',
localPath: path.join(os.userInfo().homedir, 'Downloads'),
inside: true
}

View File

@ -94,7 +94,10 @@ exports.downloadMagnets = (object) => {
// Here we convert the torrent files to magnets
const dirFiles = fs.readdirSync(DIR)
const date = new Date()
// Grabbing all the torrents
fs.appendFileSync(path.join(DIR, 'magnets.txt'), `${date}: ${animeName} ${fromEp} - ${untilEp}\n`)
for (let i = 0; i < dirFiles.length; ++i)
{
let torrent = dirFiles[i]
@ -106,12 +109,10 @@ exports.downloadMagnets = (object) => {
const name = torrent.name
const torrentHash = torrent.infoHash
const date = new Date()
const uri = parseTorrent.toMagnetURI({infoHash: torrentHash})
fs.appendFileSync(path.join(DIR, 'magnets.txt'), `${date}: ${name}\n\t`)
fs.appendFileSync(path.join(DIR, 'magnets.txt'), `${uri}\n\n`)
fs.appendFileSync(path.join(DIR, 'magnets.txt'), `${uri}\n`)
}
}