2019-12-02 20:50:00 +00:00
|
|
|
from operator import itemgetter
|
2019-11-25 21:52:22 +00:00
|
|
|
from os import environ
|
|
|
|
|
2019-11-30 15:52:13 +00:00
|
|
|
from flask import redirect, render_template, url_for, request
|
2019-11-25 21:52:22 +00:00
|
|
|
|
2019-11-29 14:04:32 +00:00
|
|
|
from config import app, auth
|
2019-11-30 15:52:13 +00:00
|
|
|
from connectors import *
|
2019-12-02 20:50:00 +00:00
|
|
|
from models import SearchForm, AnimeTitle
|
2019-11-25 21:52:22 +00:00
|
|
|
|
|
|
|
|
2019-11-28 21:20:22 +00:00
|
|
|
@auth.verify_password
|
|
|
|
def verify_password(username, password):
|
|
|
|
admin_username = environ.get('ADMIN_USERNAME', 'admin')
|
|
|
|
admin_password = environ.get('ADMIN_USERNAME', 'secret')
|
|
|
|
return username is admin_username and password is admin_password
|
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(),
|
|
|
|
]
|
|
|
|
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-03 21:43:53 +00:00
|
|
|
results.sort(key=itemgetter('date'), reverse=True)
|
2019-12-01 17:30:24 +00:00
|
|
|
|
2019-12-02 20:50:00 +00:00
|
|
|
for keyword in AnimeTitle.query.all():
|
|
|
|
for result in results:
|
|
|
|
result['name'] = Connector.boldify(result['name'], keyword)
|
2019-12-01 17:30:24 +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-03 21:43:53 +00:00
|
|
|
results = []
|
|
|
|
|
|
|
|
return render_template('list.html', form=SearchForm(), torrents=results)
|
2019-11-30 15:52:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/admin')
|
|
|
|
@auth.login_required
|
|
|
|
def admin():
|
2019-11-29 14:04:32 +00:00
|
|
|
return 'Hello!'
|
2019-11-28 21:20:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-11-30 17:09:30 +00:00
|
|
|
app_debug = environ.get('FLASK_ENV', 'production') == 'development'
|
|
|
|
app_port = environ.get('FLASK_PORT', 5000)
|
|
|
|
app.run('0.0.0.0', app_port, app_debug)
|