mirror of https://github.com/Kylart/KawAnime.git
Downloader page's code is now in its directory.
This commit is contained in:
parent
38ab228a43
commit
c88e5690ab
97
index.html
97
index.html
|
@ -21,7 +21,7 @@
|
|||
</button>
|
||||
</div>
|
||||
|
||||
<div id="container" style="display: none;">
|
||||
<div id="container" >
|
||||
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer
|
||||
mdl-layout--fixed-header">
|
||||
<header class="mdl-layout__header">
|
||||
|
@ -54,100 +54,9 @@
|
|||
</div>
|
||||
<main class="mdl-layout__content">
|
||||
<div class="page-content">
|
||||
<div id="download-container"
|
||||
v-if="show"
|
||||
<div id="download-container" v-if="show"
|
||||
v-bind:style="{ display: display }">
|
||||
<div id="footer-back-left"></div>
|
||||
<div id="footer-back-right"></div>
|
||||
|
||||
<div class="downloader-header"></div>
|
||||
<div class="mdl-grid mdl-layout__content mdl-typography--text-center downloader-form-container">
|
||||
<div class="dummy-cell mdl-cell mdl-cell--12-col"></div>
|
||||
<div class="mdl-cell mdl-cell--12-col">
|
||||
<form novalidate @submit.stop.prevent="animeNameNext">
|
||||
<md-input-container id="anime-name" class="downloader-input">
|
||||
<label><p>Name of the anime...</p></label>
|
||||
<md-input autofocus v-model="animeName" id="animeName-input"
|
||||
style="color: rgba(255, 255, 255, 0.8);text-shadow: 0 0 0 rgba(255, 255, 255, 0.8); "></md-input>
|
||||
</md-input-container>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="mdl-cell mdl-cell--12-col">
|
||||
<form novalidate @submit.stop.prevent="fromEpNext" @keydown.delete="fromEpPrevious">
|
||||
<md-input-container id="fromEp" class="downloader-input">
|
||||
<label><p>From episode...</p></label>
|
||||
<md-input type="number"
|
||||
v-model="fromEp"
|
||||
id="fromEp-input"
|
||||
style="text-shadow: 0 0 0 rgba(255, 255, 255, 0.8)"></md-input>
|
||||
</md-input-container>
|
||||
</form>
|
||||
</div>
|
||||
<div class="mdl-cell mdl-cell--12-col">
|
||||
<form novalidate @submit.stop.prevent="untilEpNext" @keydown.delete="untilEpPrevious">
|
||||
<md-input-container id="untilEp" class="downloader-input">
|
||||
<label><p>Until episode...</p></label>
|
||||
<md-input type="number"
|
||||
v-model="untilEp"
|
||||
id="untilEp-input"
|
||||
style="text-shadow: 0 0 0 rgba(255, 255, 255, 0.8)"></md-input>
|
||||
</md-input-container>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="mdl-cell mdl-cell--12-col">
|
||||
<md-theme md-name="radio">
|
||||
<div class="mdl-grid">
|
||||
<div class="mdl-cell mdl-cell--4-col">
|
||||
<md-radio v-model="quality"
|
||||
id="480p"
|
||||
name="480p"
|
||||
md-value="480p"><h6>480p</h6>
|
||||
</md-radio>
|
||||
</div>
|
||||
<div class="mdl-cell mdl-cell--4-col">
|
||||
<md-radio v-model="quality"
|
||||
id="720p"
|
||||
name="720p"
|
||||
md-value="720p"><h6>720p</h6>
|
||||
</md-radio>
|
||||
</div>
|
||||
<div class="mdl-cell mdl-cell--4-col">
|
||||
<md-radio v-model="quality"
|
||||
id="1080p"
|
||||
name="1080p"
|
||||
md-value="1080p"><h6>1080p</h6>
|
||||
</md-radio>
|
||||
</div>
|
||||
</div>
|
||||
</md-theme>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mdl-grid">
|
||||
<div class="mdl-cell mdl-cell--3-col mdl-cell--3-offset download-button">
|
||||
<md-button id="downloader-button"
|
||||
class="md-raised"
|
||||
@click.native="download()">
|
||||
<h6>Download!</h6>
|
||||
</md-button>
|
||||
</div>
|
||||
<div class="mdl-cell mdl-cell--3-col download-button">
|
||||
<md-button id="magnet-downloader-button"
|
||||
class="md-raised"
|
||||
@click.native="downloadMagnets()">
|
||||
<h6>Get Magnets!</h6>
|
||||
</md-button>
|
||||
</div>
|
||||
<div class="mdl-cell mdl-cell--12-col">
|
||||
<md-snackbar :md-position="vertical + ' ' + horizontal" ref="snackbar" :md-duration="duration">
|
||||
<span>Your magnets are ready, you can open them </span>
|
||||
<md-button class="md-accent"
|
||||
md-theme="light-blue"
|
||||
@click.native="openMagnets()">Here!</md-button>
|
||||
</md-snackbar>
|
||||
</div>
|
||||
</div>
|
||||
<downloader></downloader>
|
||||
</div>
|
||||
<div id="releases" class="mdl-grid" v-if="show">
|
||||
<template v-for="release in releases">
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
|
@ -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 = `<div>
|
||||
<div id="footer-back-left"></div>
|
||||
<div id="footer-back-right"></div>
|
||||
|
||||
<div class="downloader-header"></div>
|
||||
<div class="mdl-grid mdl-layout__content mdl-typography--text-center downloader-form-container">
|
||||
<div class="dummy-cell mdl-cell mdl-cell--12-col"></div>
|
||||
<div class="mdl-cell mdl-cell--12-col">
|
||||
<form novalidate @submit.stop.prevent="animeNameNext">
|
||||
<md-input-container id="anime-name" class="downloader-input">
|
||||
<label><p>Name of the anime...</p></label>
|
||||
<md-input autofocus v-model="animeName" id="animeName-input"
|
||||
style="color: rgba(255, 255, 255, 0.8);text-shadow: 0 0 0 rgba(255, 255, 255, 0.8); "></md-input>
|
||||
</md-input-container>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="mdl-cell mdl-cell--12-col">
|
||||
<form novalidate @submit.stop.prevent="fromEpNext" @keydown.delete="fromEpPrevious">
|
||||
<md-input-container id="fromEp" class="downloader-input">
|
||||
<label><p>From episode...</p></label>
|
||||
<md-input type="number"
|
||||
v-model="fromEp"
|
||||
id="fromEp-input"
|
||||
style="text-shadow: 0 0 0 rgba(255, 255, 255, 0.8)"></md-input>
|
||||
</md-input-container>
|
||||
</form>
|
||||
</div>
|
||||
<div class="mdl-cell mdl-cell--12-col">
|
||||
<form novalidate @submit.stop.prevent="untilEpNext" @keydown.delete="untilEpPrevious">
|
||||
<md-input-container id="untilEp" class="downloader-input">
|
||||
<label><p>Until episode...</p></label>
|
||||
<md-input type="number"
|
||||
v-model="untilEp"
|
||||
id="untilEp-input"
|
||||
style="text-shadow: 0 0 0 rgba(255, 255, 255, 0.8)"></md-input>
|
||||
</md-input-container>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="mdl-cell mdl-cell--12-col">
|
||||
<md-theme md-name="radio">
|
||||
<div class="mdl-grid">
|
||||
<div class="mdl-cell mdl-cell--4-col">
|
||||
<md-radio v-model="quality"
|
||||
id="480p"
|
||||
name="480p"
|
||||
md-value="480p"><h6>480p</h6>
|
||||
</md-radio>
|
||||
</div>
|
||||
<div class="mdl-cell mdl-cell--4-col">
|
||||
<md-radio v-model="quality"
|
||||
id="720p"
|
||||
name="720p"
|
||||
md-value="720p"><h6>720p</h6>
|
||||
</md-radio>
|
||||
</div>
|
||||
<div class="mdl-cell mdl-cell--4-col">
|
||||
<md-radio v-model="quality"
|
||||
id="1080p"
|
||||
name="1080p"
|
||||
md-value="1080p"><h6>1080p</h6>
|
||||
</md-radio>
|
||||
</div>
|
||||
</div>
|
||||
</md-theme>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mdl-grid">
|
||||
<div class="mdl-cell mdl-cell--3-col mdl-cell--3-offset download-button">
|
||||
<md-button id="downloader-button"
|
||||
class="md-raised"
|
||||
@click.native="download()">
|
||||
<h6>Download!</h6>
|
||||
</md-button>
|
||||
</div>
|
||||
<div class="mdl-cell mdl-cell--3-col download-button">
|
||||
<md-button id="magnet-downloader-button"
|
||||
class="md-raised"
|
||||
@click.native="downloadMagnets()">
|
||||
<h6>Get Magnets!</h6>
|
||||
</md-button>
|
||||
</div>
|
||||
<div class="mdl-cell mdl-cell--12-col">
|
||||
<md-snackbar :md-position="vertical + ' ' + horizontal" ref="snackbar" :md-duration="duration">
|
||||
<span>Your magnets are ready, you can open them </span>
|
||||
<md-button class="md-accent"
|
||||
md-theme="light-blue"
|
||||
@click.native="openMagnets()">Here!</md-button>
|
||||
</md-snackbar>
|
||||
</div>
|
||||
</div>
|
||||
</div>`
|
||||
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
})
|
133
src/renderer.js
133
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()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue