mirror of https://github.com/Kylart/KawAnime.git
Methods magnet2File completed, going to impletement getMagnets button
This commit is contained in:
parent
34a75fbe68
commit
078be38174
|
@ -185,15 +185,24 @@ body
|
||||||
width: 24%;
|
width: 24%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#download-button .md-button
|
.download-button .md-button
|
||||||
{
|
{
|
||||||
background-color: rgba(40, 40, 40, 0.8);
|
|
||||||
margin-top: 15%;
|
margin-top: 15%;
|
||||||
color: rgba(255, 255, 255, 0.8);
|
color: rgba(255, 255, 255, 0.8);
|
||||||
margin-right: 3%;
|
margin-right: 3%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#download-button h6
|
#downloader-button
|
||||||
|
{
|
||||||
|
background-color: rgba(40, 40, 40, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
#magnet-downloader-button
|
||||||
|
{
|
||||||
|
background-color: rgba(40, 40, 40, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.download-button h6
|
||||||
{
|
{
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
|
|
15
index.html
15
index.html
|
@ -121,8 +121,19 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mdl-grid">
|
<div class="mdl-grid">
|
||||||
<div class="mdl-cell mdl-cell--5-col mdl-cell--5-offset" id="download-button">
|
<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>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,9 @@
|
||||||
"mal-scraper": "^1.0.9",
|
"mal-scraper": "^1.0.9",
|
||||||
"malapi": "0.0.3",
|
"malapi": "0.0.3",
|
||||||
"node-nyaa-api": "latest",
|
"node-nyaa-api": "latest",
|
||||||
|
"parse-torrent": "^5.8.1",
|
||||||
"progressbar.js": "^1.0.1",
|
"progressbar.js": "^1.0.1",
|
||||||
"vue-material": "^0.7.1",
|
"request": "latest",
|
||||||
"request": "latest"
|
"vue-material": "^0.7.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
67
renderer.js
67
renderer.js
|
@ -14,6 +14,7 @@ const os = require('os')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const request = require('request')
|
const request = require('request')
|
||||||
const findRemoveSync = require('find-remove')
|
const findRemoveSync = require('find-remove')
|
||||||
|
const parseTorrent = require('parse-torrent')
|
||||||
|
|
||||||
// Mal API
|
// Mal API
|
||||||
const mal = require('malapi').Anime
|
const mal = require('malapi').Anime
|
||||||
|
@ -25,6 +26,7 @@ const malScraper = require('mal-scraper')
|
||||||
/* ----------------- END IMPORTS ----------------- */
|
/* ----------------- END IMPORTS ----------------- */
|
||||||
|
|
||||||
const DIR = path.join(os.userInfo().homedir, '.KawAnime')
|
const DIR = path.join(os.userInfo().homedir, '.KawAnime')
|
||||||
|
const magnetPath = path.join(DIR, 'magnets.txt')
|
||||||
|
|
||||||
const VueMaterial = require('vue-material')
|
const VueMaterial = require('vue-material')
|
||||||
|
|
||||||
|
@ -142,9 +144,6 @@ function getLatest() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a preference for
|
|
||||||
// -- Download torrent file (might have a problem when downloading several)
|
|
||||||
// -- Download magnet
|
|
||||||
function downloadFile(file_url, name) {
|
function downloadFile(file_url, name) {
|
||||||
let req = request({
|
let req = request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
@ -155,6 +154,39 @@ function downloadFile(file_url, name) {
|
||||||
req.pipe(out)
|
req.pipe(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function torrent2Magnet(torrentPath) {
|
||||||
|
const torrentFile = parseTorrent(fs.readFileSync(torrentPath))
|
||||||
|
|
||||||
|
const infoHash = torrentFile.infoHash
|
||||||
|
|
||||||
|
return parseTorrent.toMagnetURI({
|
||||||
|
infoHash: this.infoHash
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function magnet2File(torrentPath) {
|
||||||
|
const torrentFile = parseTorrent(fs.readFileSync(torrentPath))
|
||||||
|
|
||||||
|
const torrentName = torrentFile.name
|
||||||
|
|
||||||
|
// Convert to magnet
|
||||||
|
const torrentHash = parseTorrent.toMagnetURI({
|
||||||
|
infoHash: torrentFile.infoHash
|
||||||
|
})
|
||||||
|
|
||||||
|
// Write magnet on ~/KawAnime/magnets.txt
|
||||||
|
// Date
|
||||||
|
const date = new Date()
|
||||||
|
// Write name of torrent
|
||||||
|
fs.appendFileSync(magnetPath, `${date.toDateString()}: ${torrentName}`)
|
||||||
|
|
||||||
|
// Write hashCode
|
||||||
|
fs.appendFileSync(magnetPath, torrentHash)
|
||||||
|
|
||||||
|
// Blank line afterwards
|
||||||
|
fs.appendFileSync(magnetPath, '')
|
||||||
|
}
|
||||||
|
|
||||||
function startTorrent(file_url, name) {
|
function startTorrent(file_url, name) {
|
||||||
// Removing old torrents
|
// Removing old torrents
|
||||||
findRemoveSync(DIR, {extensions: ['.torrent']})
|
findRemoveSync(DIR, {extensions: ['.torrent']})
|
||||||
|
@ -312,6 +344,35 @@ let downloader = new Vue({
|
||||||
this.fromEp = ''
|
this.fromEp = ''
|
||||||
this.animeName = ''
|
this.animeName = ''
|
||||||
},
|
},
|
||||||
|
downloadMagnets: 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])
|
||||||
|
|
||||||
|
// Downloading torrent files
|
||||||
|
if (epNumber >= fromEp && epNumber <= untilEp)
|
||||||
|
downloadFile(url, path.join(DIR, `${name}.torrent`))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Here we convert the torrent files to magnets
|
||||||
|
|
||||||
|
})
|
||||||
|
},
|
||||||
animeNameNext: function () {
|
animeNameNext: function () {
|
||||||
document.getElementById('fromEp-input').focus()
|
document.getElementById('fromEp-input').focus()
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue