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)
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']):
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>')
def latest(page=1):
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 = []
for torrent in torrents:
@ -136,7 +138,10 @@ def admin():
if form.validate_on_submit():
link = AnimeLink.query.filter_by(id=form.id.data).first()
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.commit()
@ -145,7 +150,9 @@ def admin():
db.session.delete(title)
db.session.commit()
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()
for folder in folders:
@ -169,7 +176,9 @@ def folder_list():
db.session.delete(folder)
db.session.commit()
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()
@ -183,7 +192,12 @@ def folder_list():
def folder_edit(folder_id=None):
folder = AnimeFolder.query.filter_by(id=folder_id).first()
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():
# Folder
@ -246,9 +260,15 @@ def admin_edit(link_id=None):
# Transmission
if TRANSMISSION_ENABLED and isinstance(instance, Nyaa):
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 = 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.start_torrent(torrent.id)

View File

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

View File

@ -31,7 +31,12 @@ class Cache:
@wraps(f)
def wrapper(*args, **kwds):
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:
json = None
@ -82,9 +87,18 @@ def curl_content(url, params=None, ajax=False, debug=True):
try:
if not instance.is_behind_cloudflare:
if method == 'post':
response = requests.post(url, params, timeout=REQUESTS_TIMEOUT, headers=headers)
response = requests.post(
url,
params,
timeout=REQUESTS_TIMEOUT,
headers=headers
)
else:
response = requests.get(url, timeout=REQUESTS_TIMEOUT, headers=headers)
response = requests.get(
url,
timeout=REQUESTS_TIMEOUT,
headers=headers
)
output = response.text
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)
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({
'cmd': 'request.%s' % method,

View File

@ -17,7 +17,12 @@ class Nyaa(ConnectorCore):
if self.return_type is ConnectorReturn.HISTORY:
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)
def get_history(self):

View File

@ -17,7 +17,12 @@ class Pantsu(ConnectorCore):
if self.return_type is ConnectorReturn.HISTORY:
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)
def get_history(self):

View File

@ -21,7 +21,9 @@ class YggTorrent(ConnectorCore):
sort_type = 'size'
if self.return_type is ConnectorReturn.HISTORY:
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' % (
self.base_url, self.query, self.category, sort_type, sort_page
@ -65,7 +67,8 @@ class YggTorrent(ConnectorCore):
(url['href'], tds[3].decode_contents()),
'link': '<a href="%s/engine/download_torrent?id=%s">'
'<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(),
'date': parse_date(datetime.fromtimestamp(int(tds[4].div.get_text()))),
'seeds': check_seeds,

View File

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