News page is now available !

This commit is contained in:
Kylart 2016-12-10 22:30:47 +09:00
parent e09d9bc7ed
commit ef1cc35882
6 changed files with 133 additions and 61 deletions

View File

@ -8,6 +8,8 @@ const exec = require('child_process').exec
const Nyaa = require('node-nyaa-api')
const findRemoveSync = require('find-remove')
const main = require('electron').remote.require(path.join(__dirname, '..', '..', 'main.js'))
let animes = []
let name = new Vue({
@ -71,33 +73,10 @@ function downloadFile (file_url , targetPath){
}
function startTorrent () {
const torrents = path.join(__dirname, '..', '..', 'resources', 'tmp', '*.torrent')
let openCmd
switch (process.platform)
{
case 'darwin':
openCmd = 'open '
break
case 'linux':
openCmd = 'xdg-open '
break
case 'win32':
openCmd = 'start '
}
exec(openCmd + torrents, (error, stdout, stderr) => {
if (error)
{
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
})
main.openTorrents()
}
let downloadButton = new Vue({
new Vue({
el: '#button-container',
data: {
msg : 'Download!'
@ -107,7 +86,6 @@ let downloadButton = new Vue({
// Remove all torrent files in tmp directory
findRemoveSync(path.join(__dirname, '..', '..', 'resources', 'tmp'), {extensions: ['.torrent']})
console.log(`Retrieving ${name.anime} from ${fromEp.ep} to ${untilEp.ep}...`)
// Get the right torrents

View File

@ -294,4 +294,47 @@ body
{
text-align: right;
margin-bottom: 3%;
}
}
#news-container
{
box-sizing: border-box;
background-image: url('https://thumbs.dreamstime.com/x/seamless-fabric-background-4903761.jpg');
}
.news
{
box-shadow: 0 2px 2px 0 rgba(0,0,0,.14),0 3px 1px -2px rgba(0,0,0,.2),0 1px 5px 0 rgba(0,0,0,.12);
overflow: auto;
position: relative;
padding: 5px 10px 0 0;
background-color: rgba(255, 255, 255, 0.95);
}
.news-title
{
margin-top: 10px;
margin-bottom: 10px;
padding: 0 10px 0 25px;
}
.news-picture
{
float: left;
width: 15%;
}
.news-synopsis
{
float: right;
width: 80%;
text-align: justify;
padding: 10px 20px 10px 10px;
}
.news-link
{
position: absolute;
bottom: 0;
right: 0;
}

View File

@ -43,7 +43,8 @@
<span class="mdl-layout-title">KawAnime</span>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#" v-on:click="getDownloader()">Download an anime</a>
<a class="mdl-navigation__link" href="#" v-on:click="getInfoPage()">Get information</a>
<a class="mdl-navigation__link" href="#" v-on:click="getMainPage()">Main page</a>
<a class="mdl-navigation__link" href="#" v-on:click="getNewsPage()">Get news</a>
<a class="mdl-navigation__link" href="#">Watch List</a>
</nav>
</div>
@ -141,6 +142,22 @@
</div>
</div>
</div>
<div id="news-container" style="display: none">
<div class="mdl-grid">
<div v-for="article in news"
class="news mdl-cell mdl-cell--12-col mdl-cell--6-col-phone">
<h5 class="news-title">{{ article.title }}</h5>
<div class="news-picture" v-bind:style="{content: 'url(' + article.image + ')'}"></div>
<div class="news-synopsis">
{{ article.text }}
</div>
<button @click="openLink(article.link)"
class="news-link mdl-button mdl-js-button mdl-button--raised mdl-button--colored">
Open
</button>
</div>
</div>
</div>
</main>
</div>`

14
main.js
View File

@ -4,8 +4,10 @@ const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow
const shell = require('electron').shell
const path = require('path')
const url = require('url')
const fs = require('fs')
// 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.
@ -91,7 +93,19 @@ exports.getMainPage = () => {
protocol: 'file:',
slashes: true
}))
}
exports.openTorrents = () => {
const TORRENT_PATH = path.join(__dirname, 'resources', 'tmp')
let tmpFiles = fs.readdirSync(TORRENT_PATH)
tmpFiles.forEach( (elem) => {
if (elem.split('.').pop() === 'torrent')
{
shell.openItem(path.join(TORRENT_PATH, elem))
}
})
}

View File

@ -21,7 +21,7 @@
"dependencies": {
"find-remove": "^1.0.0",
"is-online": "^5.2.0",
"mal-scraper": "^1.0.6",
"mal-scraper": "^1.0.8",
"malapi": "0.0.3",
"node-nyaa-api": "latest",
"progressbar.js": "^1.0.1"

View File

@ -19,6 +19,8 @@ const findRemoveSync = require('find-remove')
const mal = require('malapi').Anime
// Nyaa API
const Nyaa = require('node-nyaa-api')
// Scraping the news from Mal
const malScraper = require('mal-scraper')
/* ----------------- END IMPORTS ----------------- */
@ -107,8 +109,11 @@ function getLatest () {
releases.releases.pop()
}).then( () => {
setTimeout( () => {
loader.show = false
releases.show = true
if (!news.show)
{
loader.show = false
releases.show = true
}
}, 1200)
})
}
@ -127,38 +132,14 @@ function downloadFile (file_url, name){
}
function startTorrent (file_url, name) {
const torrents = path.join(__dirname, 'resources', 'tmp', `*.torrent`)
let openCmd
// Removing old torrents
findRemoveSync(path.join(__dirname, 'resources', 'tmp'), {extensions: ['.torrent']})
// Downloading the new ones
downloadFile(file_url, name)
switch (process.platform)
{
case 'darwin':
openCmd = 'open '
break
case 'linux':
openCmd = 'xdg-open '
break
case 'win32':
openCmd = 'start '
}
exec(openCmd + torrents, (error, stdout, stderr) => {
if (error)
{
console.error(`exec error: ${error}`)
return
}
if (stdout == null && stderr == null)
{
console.log(`Starting torrent stdout: ${stdout}`)
console.log(`Starting torrent stderr: ${stderr}`)
}
})
// Opening them
main.openTorrents()
}
function makeResearchOnMal (name) {
@ -185,11 +166,20 @@ function makeResearchOnMal (name) {
})
}
function getNews() {
let tmp = malScraper.getNewsNoDetails( () => {
news.news = tmp
})
}
/* -------------------- END FUNCTIONS ----------------- */
// First research at kawAnime's start
getLatest()
// Getting the news in advance
getNews()
/* ------------------- VUE.JS OBJECTS ----------------- */
let releases = new Vue({
@ -267,6 +257,20 @@ let info = new Vue({
}
})
let news = new Vue({
el: '#news-container',
data: {
show: false,
news: []
},
methods: {
openLink: function (link) {
event.preventDefault()
shell.openExternal(link)
}
}
})
// Vue object to open the other pages
new Vue({
el: '.mdl-navigation',
@ -274,8 +278,24 @@ new Vue({
getDownloader: function () {
main.openDownloader()
},
getInfoPage: function () {
main.getInfoPage()
getMainPage: function () {
if (!loader.show)
{
releases.show = true
news.show = false
}
},
getNewsPage: function () {
// For first time
let tmp = document.getElementById('news-container')
if (tmp.style.display === 'none')
tmp.style.display = 'block'
releases.show = false
news.show = true
loader.show = false
}
}
})