Back to Idea

This commit is contained in:
Michel Roux 2019-11-28 16:07:26 +01:00
parent cba10eef59
commit 44ef6eec34
3 changed files with 36 additions and 26 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
.vscode/ .idea/
.venv/ .venv/
.db/ .db/
__pycache__/ __pycache__/

1
app.py
View File

@ -29,6 +29,7 @@ def requires_auth(f):
if not auth or not check_auth(auth.username, auth.password): if not auth or not check_auth(auth.username, auth.password):
return authenticate() return authenticate()
return f(*args, **kwargs) return f(*args, **kwargs)
return decorated return decorated

View File

@ -31,23 +31,25 @@ class Connector(ABC):
def get_history(self, sort_type, page, category): def get_history(self, sort_type, page, category):
pass pass
def curl_content(self, url, params={}, ajax=False): def curl_content(self, url, params=None, ajax=False):
if isinstance(self, YggTorrent): if isinstance(self, YggTorrent):
try: try:
qt_env = {'QT_QPA_PLATFORM': 'offscreen'} if platform is 'linux' else {} qt_env = {'QT_QPA_PLATFORM': 'offscreen'} if platform is 'linux' else {}
qt_output = run('phantomjs --cookies-file=/tmp/cookies.json delay.js "%s" 5000' % url, env=qt_env, shell=True, check=True, capture_output=True, timeout=7000) qt_output = run('phantomjs --cookies-file=/tmp/cookies.json delay.js "%s" 5000' % url, env=qt_env,
shell=True, check=True, capture_output=True, timeout=7000)
output = qt_output.stdout output = qt_output.stdout
http_code = 200 http_code = 200
except Exception as e: except Exception as e:
output = '' output = ''
http_code = 500 http_code = 500
print(e)
else: else:
if ajax: if ajax:
headers = {'X-Requested-With': 'XMLHttpRequest'} headers = {'X-Requested-With': 'XMLHttpRequest'}
else: else:
headers = {} headers = {}
if params: if params is not None:
response = requests.post(url, params, timeout=10, headers=headers) response = requests.post(url, params, timeout=10, headers=headers)
else: else:
response = requests.get(url, timeout=10, headers=headers) response = requests.get(url, timeout=10, headers=headers)
@ -57,19 +59,21 @@ class Connector(ABC):
return {'http_code': http_code, 'output': output} return {'http_code': http_code, 'output': output}
def get_instance(self, url): @staticmethod
def get_instance(url, query):
if 'nyaa.si' in url: if 'nyaa.si' in url:
return Nyaa() return Nyaa(query)
elif 'nyaa.net' in url: elif 'nyaa.net' in url:
return Pantsu() return Pantsu(query)
elif 'anime-ultime' in url: elif 'anime-ultime' in url:
return AnimeUltime() return AnimeUltime(query)
elif 'ygg' in url: elif 'ygg' in url:
return YggTorrent() return YggTorrent(query)
else: else:
return Other() return Other(query)
def get_lang(self, str_to_test): @staticmethod
def get_lang(str_to_test):
if re.search('(vf|multi|french)', str_to_test, re.IGNORECASE): if re.search('(vf|multi|french)', str_to_test, re.IGNORECASE):
return 'fr' return 'fr'
else: else:
@ -133,7 +137,8 @@ class Nyaa(Connector):
'lang': self.get_lang(url.string), 'lang': self.get_lang(url.string),
'href': '%s%s' % (self.base_url, url['href']), 'href': '%s%s' % (self.base_url, url['href']),
'name': self.boldify(url.string), 'name': self.boldify(url.string),
'comment': str(urls[0]).replace('/view/', '%s%s' % (self.base_url, '/view/')) if has_comment else '', 'comment': str(urls[0]).replace('/view/',
'%s%s' % (self.base_url, '/view/')) if has_comment else '',
'link': tds[2].decode_contents().replace('/download/', '%s%s' % (self.base_url, '/download/')), 'link': tds[2].decode_contents().replace('/download/', '%s%s' % (self.base_url, '/download/')),
'size': tds[3].string, 'size': tds[3].string,
'date': '%s:00' % tds[4].string, 'date': '%s:00' % tds[4].string,
@ -143,10 +148,9 @@ class Nyaa(Connector):
'class': 'is-%s' % tr['class'][0] 'class': 'is-%s' % tr['class'][0]
}) })
return (data, valid_trs is not len(trs)) return data, valid_trs is not len(trs)
else: else:
raise ConnectorException(self.title) raise ConnectorException(self.title)
return (data, False)
class Pantsu(Connector): class Pantsu(Connector):
@ -194,19 +198,20 @@ class Pantsu(Connector):
'href': '%s%s' % (self.base_url, url['href']), 'href': '%s%s' % (self.base_url, url['href']),
'name': self.boldify(url.string), 'name': self.boldify(url.string),
'comment': '', 'comment': '',
'link': tds[2].decode_contents().replace('icon-magnet', 'fa fa-fw fa-magnet').replace('icon-floppy', 'fa fa-fw fa-download'), 'link': tds[2].decode_contents().replace('icon-magnet', 'fa fa-fw fa-magnet').replace(
'icon-floppy', 'fa fa-fw fa-download'),
'size': tds[3].string, 'size': tds[3].string,
'date': datetime.strptime(tds[7]['title'], '%m/%d/%Y, %I:%M:%S %p %Z+0').strftime('%Y-%m-%d %H:%M:%S'), 'date': datetime.strptime(tds[7]['title'], '%m/%d/%Y, %I:%M:%S %p %Z+0').strftime(
'%Y-%m-%d %H:%M:%S'),
'seeds': check_seeds, 'seeds': check_seeds,
'leechs': tds[5].string, 'leechs': tds[5].string,
'downloads': check_downloads, 'downloads': check_downloads,
'class': 'is-%s' % tr['class'][0] 'class': 'is-%s' % tr['class'][0]
}) })
return (data, valid_trs is not len(trs)) return data, valid_trs is not len(trs)
else: else:
raise ConnectorException(self.title) raise ConnectorException(self.title)
return (data, False)
class YggTorrent(Connector): class YggTorrent(Connector):
@ -220,7 +225,8 @@ class YggTorrent(Connector):
if category is None: if category is None:
raise ConnectorException(self.title) raise ConnectorException(self.title)
return '%s/engine/search?do=search&order=desc&sort=%s&category=2145&sub_category=%s&name=%s&page=%s' % (self.base_url, sort_type, category, self.query, page) return '%s/engine/search?do=search&order=desc&sort=%s&category=2145&sub_category=%s&name=%s&page=%s' % (
self.base_url, sort_type, category, self.query, page)
def get_history(self, sort_type=default_sort, page=1, category=None): def get_history(self, sort_type=default_sort, page=1, category=None):
if category is None: if category is None:
@ -261,8 +267,10 @@ class YggTorrent(Connector):
'lang': self.get_lang(url.string), 'lang': self.get_lang(url.string),
'href': url['href'], 'href': url['href'],
'name': self.boldify(url.string), 'name': self.boldify(url.string),
'comment': '<a href="%s#comm" target="_blank"><i class="fa fa-comments-o"></i>%s</a>' % (url['href'], tds[3].string), 'comment': '<a href="%s#comm" target="_blank"><i class="fa fa-comments-o"></i>%s</a>' % (
'link': '<a href="%s/engine/download_torrent?id=%s"><i class="fa fa-fw fa-download"></i></a>' % (self.base_url, re.search('/(\d+)', url['href']).group(1)), url['href'], tds[3].string),
'link': '<a href="%s/engine/download_torrent?id=%s"><i class="fa fa-fw fa-download"></i></a>' % (
self.base_url, re.search('/(\d+)', url['href']).group(1)),
'size': tds[5].string, 'size': tds[5].string,
'date': datetime.fromtimestamp(int(tds[4].div.string)).strftime('%Y-%m-%d %H:%M:%S'), 'date': datetime.fromtimestamp(int(tds[4].div.string)).strftime('%Y-%m-%d %H:%M:%S'),
'seeds': check_seeds, 'seeds': check_seeds,
@ -271,10 +279,9 @@ class YggTorrent(Connector):
'class': '' 'class': ''
}) })
return (data, valid_trs is len(trs)) return data, valid_trs is len(trs)
else: else:
raise ConnectorException(self.title) raise ConnectorException(self.title)
return (data, False)
class AnimeUltime(Connector): class AnimeUltime(Connector):
@ -332,9 +339,10 @@ class AnimeUltime(Connector):
'name': self.boldify(name[0].string), 'name': self.boldify(name[0].string),
'type': ani_type[0].string.replace(':', '') 'type': ani_type[0].string.replace(':', '')
}) })
return data, False
else: else:
raise ConnectorException(self.title) raise ConnectorException(self.title)
return (data, False)
def get_history(self, sort_type=default_sort, page=1, category=None): def get_history(self, sort_type=default_sort, page=1, category=None):
data = [] data = []
@ -365,9 +373,10 @@ class AnimeUltime(Connector):
'type': tds[4].string, 'type': tds[4].string,
'date': release_date 'date': release_date
}) })
return data
else: else:
raise ConnectorException(self.title) raise ConnectorException(self.title)
return data
class Other(Connector): class Other(Connector):