VF is auto now (refacto)
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Michel Roux 2021-01-30 19:40:36 +01:00
parent a3abcbe28d
commit c2c3e30879
12 changed files with 66 additions and 32 deletions

View File

@ -85,7 +85,7 @@ def latest(page=1):
for torrent in torrents:
results = results + torrent.data
for result in results:
result['self'] = get_instance(result['href'], '')
result['self'] = get_instance(result['href'])
results.sort(key=itemgetter('date'), reverse=True)
return render_template('latest.html', search_form=SearchForm(), torrents=results, page=page)
@ -155,6 +155,8 @@ def admin_edit(link_id=None):
form = EditForm(request.form)
if form.validate_on_submit():
# Instance for VF tag
instance = get_instance(form.link.data)
# Folder
folder = AnimeFolder.query.filter_by(name=form.folder.data).first()
folder = folder if folder else AnimeFolder()
@ -177,7 +179,7 @@ def admin_edit(link_id=None):
link.link = form.link.data
link.season = form.season.data
link.comment = form.comment.data
link.vf = form.is_vf.data
link.vf = instance.is_vf(form.link.data)
db.session.add(link)
db.session.commit()
remove_garbage(link)

View File

@ -20,7 +20,7 @@ async def run_all(*args, **kwargs):
return list(await gather(*coroutines))
def get_instance(url, query):
def get_instance(url, query=''):
if 'nyaa.si' in url:
return Nyaa(query)
elif 'nyaa.net' in url:

View File

