mirror of https://github.com/Kylart/KawAnime.git
Implemented download with config's fansub and ANY name with nyaapi
Fixed a bug where saved config was malformed Fixed tests
This commit is contained in:
parent
98f7f4fc8d
commit
7a350cf31d
|
@ -65,41 +65,3 @@ exports.getLatest = (url, res) => {
|
|||
res.end()
|
||||
})
|
||||
}
|
||||
|
||||
exports.download = (req, res) => {
|
||||
req.on('data', (chunk) => {
|
||||
chunk = JSON.parse(chunk)
|
||||
|
||||
console.log('[Horrible] (Download): Received a download request.')
|
||||
|
||||
const searchData = {
|
||||
quality: chunk.quality,
|
||||
name: chunk.name,
|
||||
fromEp: chunk.fromEp,
|
||||
untilEp: chunk.untilEp
|
||||
}
|
||||
|
||||
console.log(searchData)
|
||||
|
||||
// Calling api
|
||||
horribleApi.getMagnetsFromAnimeName(searchData).then((links) => {
|
||||
console.log('[Horrible] (Download): Request fulfilled!')
|
||||
|
||||
res.writeHead(200, {'Content-type': 'application/json'})
|
||||
res.write(JSON.stringify(links))
|
||||
res.end()
|
||||
}).catch((err) => {
|
||||
console.log('[Horrible] (Download): An error occurred...\n' + err)
|
||||
res.writeHead(204, {})
|
||||
res.end()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
exports.getShowsList = (res) => {
|
||||
const list = horribleApi.getShowsOnly()
|
||||
|
||||
res.writeHead(200, {'Content-type': 'application/json'})
|
||||
res.write(JSON.stringify(list))
|
||||
res.end()
|
||||
}
|
||||
|
|
|
@ -118,18 +118,10 @@ const route = (nuxt) => {
|
|||
nyaa.getLatest(url, res)
|
||||
break
|
||||
|
||||
case '/downloadNyaa':
|
||||
nyaa.download(req, res)
|
||||
break
|
||||
|
||||
case '/getLatest.json':
|
||||
horrible.getLatest(url, res)
|
||||
break
|
||||
|
||||
case '/getAllShows.json':
|
||||
horrible.getShowsList(res)
|
||||
break
|
||||
|
||||
/* istanbul ignore next */
|
||||
case '/openThis':
|
||||
openExternal(url, res)
|
||||
|
@ -140,7 +132,7 @@ const route = (nuxt) => {
|
|||
break
|
||||
|
||||
case '/download':
|
||||
horrible.download(req, res)
|
||||
nyaa.download(req, res)
|
||||
break
|
||||
|
||||
case '/news.json':
|
||||
|
|
|
@ -14,12 +14,12 @@ const sendRes = (object, res) => {
|
|||
|
||||
const download = (req, res) => {
|
||||
req.on('data', (chunk) => {
|
||||
console.log('[Nyaa] (Download): Received a download request.')
|
||||
|
||||
chunk = JSON.parse(chunk)
|
||||
|
||||
const choice = chunk.choice
|
||||
|
||||
console.log('[Nyaa] (Download): Received a download request. Choice is ' + choice)
|
||||
|
||||
const searchData = {
|
||||
quality: chunk.quality,
|
||||
name: chunk.name,
|
||||
|
@ -28,6 +28,8 @@ const download = (req, res) => {
|
|||
untilEp: chunk.untilEp
|
||||
}
|
||||
|
||||
console.log(searchData)
|
||||
|
||||
const term = `[${searchData.fansub}]+${searchData.quality}+${searchData.name}`
|
||||
|
||||
if (choice === 'si') {
|
||||
|
@ -37,7 +39,9 @@ const download = (req, res) => {
|
|||
data.forEach((elem) => {
|
||||
const ep = elem.title[0].split(' ').splice(-2, 1)[0]
|
||||
|
||||
|
||||
if (ep <= searchData.untilEp && ep >= searchData.fromEp) {
|
||||
console.log(ep)
|
||||
magnets.push(`magnet:?xt=urn:btih:${elem['nyaa:infoHash'][0]}`)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -19,16 +19,15 @@
|
|||
</div>
|
||||
</v-col>
|
||||
<v-col xs4></v-col>
|
||||
<v-col xs4>
|
||||
<v-select name="name-input"
|
||||
id="name-input"
|
||||
autocomplete
|
||||
v-bind:items="list"
|
||||
type="text"
|
||||
label="Name of the anime"
|
||||
v-model="$store.state.downloaderForm.name"
|
||||
dark>
|
||||
</v-select>
|
||||
<v-col xs4
|
||||
@keydown.enter="next(1)">
|
||||
<v-text-field name="name-input"
|
||||
type="text"
|
||||
id="name-input"
|
||||
label="Name of the anime"
|
||||
v-model="$store.state.downloaderForm.name"
|
||||
dark>
|
||||
</v-text-field>
|
||||
</v-col>
|
||||
<v-col xs4></v-col>
|
||||
<v-col xs4></v-col>
|
||||
|
@ -154,9 +153,6 @@
|
|||
computed: {
|
||||
formValues: function () {
|
||||
return this.$store.state.downloaderForm
|
||||
},
|
||||
list: function () {
|
||||
return this.$store.state.downloaderList
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -183,16 +179,16 @@
|
|||
next (number) {
|
||||
switch (number) {
|
||||
case 1:
|
||||
document.getElementsByName('input-2')[0].focus()
|
||||
document.getElementsByName('from-ep-input')[0].focus()
|
||||
break
|
||||
|
||||
case 2:
|
||||
document.getElementsByName('input-3')[0].focus()
|
||||
document.getElementsByName('until-ep-input')[0].focus()
|
||||
break
|
||||
|
||||
case 3:
|
||||
document.getElementById('download-btn').click()
|
||||
document.getElementsByName('input-1')[0].focus()
|
||||
document.getElementsByName('name-input')[0].focus()
|
||||
break
|
||||
|
||||
default:
|
||||
|
@ -202,11 +198,11 @@
|
|||
previous (number) {
|
||||
switch (number) {
|
||||
case 2:
|
||||
if (!this.formValues.fromEp) document.getElementsByName('input-1')[0].focus()
|
||||
if (!this.formValues.fromEp) document.getElementsByName('name-input')[0].focus()
|
||||
break
|
||||
|
||||
case 3:
|
||||
if (!this.formValues.untilEp) document.getElementsByName('input-2')[0].focus()
|
||||
if (!this.formValues.untilEp) document.getElementsByName('from-ep-input')[0].focus()
|
||||
break
|
||||
|
||||
default:
|
||||
|
|
|
@ -28,7 +28,6 @@ const store = new Vuex.Store({
|
|||
show: false,
|
||||
text: ''
|
||||
},
|
||||
downloaderList: [],
|
||||
downloaderForm: {
|
||||
name: '',
|
||||
fromEp: '',
|
||||
|
@ -93,10 +92,6 @@ const store = new Vuex.Store({
|
|||
setReleaseParams (state, data) {
|
||||
state.releaseParams = data
|
||||
},
|
||||
setDownloaderList (state, data) {
|
||||
state.downloaderList = data
|
||||
log(`${data.length} anime name loaded.`)
|
||||
},
|
||||
setInfoSnackbar (state, data) {
|
||||
state.infoSnackbar.text = data
|
||||
state.infoSnackbar.show = true
|
||||
|
@ -209,20 +204,14 @@ const store = new Vuex.Store({
|
|||
const {data} = await axios.get('getConfig.json')
|
||||
commit('init', data.config)
|
||||
|
||||
dispatch('downloaderInit').catch(err => { void (err) })
|
||||
dispatch('releasesInit').catch(err => { void (err) })
|
||||
dispatch('seasonsInit').catch(err => { void (err) })
|
||||
dispatch('newsInit').catch(err => { void (err) })
|
||||
// dispatch('newsInit').catch(err => { void (err) })
|
||||
dispatch('localInit').catch(err => { void (err) })
|
||||
dispatch('listInit').catch(err => { void (err) })
|
||||
dispatch('getHistory').catch(err => { void (err) })
|
||||
}
|
||||
},
|
||||
async downloaderInit ({commit}) {
|
||||
const {data} = await axios.get('getAllShows.json')
|
||||
|
||||
commit('setDownloaderList', data)
|
||||
},
|
||||
async releasesInit ({state, commit, dispatch}) {
|
||||
// TODO refactor this since it is a bit hard coded
|
||||
console.log('[INIT] Releases')
|
||||
|
@ -447,14 +436,16 @@ const store = new Vuex.Store({
|
|||
|
||||
log(`Received a request to download ${name} from ep ${fromEp} to ep ${untilEp}. Transmitting...`)
|
||||
|
||||
const {data, status} = await axios.post('download', {
|
||||
const infos = {
|
||||
name: name,
|
||||
quality: quality,
|
||||
fromEp: fromEp,
|
||||
untilEp: untilEp
|
||||
})
|
||||
fromEp: +fromEp,
|
||||
untilEp: +untilEp,
|
||||
fansub: state.config.fansub,
|
||||
choice: 'si'
|
||||
}
|
||||
|
||||
state.downloaderForm.loading = false
|
||||
const {data, status} = await axios.post('download', infos)
|
||||
|
||||
if (status === 200) {
|
||||
log(`Request fulfilled!`)
|
||||
|
@ -474,10 +465,52 @@ const store = new Vuex.Store({
|
|||
window.open(link)
|
||||
})
|
||||
}
|
||||
} else if (status === 204) {
|
||||
log('nyaa.si is down, trying with nyaa.pantsu.cat')
|
||||
|
||||
const {data, status} = await axios.post('download', {
|
||||
name: name,
|
||||
quality: quality,
|
||||
fromEp: fromEp,
|
||||
untilEp: untilEp,
|
||||
fansub: state.config.fansub,
|
||||
choice: 'pantsu'
|
||||
})
|
||||
|
||||
if (status === 200) {
|
||||
log(`Request fulfilled!`)
|
||||
|
||||
if (magnets === true)
|
||||
{
|
||||
const lastEp = fromEp !== '1' ? +fromEp + +data.length : data.length
|
||||
log(`User says he prefers having magnets hashes.`)
|
||||
commit('setDownloaderModal', {
|
||||
show: true,
|
||||
title: `${name.replace('_', ' ')}\t ${fromEp} - ${lastEp}`,
|
||||
text: data
|
||||
})
|
||||
}
|
||||
else
|
||||
{
|
||||
log(`Opening torrents directly on preferred torrent client.`)
|
||||
|
||||
data.forEach((link) => {
|
||||
window.open(link)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
log('Unknown error occurred. nyaa.si and nyaa.pantsu.cat seems both down.')
|
||||
|
||||
commit('setInfoSnackbar', 'Sorry. KawAnime was not able to get your torrents...')
|
||||
}
|
||||
}
|
||||
|
||||
state.downloaderForm.loading = false
|
||||
},
|
||||
saveConfig ({}, data) { // eslint-disable-line
|
||||
axios.post('saveConfig', JSON.stringify(data)).then((res) => {
|
||||
axios.post('saveConfig', JSON.stringify({
|
||||
config: data
|
||||
})).then((res) => {
|
||||
if (res.status === 200) { log(`Successfully updated config!`) }
|
||||
}).catch((err) => {
|
||||
log(`An error occurred while saving config: ${err}`)
|
||||
|
|
|
@ -117,12 +117,6 @@ test('/saveConfig.json route exits and saves config and return 200', async t =>
|
|||
writeFileSync(join(DIR, 'config.json'), JSON.stringify(config), 'utf-8')
|
||||
})
|
||||
|
||||
test('/getAllShows.json exits and returns a list of names', async t => {
|
||||
const { data } = await axios.get(`${uri}/getAllShows.json`)
|
||||
|
||||
t.true(data.length > 1)
|
||||
})
|
||||
|
||||
test('/getLatest.json exits and returns 18 elements with right keys at 720p', async t => {
|
||||
const { data, status } = await axios.get(`${uri}/getLatest.json?quality=720p`)
|
||||
|
||||
|
@ -141,21 +135,9 @@ test('/getLatest.json exits and returns 18 elements with right keys at 720p', as
|
|||
}
|
||||
})
|
||||
|
||||
test('/download Mahou Shoujo Ikusei Keikaku at 720p exits and returns all magnets', async t => {
|
||||
const { data } = await axios.post(`${uri}/download`, {
|
||||
name: 'Mahou Shoujo Ikusei Keikaku',
|
||||
quality: '720p',
|
||||
fromEp: 0,
|
||||
untilEp: 20000
|
||||
})
|
||||
|
||||
t.is(data.length, 12)
|
||||
t.not(data[0], '')
|
||||
})
|
||||
|
||||
test('/downloadNyaa Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p on nyaa.si exits and returns all' +
|
||||
test('/download Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p on nyaa.si exits and returns all' +
|
||||
' magnets', async t => {
|
||||
const { data } = await axios.post(`${uri}/downloadNyaa`, {
|
||||
const { data } = await axios.post(`${uri}/download`, {
|
||||
name: 'Mahou Shoujo Ikusei Keikaku',
|
||||
quality: '720p',
|
||||
fromEp: 0,
|
||||
|
@ -168,9 +150,9 @@ test('/downloadNyaa Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p on nya
|
|||
t.not(data[0], '')
|
||||
})
|
||||
|
||||
test('/downloadNyaa Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p on nyaa.pantsu.cat exits and returns' +
|
||||
test('/download Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p on nyaa.pantsu.cat exits and returns' +
|
||||
' all magnets', async t => {
|
||||
const { data } = await axios.post(`${uri}/downloadNyaa`, {
|
||||
const { data } = await axios.post(`${uri}/download`, {
|
||||
name: 'Mahou Shoujo Ikusei Keikaku',
|
||||
quality: '720p',
|
||||
fromEp: 0,
|
||||
|
@ -201,10 +183,9 @@ test('/getLatestNyaa exits and returns 18 elements with right keys at 720p on ny
|
|||
}
|
||||
})
|
||||
|
||||
test('/downloadNyaa Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p from ep 3 to 9 on nyaa.si exits and' +
|
||||
' returns' +
|
||||
' all magnets', async t => {
|
||||
const { data } = await axios.post(`${uri}/downloadNyaa`, {
|
||||
test('/download Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p from ep 3 to 9 on nyaa.si exits and' +
|
||||
' returns 7 magnets', async t => {
|
||||
const { data } = await axios.post(`${uri}/download`, {
|
||||
name: 'Mahou Shoujo Ikusei Keikaku',
|
||||
quality: '720p',
|
||||
fromEp: 3,
|
||||
|
@ -217,10 +198,10 @@ test('/downloadNyaa Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p from e
|
|||
t.not(data[0], '')
|
||||
})
|
||||
|
||||
test('/downloadNyaa Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p from ep 3 to 9 on nyaa.pantsu.cat' +
|
||||
test('/download Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p from ep 3 to 9 on nyaa.pantsu.cat' +
|
||||
' exits and returns' +
|
||||
' all magnets', async t => {
|
||||
const { data } = await axios.post(`${uri}/downloadNyaa`, {
|
||||
const { data } = await axios.post(`${uri}/download`, {
|
||||
name: 'Mahou Shoujo Ikusei Keikaku',
|
||||
quality: '720p',
|
||||
fromEp: 3,
|
||||
|
@ -233,29 +214,6 @@ test('/downloadNyaa Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p from e
|
|||
t.not(data[0], '')
|
||||
})
|
||||
|
||||
test('/download Akame ga Kill! at 1080p exits and returns only 4 eps', async t => {
|
||||
const { data } = await axios.post(`${uri}/download`, {
|
||||
name: 'Akame ga Kill!',
|
||||
quality: '720p',
|
||||
fromEp: 3,
|
||||
untilEp: 6
|
||||
})
|
||||
|
||||
t.is(data.length, 4)
|
||||
t.not(data[0], '')
|
||||
})
|
||||
|
||||
test('/download with wrong entries exits and returns 204', async t => {
|
||||
const { status } = await axios.post(`${uri}/download`, {
|
||||
name: 'Non-existent anime',
|
||||
quality: '30p',
|
||||
fromEp: 3,
|
||||
untilEp: 6
|
||||
})
|
||||
|
||||
t.is(status, 204)
|
||||
})
|
||||
|
||||
test('/getLatest.json exits and returns 204 status at 30p', async t => {
|
||||
const { status } = await axios.get(`${uri}/getLatest.json?quality=30p`)
|
||||
|
||||
|
|
Loading…
Reference in New Issue