2019-12-02 20:50:00 +00:00
|
|
|
from operator import itemgetter
|
2019-11-25 21:52:22 +00:00
|
|
|
|
2019-12-07 22:11:14 +00:00
|
|
|
from flask import redirect, render_template, request, url_for
|
2019-11-25 21:52:22 +00:00
|
|
|
|
2019-12-07 22:11:14 +00:00
|
|
|
from config import app, auth, db, ADMIN_USERNAME, ADMIN_PASSWORD, APP_PORT, IS_DEBUG
|
2019-11-30 15:52:13 +00:00
|
|
|
from connectors import *
|
2019-12-09 11:10:57 +00:00
|
|
|
from models import AnimeFolder, AnimeTitle, DeleteForm, SearchForm
|
2019-11-25 21:52:22 +00:00
|
|
|
|
|
|
|
|
2019-11-28 21:20:22 +00:00
|
|
|
@auth.verify_password
|
|
|
|
def verify_password(username, password):
|
2019-12-07 22:11:14 +00:00
|
|
|
return username == ADMIN_USERNAME and password == ADMIN_PASSWORD
|
2019-11-25 21:52:22 +00:00
|
|
|
|
|
|
|
|
2019-12-05 17:53:23 +00:00
|
|
|
@app.template_filter('boldify')
|
|
|
|
def boldify(name):
|
|
|
|
query = request.args.get('q')
|
|
|
|
name = Connector.boldify(name, query)
|
2019-12-07 17:31:10 +00:00
|
|
|
for title in ConnectorCache.get_keywords():
|
2019-12-05 17:53:23 +00:00
|
|
|
if title.keyword is not query:
|
|
|
|
name = Connector.boldify(name, title.keyword)
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
2019-12-07 22:11:14 +00:00
|
|
|
@app.template_filter('flagify')
|
|
|
|
def flagify(is_vf):
|
|
|
|
return ConnectorLang.FR.value if is_vf else ConnectorLang.JP.value
|
|
|
|
|
|
|
|
|
|
|
|
@app.template_filter('colorify')
|
|
|
|
def colorify(model):
|
|
|
|
return Connector.get_instance(model.link, model.title.keyword).color
|
2019-12-05 17:53:23 +00:00
|
|
|
|
|
|
|
|
2019-11-25 21:52:22 +00:00
|
|
|
@app.route('/')
|
2019-11-29 14:04:32 +00:00
|
|
|
def home():
|
2019-12-01 17:30:24 +00:00
|
|
|
return render_template('layout.html', form=SearchForm())
|
2019-11-29 14:04:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/search')
|
|
|
|
def search():
|
2019-11-30 15:52:13 +00:00
|
|
|
query = request.args.get('q')
|
|
|
|
if not query:
|
|
|
|
return redirect(url_for('home'))
|
|
|
|
|
|
|
|
results = [
|
|
|
|
Nyaa(query).run(),
|
|
|
|
Pantsu(query).run(),
|
2019-12-01 17:30:24 +00:00
|
|
|
YggTorrent(query).run(),
|
|
|
|
YggAnimation(query).run(),
|
2019-11-30 15:52:13 +00:00
|
|
|
AnimeUltime(query).run(),
|
|
|
|
]
|
2019-12-04 18:58:35 +00:00
|
|
|
|
2019-11-30 15:52:13 +00:00
|
|
|
return render_template('search.html', form=SearchForm(), connectors=results)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/latest')
|
|
|
|
def latest():
|
2019-12-03 21:43:53 +00:00
|
|
|
page = request.args.get('page', 1)
|
|
|
|
|
2019-12-01 17:30:24 +00:00
|
|
|
torrents = [
|
2019-12-03 21:43:53 +00:00
|
|
|
Nyaa('', return_type=ConnectorReturn.HISTORY, page=page).run(),
|
|
|
|
Pantsu('', return_type=ConnectorReturn.HISTORY, page=page).run(),
|
|
|
|
YggTorrent('', return_type=ConnectorReturn.HISTORY, page=page).run(),
|
|
|
|
YggAnimation('', return_type=ConnectorReturn.HISTORY, page=page).run(),
|
|
|
|
AnimeUltime('', return_type=ConnectorReturn.HISTORY, page=page).run(),
|
2019-12-01 17:30:24 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
results = []
|
|
|
|
for torrent in torrents:
|
|
|
|
results = results + torrent.data
|
2019-12-04 18:58:35 +00:00
|
|
|
for result in results:
|
|
|
|
result['self'] = Connector.get_instance(result['href'], '')
|
2019-12-05 17:53:23 +00:00
|
|
|
results.sort(key=itemgetter('date'), reverse=True)
|
2019-12-04 18:58:35 +00:00
|
|
|
|
2019-12-03 21:43:53 +00:00
|
|
|
return render_template('latest.html', form=SearchForm(), torrents=results, page=page)
|
2019-11-30 15:52:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/list')
|
|
|
|
def list_animes():
|
2019-12-07 09:17:29 +00:00
|
|
|
filters = None
|
|
|
|
for i, to_filter in enumerate(request.args.get('s', 'nyaa,yggtorrent').split(',')):
|
|
|
|
if not i:
|
|
|
|
filters = AnimeLink.link.contains(to_filter)
|
|
|
|
else:
|
|
|
|
filters = filters | AnimeLink.link.contains(to_filter)
|
2019-12-03 21:43:53 +00:00
|
|
|
|
2019-12-07 09:17:29 +00:00
|
|
|
titles = db.session.query(AnimeTitle, AnimeLink).join(AnimeLink).filter(filters).order_by(AnimeTitle.name).all()
|
|
|
|
|
|
|
|
results = {}
|
|
|
|
for title, link in titles:
|
|
|
|
if title.id not in results:
|
|
|
|
results[title.id] = [link]
|
|
|
|
else:
|
|
|
|
results[title.id].append(link)
|
|
|
|
|
2019-12-07 22:11:14 +00:00
|
|
|
return render_template('list.html', form=SearchForm(), titles=results)
|
2019-11-30 15:52:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/admin')
|
|
|
|
@auth.login_required
|
|
|
|
def admin():
|
2019-12-07 22:11:14 +00:00
|
|
|
folders = AnimeFolder.query.all()
|
|
|
|
|
2019-12-09 11:10:57 +00:00
|
|
|
return render_template('admin/list.html', form=SearchForm(), folders=folders, delete_form=DeleteForm())
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/admin/delete', methods=['POST'])
|
|
|
|
@auth.login_required
|
|
|
|
def admin_delete():
|
|
|
|
form = DeleteForm()
|
|
|
|
form_id = request.form.id
|
|
|
|
if form.validate_on_submit() and form_id:
|
|
|
|
link = AnimeLink.query.filter_by(id=form_id).first()
|
|
|
|
title = link.title
|
|
|
|
db.session.delete(link)
|
|
|
|
if not len(title.links):
|
|
|
|
db.session.delete(title)
|
|
|
|
return redirect(url_for('admin'))
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/admin/edit/<id>')
|
|
|
|
@auth.login_required
|
|
|
|
def admin_edit(id):
|
|
|
|
return True
|
2019-11-28 21:20:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-12-07 09:17:29 +00:00
|
|
|
app.run('0.0.0.0', APP_PORT, IS_DEBUG)
|