@ -2,7 +2,7 @@ from datetime import datetime, timedelta
from bs4 import BeautifulSoup
from .core import ConnectorCore, ConnectorReturn, ConnectorCache, ConnectorLang, curl_content
from .core import ConnectorCore, ConnectorReturn, ConnectorCache, curl_content
from ..utils import parse_date, link_exist_in_db
@ -54,7 +54,7 @@ class AnimeUltime(ConnectorCore):
if not any(href == d['href'] for d in self.data):
self.data.append({
'lang': ConnectorLang.JP,
'vf': self.is_vf(),
'href': href,
'name': url.get_text(),
'type': tds[1].get_text(),
@ -67,7 +67,7 @@ class AnimeUltime(ConnectorCore):
href = '%s/file-0-1/%s' % (self.base_url, player[0]['data-serie'])
self.data.append({
'lang': ConnectorLang.JP,
'vf': self.is_vf(),
'href': '%s/file-0-1/%s' % (self.base_url, player[0]['data-serie']),
'name': name[0].get_text(),
'type': ani_type[0].get_text().replace(':', ''),
@ -96,7 +96,7 @@ class AnimeUltime(ConnectorCore):
href = '%s/%s' % (self.base_url, link['href'])
self.data.append({
'lang': ConnectorLang.JP,
'vf': self.is_vf(),
'href': '%s/%s' % (self.base_url, link['href']),
'name': link.get_text(),
'type': tds[4].get_text(),
@ -105,3 +105,7 @@ class AnimeUltime(ConnectorCore):
})
self.on_error = False
@ConnectorCache.cache_data
def is_vf(self, url=''):
return False

View File

@ -1,4 +1,3 @@
import re
from abc import ABC, abstractmethod
from datetime import datetime
from enum import Enum
@ -80,7 +79,7 @@ def curl_content(url, params=None, ajax=False, debug=True):
output = ''
http_code = 500
method = 'post' if (params is not None) else 'get'
instance = get_instance(url, '')
instance = get_instance(url)
if ajax:
headers = {'X-Requested-With': 'XMLHttpRequest'}
@ -183,12 +182,9 @@ class ConnectorCore(ABC):
def get_history(self):
pass
@staticmethod
def get_lang(str_to_test):
if re.search('(vf|multi|french)', str_to_test, re.IGNORECASE):
return ConnectorLang.FR
else:
return ConnectorLang.JP
@abstractmethod
def is_vf(self, url):
pass
async def run(self):
if self.on_error:

View File

@ -1,7 +1,7 @@
from bs4 import BeautifulSoup
from .core import ConnectorCore, ConnectorReturn, ConnectorCache, curl_content
from ..utils import parse_date, link_exist_in_db, check_blacklist_words
from ..utils import parse_date, link_exist_in_db, check_blacklist_words, check_if_vf
class Nyaa(ConnectorCore):
@ -59,7 +59,7 @@ class Nyaa(ConnectorCore):
href = self.base_url + url['href']
self.data.append({
'lang': self.get_lang(url_safe),
'vf': check_if_vf(url_safe),
'href': href,
'name': url_safe,
'comment': str(urls[0]).replace('/view/', self.base_url + '/view/') if has_comment else '',
@ -74,3 +74,14 @@ class Nyaa(ConnectorCore):
self.on_error = False
self.is_more = valid_trs and valid_trs is not len(trs) - 1
@ConnectorCache.cache_data
def is_vf(self, url):
response = curl_content(url)
if response['http_code'] == 200:
html = BeautifulSoup(response['output'], 'html.parser')
title = html.select('h3.panel-title')
return check_if_vf(title[0].get_text())
return False

View File

@ -1,7 +1,7 @@
from bs4 import BeautifulSoup
from .core import ConnectorCore, ConnectorReturn, ConnectorCache, curl_content
from ..utils import parse_date, link_exist_in_db, check_blacklist_words
from ..utils import parse_date, link_exist_in_db, check_blacklist_words, check_if_vf
class Pantsu(ConnectorCore):
@ -51,7 +51,7 @@ class Pantsu(ConnectorCore):
href = self.base_url + url['href']
self.data.append({
'lang': self.get_lang(url_safe),
'vf': check_if_vf(url_safe),
'href': href,
'name': url_safe,
'comment': '',
@ -67,3 +67,15 @@ class Pantsu(ConnectorCore):
self.on_error = False
self.is_more = valid_trs and valid_trs is not len(trs) - 1
@ConnectorCache.cache_data
def is_vf(self, url):
response = curl_content(url)
if response['http_code'] == 200:
html = BeautifulSoup(response['output'], 'html.parser')
title = html.select('h1.torrent-hr')
print(title, flush=True)
return check_if_vf(title[0].get_text())
return False

View File

@ -5,7 +5,7 @@ from urllib.parse import quote
from bs4 import BeautifulSoup
from .core import ConnectorCore, ConnectorReturn, ConnectorCache, curl_content
from ..utils import parse_date, link_exist_in_db, check_blacklist_words
from ..utils import parse_date, link_exist_in_db, check_blacklist_words, check_if_vf
class YggTorrent(ConnectorCore):
@ -58,7 +58,7 @@ class YggTorrent(ConnectorCore):
valid_trs = valid_trs + 1
self.data.append({
'lang': self.get_lang(url_safe),
'vf': check_if_vf(url_safe),
'href': url['href'],
'name': url_safe,
'comment': '<a href="%s#comm" target="_blank"><i class="fa fa-comments-o"></i>%s</a>' %
@ -77,6 +77,17 @@ class YggTorrent(ConnectorCore):
self.on_error = False
self.is_more = valid_trs and valid_trs is not len(trs) - 1
@ConnectorCache.cache_data
def is_vf(self, url):
response = curl_content(url)
if response['http_code'] == 200:
html = BeautifulSoup(response['output'], 'html.parser')
title = html.select('#title h1')
return check_if_vf(title[0].get_text())
return False
class YggAnimation(YggTorrent):
title = 'YggAnimation'

View File

@ -1,5 +1,5 @@
from flask_wtf import FlaskForm
from wtforms import BooleanField, HiddenField, StringField
from wtforms import HiddenField, StringField
from wtforms.fields.html5 import SearchField, URLField
from wtforms.validators import DataRequired
@ -23,4 +23,3 @@ class EditForm(FlaskForm):
season = StringField('season', validators=[DataRequired()])
comment = StringField('comment')
keyword = StringField('keyword', validators=[DataRequired()])
is_vf = BooleanField('is_vf')

View File

@ -53,7 +53,7 @@
<div class="field is-horizontal">
<div class="field-body">
<div class="field column is-4">
<div class="field column is-6">
<div class="control is-expanded">
{{ action_form.link(value=link.link, class='input', placeholder='Link') }}
</div>
@ -69,7 +69,7 @@
<div class="field is-horizontal">
<div class="field-body">
<div class="field column is-5">
<div class="field column is-6">
<div class="control is-expanded">
{{ action_form.comment(value=link.comment, class='input', placeholder='Comment') }}
</div>
@ -90,11 +90,6 @@
</div>
</div>
</div>
<label class="checkbox">
<b>{{ true|flagify }}</b>
{{ action_form.is_vf(checked=link.vf) }}
</label>
</div>
</div>

View File

@ -27,7 +27,7 @@
<img class="favicon"
src="{{ url_for('static', filename='favicons/%s' % torrent.self.favicon) }}" alt="">
<i>&nbsp;</i>
{{ torrent.lang.value }}
{{ torrent.vf|flagify }}
<a href="{{ torrent.href }}" target="_blank">
{{ torrent.name|boldify|safe }}
</a>

View File

@ -32,7 +32,7 @@
{% for torrent in connector.data %}
<tr class="{{ torrent.class }}">
<td>
{{ torrent.lang.value }}
{{ torrent.vf|flagify }}
<a href="{{ torrent.href }}" target="_blank">
{{ torrent.name|boldify|safe }}
</a>

View File

@ -45,3 +45,7 @@ def clean_model(obj):
def check_blacklist_words(url):
return any(word.lower() in url.lower() for word in BLACKLIST_WORDS)
def check_if_vf(title):
return any(word.lower() in title.lower() for word in ['vf', 'multi', 'french'])