-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 480p
-
-
-
- 720p
-
-
-
- 1080p
-
-
+
-
-
-
- Your magnets are ready, you can open them
- Here!
-
-
-
diff --git a/src/downloader/functions.js b/src/downloader/functions.js
index 20b07ac..ca7d938 100644
--- a/src/downloader/functions.js
+++ b/src/downloader/functions.js
@@ -1,8 +1,126 @@
/**
* Created by Kylart on 01/03/2017.
*
- * In this file, all the functions needed by the downloader page
+ * In object file, all the functions needed by the downloader page
* are present. This is for cleaner code.
*
*/
+// Those are needed to download the torrents
+const fs = require('fs')
+const path = require('path')
+const req = require('request')
+const request = require('request')
+const findRemoveSync = require('find-remove')
+const parseTorrent = require('parse-torrent')
+
+// Nyanpasu ~
+const player = require('play-sound')(opts = {})
+
+// Nyaa API
+const Nyaa = require('node-nyaa-api')
+
+const os = require('os')
+const DIR = path.join(os.userInfo().homedir, '.KawAnime')
+
+const downloadFile= (file_url, name) => {
+ let req = request({
+ method: 'GET',
+ uri: file_url
+ })
+
+ let out = fs.createWriteStream(path.join(DIR, `${name}.torrent`))
+ req.pipe(out)
+}
+
+exports.download = (object) => {
+ console.log(`Retrieving ${object.animeName} from ${object.fromEp} to ${object.untilEp}...`)
+
+ const quality = object.quality
+ const animeName = object.animeName
+ const fromEp = object.fromEp
+ const untilEp = object.untilEp
+
+ Nyaa.search(`[HorribleSubs] ${quality} ${animeName}`, (err, articles) => {
+ if (err) throw err
+
+ let animes = []
+
+ for (let article in articles)
+ animes.push(articles[article])
+
+ animes.forEach((elem) => {
+ const url = elem.link
+ const epNumber = parseInt(elem.title.split(' ').reverse()[1])
+
+ if (epNumber >= fromEp && epNumber <= untilEp)
+ window.open(`${url}&magnet=1`)
+ })
+ })
+}
+
+exports.downloadMagnets = (object) => {
+ console.log(`Retrieving ${object.animeName} from ${object.fromEp} to ${object.untilEp}...`)
+
+ // Removing old torrents
+ findRemoveSync(DIR, {extensions: ['.torrent']})
+
+ const quality = object.quality
+ const animeName = object.animeName
+ const fromEp = object.fromEp
+ const untilEp = object.untilEp
+
+ // TODO : Need to make only 10 by 10 downloads
+ Nyaa.search(`[HorribleSubs] ${quality} ${animeName}`, (err, articles) => {
+ if (err) throw err
+
+ let animes = []
+
+ for (let article in articles)
+ animes.push(articles[article])
+
+ animes.forEach((elem) => {
+ const url = elem.link
+ const epNumber = parseInt(elem.title.split(' ').reverse()[1])
+ const name = elem.title.split(' ').slice(0, -1).join(' ')
+
+ // Downloading torrent files
+ if (epNumber >= fromEp && epNumber <= untilEp)
+ downloadFile(url, name) // TODO : implement a method to know when the files are done downloading
+ })
+
+ // Need to wait for the downloads to be over
+ setTimeout(() => {
+ // Here we convert the torrent files to magnets
+ const dirFiles = fs.readdirSync(DIR)
+
+ // Grabbing all the torrents
+ for (let i = 0; i < dirFiles.length; ++i)
+ {
+ let torrent = dirFiles[i]
+ if (path.extname(torrent) === '.torrent')
+ {
+ const file = fs.readFileSync(path.join(DIR, dirFiles[i]))
+
+ const torrent = parseTorrent(file)
+
+ 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`)
+ }
+ }
+
+ object.openSnackbar()
+
+ // Nyanpasu! ~
+ player.play(path.join(__dirname, '..', '..', 'resources', 'Nyanpasu.m4a'), (err) => {
+ if (err) throw err
+ })
+ }, 600 + (untilEp - fromEp) * 100)
+ })
+}
\ No newline at end of file
diff --git a/src/downloader/index.js b/src/downloader/index.js
index 5fa3cdb..72d8f81 100644
--- a/src/downloader/index.js
+++ b/src/downloader/index.js
@@ -5,3 +5,162 @@
* of the downloader.
*
*/
+
+// To open files
+const shell = require('electron').shell
+const path = require('path')
+const fs = require('fs')
+const os = require('os')
+
+const DIR = path.join(os.userInfo().homedir, '.KawAnime')
+
+const functions = require('./functions.js')
+
+const html = `
+
+
+
+
+
`
+
+
+Vue.component('downloader', {
+ template: html,
+ data: function () {
+ return {
+ display: "none",
+ quality: '720p',
+ animeName: '',
+ fromEp: '',
+ untilEp: '',
+ vertical: 'top',
+ horizontal: 'center',
+ duration: '4000'
+ }
+ },
+ methods: {
+ download: function () {
+ functions.download(this)
+
+ this.untilEp = ''
+ this.fromEp = ''
+ this.animeName = ''
+ },
+ downloadMagnets: function () {
+ functions.downloadMagnets(this)
+ },
+ openSnackbar: function () {
+ this.$refs.snackbar.open();
+ },
+ openMagnets: function () {
+ this.$refs.snackbar.close()
+
+ shell.openItem(path.join(DIR, 'magnets.txt'))
+ },
+ animeNameNext: function () {
+ document.getElementById('fromEp-input').focus()
+ },
+ fromEpNext: function () {
+ document.getElementById('untilEp-input').focus()
+ },
+ untilEpNext: function () {
+ document.getElementById('animeName-input').focus()
+ document.getElementById('downloader-button').click()
+ },
+ fromEpPrevious: function () {
+ if (this.fromEp === '')
+ document.getElementById('animeName-input').focus()
+ },
+ untilEpPrevious: function () {
+ if (this.untilEp === '')
+ document.getElementById('fromEp-input').focus()
+ }
+ }
+})
\ No newline at end of file
diff --git a/src/renderer.js b/src/renderer.js
index 8b6b37e..726002f 100644
--- a/src/renderer.js
+++ b/src/renderer.js
@@ -26,6 +26,10 @@ const malScraper = require('mal-scraper')
const DIR = path.join(os.userInfo().homedir, '.KawAnime')
const magnetPath = path.join(DIR, 'magnets.txt')
+/* ----------------- VUE IMPORTS ----------------- */
+
+require(path.join(__dirname, 'downloader', 'index.js'))
+
const VueMaterial = require('vue-material')
Vue.use(VueMaterial)
@@ -283,135 +287,6 @@ let downloader = new Vue({
data: {
show: false,
display: "none",
- quality: '720p',
- animeName: '',
- fromEp: '',
- untilEp: '',
- vertical: 'top',
- horizontal: 'center',
- duration: '4000'
- },
- methods: {
- download: function () {
- console.log(`Retrieving ${this.animeName} from ${this.fromEp} to ${this.untilEp}...`)
-
- const quality = this.quality
- const animeName = this.animeName
- const fromEp = this.fromEp
- const untilEp = this.untilEp
-
- Nyaa.search(`[HorribleSubs] ${quality} ${animeName}`, (err, articles) => {
- if (err) throw err
-
- let animes = []
-
- for (let article in articles)
- animes.push(articles[article])
-
- animes.forEach((elem) => {
- const url = elem.link
- const epNumber = parseInt(elem.title.split(' ').reverse()[1])
-
- if (epNumber >= fromEp && epNumber <= untilEp)
- window.open(`${url}&magnet=1`)
- })
- })
-
- this.untilEp = ''
- this.fromEp = ''
- this.animeName = ''
- },
- downloadMagnets: function () {
- console.log(`Retrieving ${this.animeName} from ${this.fromEp} to ${this.untilEp}...`)
-
- // Removing old torrents
- findRemoveSync(DIR, {extensions: ['.torrent']})
-
- const quality = this.quality
- const animeName = this.animeName
- const fromEp = this.fromEp
- const untilEp = this.untilEp
-
- // TODO : Need to make only 10 by 10 downloads
- Nyaa.search(`[HorribleSubs] ${quality} ${animeName}`, (err, articles) => {
- if (err) throw err
-
- let animes = []
-
- for (let article in articles)
- animes.push(articles[article])
-
- animes.forEach((elem) => {
- const url = elem.link
- const epNumber = parseInt(elem.title.split(' ').reverse()[1])
- const name = elem.title.split(' ').slice(0, -1).join(' ')
-
- // Downloading torrent files
- if (epNumber >= fromEp && epNumber <= untilEp)
- downloadFile(url, name) // TODO : implement a method to know when the files are done downloading
- })
-
- // Need to wait for the downloads to be over
- setTimeout(() => {
- // Here we convert the torrent files to magnets
- const dirFiles = fs.readdirSync(DIR)
-
- // Grabbing all the torrents
- for (let i = 0; i < dirFiles.length; ++i)
- {
- let torrent = dirFiles[i]
- if (path.extname(torrent) === '.torrent')
- {
- const file = fs.readFileSync(path.join(DIR, dirFiles[i]))
-
- const torrent = parseTorrent(file)
-
- 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`)
- }
- }
-
- this.openSnackbar()
-
- // Nyanpasu! ~
- player.play(path.join(__dirname, '..', 'resources', 'Nyanpasu.m4a'), (err) => {
- if (err) throw err
- })
- }, 600 + (untilEp - fromEp) * 100)
- })
- },
- openSnackbar: function () {
- this.$refs.snackbar.open();
- },
- openMagnets: function () {
- this.$refs.snackbar.close()
-
- shell.openItem(path.join(DIR, 'magnets.txt'))
- },
- animeNameNext: function () {
- document.getElementById('fromEp-input').focus()
- },
- fromEpNext: function () {
- document.getElementById('untilEp-input').focus()
- },
- untilEpNext: function () {
- document.getElementById('animeName-input').focus()
- document.getElementById('downloader-button').click()
- },
- fromEpPrevious: function () {
- if (this.fromEp === '')
- document.getElementById('animeName-input').focus()
- },
- untilEpPrevious: function () {
- if (this.untilEp === '')
- document.getElementById('fromEp-input').focus()
- }
}
})
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 480p
+
+
+
+ 720p
+
+
+
+ 1080p
+
+
+
+
+
+
+ Your magnets are ready, you can open them
+ Here!
+
+
+