Prettifying the code a little bit + redundant href on A-U
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michel Roux 2021-09-01 15:57:54 +00:00
parent 0c2e03eed7
commit 37ea16c95a
8 changed files with 106 additions and 26 deletions

View File

@ -7,6 +7,15 @@ for link in links:
html = curl_content(link.link, debug=False) html = curl_content(link.link, debug=False)
if html['http_code'] != 200 and html['http_code'] != 500: if html['http_code'] != 200 and html['http_code'] != 500:
print('(%d) %s %s : %s' % (html['http_code'], link.title.name, link.season, link.link)) print('(%d) %s %s : %s' % (
html['http_code'],
link.title.name,
link.season,
link.link
))
elif 'darkgray' in str(html['output']): elif 'darkgray' in str(html['output']):
print('(darkgray) %s %s : %s' % (link.title.name, link.season, link.link)) print('(darkgray) %s %s : %s' % (
link.title.name,
link.season,
link.link
))

View File

@ -92,7 +92,9 @@ def search():
@app.route('/latest/<int:page>') @app.route('/latest/<int:page>')
def latest(page=1): def latest(page=1):
set_event_loop(SelectorEventLoop()) set_event_loop(SelectorEventLoop())
torrents = get_event_loop().run_until_complete(run_all('', return_type=ConnectorReturn.HISTORY, page=page)) torrents = get_event_loop().run_until_complete(
run_all('', return_type=ConnectorReturn.HISTORY, page=page)
)
results = [] results = []
for torrent in torrents: for torrent in torrents:
@ -136,7 +138,10 @@ def admin():
if form.validate_on_submit(): if form.validate_on_submit():
link = AnimeLink.query.filter_by(id=form.id.data).first() link = AnimeLink.query.filter_by(id=form.id.data).first()
if link: if link:
form.message = '%s (%s) has been successfully deleted' % (link.title.name, link.season) form.message = '%s (%s) has been successfully deleted' % (
link.title.name,
link.season
)
db.session.delete(link) db.session.delete(link)
db.session.commit() db.session.commit()
@ -145,7 +150,9 @@ def admin():
db.session.delete(title) db.session.delete(title)
db.session.commit() db.session.commit()
else: else:
form._errors = {'id': ['Id %s was not found in the database' % form.id.data]} form._errors = {
'id': ['Id %s was not found in the database' % form.id.data]
}
folders = AnimeFolder.query.all() folders = AnimeFolder.query.all()
for folder in folders: for folder in folders:
@ -169,7 +176,9 @@ def folder_list():
db.session.delete(folder) db.session.delete(folder)
db.session.commit() db.session.commit()
else: else:
form._errors = {'id': ['Id %s was not found in the database' % form.id.data]} form._errors = {
'id': ['Id %s was not found in the database' % form.id.data]
}
folders = AnimeFolder.query.all() folders = AnimeFolder.query.all()
@ -183,7 +192,12 @@ def folder_list():
def folder_edit(folder_id=None): def folder_edit(folder_id=None):
folder = AnimeFolder.query.filter_by(id=folder_id).first() folder = AnimeFolder.query.filter_by(id=folder_id).first()
folder = folder if folder else AnimeFolder() folder = folder if folder else AnimeFolder()
form = FolderEditForm(request.form, id=folder.id, name=folder.name, path=folder.path) form = FolderEditForm(
request.form,
id=folder.id,
name=folder.name,
path=folder.path
)
if form.validate_on_submit(): if form.validate_on_submit():
# Folder # Folder
@ -246,9 +260,15 @@ def admin_edit(link_id=None):
# Transmission # Transmission
if TRANSMISSION_ENABLED and isinstance(instance, Nyaa): if TRANSMISSION_ENABLED and isinstance(instance, Nyaa):
if title.folder.path is not None and title.folder.path != '': if title.folder.path is not None and title.folder.path != '':
download_url = link.link.replace('/view/', '/download/') + '.torrent' download_url = link.link.replace(
'/view/',
'/download/'
) + '.torrent'
torrent_path = '%s/%s' % (title.folder.path, title.name) torrent_path = '%s/%s' % (title.folder.path, title.name)
torrent = transmission.add_torrent(download_url, download_dir=torrent_path) torrent = transmission.add_torrent(
download_url,
download_dir=torrent_path
)
transmission.move_torrent_data(torrent.id, torrent_path) transmission.move_torrent_data(torrent.id, torrent_path)
transmission.start_torrent(torrent.id) transmission.start_torrent(torrent.id)

