list page OK + fix cache
This commit is contained in:
parent
76ca5549de
commit
a4a9e23607
28
app.py
28
app.py
@ -15,6 +15,21 @@ def verify_password(username, password):
|
|||||||
return username is admin_username and password is admin_password
|
return username is admin_username and password is admin_password
|
||||||
|
|
||||||
|
|
||||||
|
@app.template_filter('boldify')
|
||||||
|
def boldify(name):
|
||||||
|
query = request.args.get('q')
|
||||||
|
name = Connector.boldify(name, query)
|
||||||
|
for title in AnimeTitle.query.all():
|
||||||
|
if title.keyword is not query:
|
||||||
|
name = Connector.boldify(name, title.keyword)
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
|
@app.template_filter('shorten')
|
||||||
|
def shorten(str):
|
||||||
|
return str[:30] + '...' if len(str) > 30 else str
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def home():
|
def home():
|
||||||
return render_template('layout.html', form=SearchForm())
|
return render_template('layout.html', form=SearchForm())
|
||||||
@ -52,23 +67,20 @@ def latest():
|
|||||||
results = []
|
results = []
|
||||||
for torrent in torrents:
|
for torrent in torrents:
|
||||||
results = results + torrent.data
|
results = results + torrent.data
|
||||||
results.sort(key=itemgetter('date'), reverse=True)
|
|
||||||
|
|
||||||
for keyword in AnimeTitle.query.all():
|
|
||||||
for result in results:
|
|
||||||
result['name'] = Connector.boldify(result['name'], keyword)
|
|
||||||
|
|
||||||
for result in results:
|
for result in results:
|
||||||
result['self'] = Connector.get_instance(result['href'], '')
|
result['self'] = Connector.get_instance(result['href'], '')
|
||||||
|
results.sort(key=itemgetter('date'), reverse=True)
|
||||||
|
|
||||||
return render_template('latest.html', form=SearchForm(), torrents=results, page=page)
|
return render_template('latest.html', form=SearchForm(), torrents=results, page=page)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/list')
|
@app.route('/list')
|
||||||
def list_animes():
|
def list_animes():
|
||||||
results = []
|
filters = request.args.get('s', 'nyaa,yggtorrent').split(',')
|
||||||
|
titles = AnimeTitle.query.order_by(AnimeTitle.name).all()
|
||||||
|
|
||||||
return render_template('list.html', form=SearchForm(), torrents=results)
|
return render_template('list.html', form=SearchForm(), titles=titles, filters=filters, connector=Connector,
|
||||||
|
flags=ConnectorLang)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/admin')
|
@app.route('/admin')
|
||||||
|
@ -41,20 +41,22 @@ class Cache:
|
|||||||
self.CACHE_DATA[connector.__class__.__name__][f.__name__][connector.query] = {}
|
self.CACHE_DATA[connector.__class__.__name__][f.__name__][connector.query] = {}
|
||||||
if connector.page not in self.CACHE_DATA[connector.__class__.__name__][f.__name__][connector.query]:
|
if connector.page not in self.CACHE_DATA[connector.__class__.__name__][f.__name__][connector.query]:
|
||||||
self.CACHE_DATA[connector.__class__.__name__][f.__name__][connector.query][connector.page] = {
|
self.CACHE_DATA[connector.__class__.__name__][f.__name__][connector.query][connector.page] = {
|
||||||
'data': {},
|
|
||||||
'timeout': 0
|
'timeout': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
cached_data = self.CACHE_DATA[connector.__class__.__name__][f.__name__][connector.query][connector.page]
|
cached_data = self.CACHE_DATA[connector.__class__.__name__][f.__name__][connector.query][connector.page]
|
||||||
if cached_data['timeout'] > timestamp:
|
if cached_data['timeout'] > timestamp:
|
||||||
connector.data = cached_data['data']
|
connector.data = cached_data['data']
|
||||||
|
connector.is_more = cached_data['is_more']
|
||||||
return
|
return
|
||||||
|
|
||||||
ret = f(*args, **kwds)
|
ret = f(*args, **kwds)
|
||||||
self.CACHE_DATA[connector.__class__.__name__][f.__name__][connector.query][connector.page] = {
|
if not connector.on_error:
|
||||||
'data': connector.data,
|
self.CACHE_DATA[connector.__class__.__name__][f.__name__][connector.query][connector.page] = {
|
||||||
'timeout': timestamp + self.CACHE_TIMEOUT
|
'data': connector.data,
|
||||||
}
|
'timeout': timestamp + self.CACHE_TIMEOUT,
|
||||||
|
'is_more': connector.is_more
|
||||||
|
}
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
@ -247,7 +249,7 @@ class Nyaa(Connector):
|
|||||||
self.data.append({
|
self.data.append({
|
||||||
'lang': self.get_lang(url.string),
|
'lang': self.get_lang(url.string),
|
||||||
'href': href,
|
'href': href,
|
||||||
'name': self.boldify(url.string, self.query),
|
'name': url.string,
|
||||||
'comment': str(urls[0]).replace('/view/',
|
'comment': str(urls[0]).replace('/view/',
|
||||||
'%s%s' % (self.base_url, '/view/')) if has_comment else '',
|
'%s%s' % (self.base_url, '/view/')) if has_comment else '',
|
||||||
'link': tds[2].decode_contents().replace('/download/',
|
'link': tds[2].decode_contents().replace('/download/',
|
||||||
@ -330,7 +332,7 @@ class Pantsu(Connector):
|
|||||||
self.data.append({
|
self.data.append({
|
||||||
'lang': self.get_lang(url.string),
|
'lang': self.get_lang(url.string),
|
||||||
'href': href,
|
'href': href,
|
||||||
'name': self.boldify(url.string, self.query),
|
'name': url.string,
|
||||||
'comment': '',
|
'comment': '',
|
||||||
'link': tds[2].decode_contents()
|
'link': tds[2].decode_contents()
|
||||||
.replace('icon-magnet', 'fa fa-fw fa-magnet')
|
.replace('icon-magnet', 'fa fa-fw fa-magnet')
|
||||||
@ -399,7 +401,7 @@ class YggTorrent(Connector):
|
|||||||
self.data.append({
|
self.data.append({
|
||||||
'lang': self.get_lang(url.string),
|
'lang': self.get_lang(url.string),
|
||||||
'href': url['href'],
|
'href': url['href'],
|
||||||
'name': self.boldify(url.string, self.query),
|
'name': url.string,
|
||||||
'comment': '<a href="%s#comm" target="_blank"><i class="fa fa-comments-o"></i>%s</a>' %
|
'comment': '<a href="%s#comm" target="_blank"><i class="fa fa-comments-o"></i>%s</a>' %
|
||||||
(url['href'], tds[3].string),
|
(url['href'], tds[3].string),
|
||||||
'link': '<a href="%s/engine/download_torrent?id=%s">'
|
'link': '<a href="%s/engine/download_torrent?id=%s">'
|
||||||
@ -473,7 +475,7 @@ class AnimeUltime(Connector):
|
|||||||
self.data.append({
|
self.data.append({
|
||||||
'lang': ConnectorLang.JP,
|
'lang': ConnectorLang.JP,
|
||||||
'href': '%s/%s' % (self.base_url, url['href']),
|
'href': '%s/%s' % (self.base_url, url['href']),
|
||||||
'name': url.decode_contents(),
|
'name': url.get_text(),
|
||||||
'type': tds[1].string,
|
'type': tds[1].string,
|
||||||
'class': self.color if AnimeLink.query.filter_by(link=href).first() else ''
|
'class': self.color if AnimeLink.query.filter_by(link=href).first() else ''
|
||||||
})
|
})
|
||||||
@ -486,7 +488,7 @@ class AnimeUltime(Connector):
|
|||||||
self.data.append({
|
self.data.append({
|
||||||
'lang': ConnectorLang.JP,
|
'lang': ConnectorLang.JP,
|
||||||
'href': '%s/file-0-1/%s' % (self.base_url, player[0]['data-serie']),
|
'href': '%s/file-0-1/%s' % (self.base_url, player[0]['data-serie']),
|
||||||
'name': self.boldify(name[0].string, self.query),
|
'name': name[0].string,
|
||||||
'type': ani_type[0].string.replace(':', ''),
|
'type': ani_type[0].string.replace(':', ''),
|
||||||
'class': self.color if AnimeLink.query.filter_by(link=href).first() else ''
|
'class': self.color if AnimeLink.query.filter_by(link=href).first() else ''
|
||||||
})
|
})
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
<i> </i>
|
<i> </i>
|
||||||
{{ torrent.lang.value }}
|
{{ torrent.lang.value }}
|
||||||
<a href="{{ torrent.href }}" target="_blank">
|
<a href="{{ torrent.href }}" target="_blank">
|
||||||
{{ torrent.name }}
|
{{ torrent.name|boldify|safe }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@ -47,7 +47,7 @@
|
|||||||
<i> </i>
|
<i> </i>
|
||||||
{{ torrent.lang.value }}
|
{{ torrent.lang.value }}
|
||||||
<a href="{{ torrent.href }}" target="_blank">
|
<a href="{{ torrent.href }}" target="_blank">
|
||||||
{{ torrent.name }}
|
{{ torrent.name|boldify|safe }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -12,6 +12,38 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
||||||
|
{% for title in titles %}
|
||||||
|
{% for link in title.links %}
|
||||||
|
<tr>
|
||||||
|
{% if not loop.index0 %}
|
||||||
|
<td rowspan="{{ title.links|length }}">
|
||||||
|
{{ title.name }}
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% set instance = connector.get_instance(link.link, '') %}
|
||||||
|
<td class="{{ instance.color }}">
|
||||||
|
{{ flags.FR.value if link.vf else flags.JP.value }}
|
||||||
|
<a href="{{ link.link }}" target="_blank">
|
||||||
|
{{ link.link|shorten }}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
{{ link.season }}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{% if not loop.index0 %}
|
||||||
|
<td rowspan="{{ title.links|length }}">
|
||||||
|
<a href="{{ url_for('search', q=title.keyword) }}" target="_blank">
|
||||||
|
<i class="fa fa-search"></i>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
<td>
|
<td>
|
||||||
{{ torrent.lang.value }}
|
{{ torrent.lang.value }}
|
||||||
<a href="{{ torrent.href }}" target="_blank">
|
<a href="{{ torrent.href }}" target="_blank">
|
||||||
{{ torrent.name|safe }}
|
{{ torrent.name|boldify|safe }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user