View File

@ -30,7 +30,9 @@ class AnimeUltime(ConnectorCore):
@ConnectorCache.cache_data @ConnectorCache.cache_data
def search(self): def search(self):
response = curl_content(self.get_full_search_url(), {'search': self.query}) response = curl_content(self.get_full_search_url(), {
'search': self.query
})
if response['http_code'] == 200: if response['http_code'] == 200:
html = BeautifulSoup(response['output'], 'html.parser') html = BeautifulSoup(response['output'], 'html.parser')
@ -63,11 +65,14 @@ class AnimeUltime(ConnectorCore):
elif len(player) > 0: elif len(player) > 0:
name = html.select('h1') name = html.select('h1')
ani_type = html.select('div.titre') ani_type = html.select('div.titre')
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']
)
self.data.append({ self.data.append({
'vf': self.is_vf(), 'vf': self.is_vf(),
'href': '%s/file-0-1/%s' % (self.base_url, player[0]['data-serie']), 'href': href,
'name': name[0].get_text(), 'name': name[0].get_text(),
'type': ani_type[0].get_text().replace(':', ''), 'type': ani_type[0].get_text().replace(':', ''),
'class': self.color if link_exist_in_db(href) else '' 'class': self.color if link_exist_in_db(href) else ''
@ -95,7 +100,7 @@ class AnimeUltime(ConnectorCore):
self.data.append({ self.data.append({
'vf': self.is_vf(), 'vf': self.is_vf(),
'href': '%s/%s' % (self.base_url, link['href']), 'href': href,
'name': link.get_text(), 'name': link.get_text(),
'type': tds[4].get_text(), 'type': tds[4].get_text(),
'date': parse_date(h3s[i].string[:-3], '%A %d %B %Y'), 'date': parse_date(h3s[i].string[:-3], '%A %d %B %Y'),

View File

@ -31,7 +31,12 @@ class Cache:
@wraps(f) @wraps(f)
def wrapper(*args, **kwds): def wrapper(*args, **kwds):
connector = args[0] connector = args[0]
key = 'pynyaata.%s.%s.%s.%s' % (connector.__class__.__name__, f.__name__, connector.query, connector.page) key = 'pynyaata.%s.%s.%s.%s' % (
connector.__class__.__name__,
f.__name__,
connector.query,
connector.page
)
if REDIS_ENABLED: if REDIS_ENABLED:
json = None json = None
@ -82,9 +87,18 @@ def curl_content(url, params=None, ajax=False, debug=True):
try: try:
if not instance.is_behind_cloudflare: if not instance.is_behind_cloudflare:
if method == 'post': if method == 'post':
response = requests.post(url, params, timeout=REQUESTS_TIMEOUT, headers=headers) response = requests.post(
url,
params,
timeout=REQUESTS_TIMEOUT,
headers=headers
)
else: else:
response = requests.get(url, timeout=REQUESTS_TIMEOUT, headers=headers) response = requests.get(
url,
timeout=REQUESTS_TIMEOUT,
headers=headers
)
output = response.text output = response.text
http_code = response.status_code http_code = response.status_code
@ -97,7 +111,10 @@ def curl_content(url, params=None, ajax=False, debug=True):
response_session = loads(json_session.text) response_session = loads(json_session.text)
cloudproxy_session = response_session['session'] cloudproxy_session = response_session['session']
headers['Content-Type'] = 'application/x-www-form-urlencoded' if (method == 'post') else 'application/json' if method == 'post':
headers['Content-Type'] = 'application/x-www-form-urlencoded'
else:
headers['Content-Type'] = 'application/json'
json_response = requests.post(CLOUDPROXY_ENDPOINT, headers=headers, data=dumps({ json_response = requests.post(CLOUDPROXY_ENDPOINT, headers=headers, data=dumps({
'cmd': 'request.%s' % method, 'cmd': 'request.%s' % method,

View File

@ -17,7 +17,12 @@ class Nyaa(ConnectorCore):
if self.return_type is ConnectorReturn.HISTORY: if self.return_type is ConnectorReturn.HISTORY:
sort_type = 'id' sort_type = 'id'
to_query = '(%s vf)|(%s vostfr)|(%s multi)|(%s french)' % (self.query, self.query, self.query, self.query) to_query = '(%s vf)|(%s vostfr)|(%s multi)|(%s french)' % (
self.query,
self.query,
self.query,
self.query
)
return '%s/?f=0&c=1_3&s=%s&o=desc&q=%s&p=%s' % (self.base_url, sort_type, to_query, self.page) return '%s/?f=0&c=1_3&s=%s&o=desc&q=%s&p=%s' % (self.base_url, sort_type, to_query, self.page)
def get_history(self): def get_history(self):

View File

@ -17,7 +17,12 @@ class Pantsu(ConnectorCore):
if self.return_type is ConnectorReturn.HISTORY: if self.return_type is ConnectorReturn.HISTORY:
sort_type = 2 sort_type = 2
to_query = '(%s vf)|(%s vostfr)|(%s multi)|(%s french)' % (self.query, self.query, self.query, self.query) to_query = '(%s vf)|(%s vostfr)|(%s multi)|(%s french)' % (
self.query,
self.query,
self.query,
self.query
)
return '%s/search/%s?c=3_13&order=false&q=%s&sort=%s' % (self.base_url, self.page, to_query, sort_type) return '%s/search/%s?c=3_13&order=false&q=%s&sort=%s' % (self.base_url, self.page, to_query, sort_type)
def get_history(self): def get_history(self):

View File

@ -21,7 +21,9 @@ class YggTorrent(ConnectorCore):
sort_type = 'size' sort_type = 'size'
if self.return_type is ConnectorReturn.HISTORY: if self.return_type is ConnectorReturn.HISTORY:
sort_type = 'publish_date' sort_type = 'publish_date'
sort_page = '&page=%s' % ((self.page - 1) * 50) if self.page > 1 else '' sort_page = '&page=%s' % (
(self.page - 1) * 50
) if self.page > 1 else ''
return '%s/engine/search?name=%s&category=2145&sub_category=%s&do=search&order=desc&sort=%s%s' % ( return '%s/engine/search?name=%s&category=2145&sub_category=%s&do=search&order=desc&sort=%s%s' % (
self.base_url, self.query, self.category, sort_type, sort_page self.base_url, self.query, self.category, sort_type, sort_page
@ -65,7 +67,8 @@ class YggTorrent(ConnectorCore):
(url['href'], tds[3].decode_contents()), (url['href'], tds[3].decode_contents()),
'link': '<a href="%s/engine/download_torrent?id=%s">' 'link': '<a href="%s/engine/download_torrent?id=%s">'
'<i class="fa fa-fw fa-download"></i>' '<i class="fa fa-fw fa-download"></i>'
'</a>' % (self.base_url, re.search(r'/(\d+)', url['href']).group(1)), '</a>' % (self.base_url,
re.search(r'/(\d+)', url['href']).group(1)),
'size': tds[5].get_text(), 'size': tds[5].get_text(),
'date': parse_date(datetime.fromtimestamp(int(tds[4].div.get_text()))), 'date': parse_date(datetime.fromtimestamp(int(tds[4].div.get_text()))),
'seeds': check_seeds, 'seeds': check_seeds,

View File

@ -3,17 +3,33 @@ from .config import db
class AnimeFolder(db.Model): class AnimeFolder(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(length=100, collation='utf8mb4_general_ci'), unique=True, nullable=False) name = db.Column(db.String(
length=100,
collation='utf8mb4_general_ci'
), unique=True, nullable=False)
path = db.Column(db.String(length=100, collation='utf8mb4_general_ci')) path = db.Column(db.String(length=100, collation='utf8mb4_general_ci'))
titles = db.relationship("AnimeTitle", backref="folder", cascade='all,delete-orphan') titles = db.relationship(
"AnimeTitle",
backref="folder",
cascade='all,delete-orphan'
)
class AnimeTitle(db.Model): class AnimeTitle(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(length=100, collation='utf8mb4_general_ci'), unique=True, nullable=False) name = db.Column(db.String(
keyword = db.Column(db.Text(collation='utf8mb4_general_ci'), nullable=False) length=100,
collation='utf8mb4_general_ci'
), unique=True, nullable=False)
keyword = db.Column(db.Text(
collation='utf8mb4_general_ci'
), nullable=False)
folder_id = db.Column(db.Integer, db.ForeignKey('anime_folder.id')) folder_id = db.Column(db.Integer, db.ForeignKey('anime_folder.id'))
links = db.relationship('AnimeLink', backref="title", cascade='all,delete-orphan') links = db.relationship(
'AnimeLink',
backref="title",
cascade='all,delete-orphan'
)
class AnimeLink(db.Model): class AnimeLink(db.Model):