Refactor again

This commit is contained in:
Michel Roux 2019-11-30 18:09:30 +01:00
parent 79f847316c
commit 682aa72031
4 changed files with 165 additions and 161 deletions

5
app.py
View File

@ -52,5 +52,6 @@ def admin():
if __name__ == '__main__':
app_debug = environ.get('FLASK_ENV', 'production') is 'development'
app.run('0.0.0.0', debug=app_debug)
app_debug = environ.get('FLASK_ENV', 'production') == 'development'
app_port = environ.get('FLASK_PORT', 5000)
app.run('0.0.0.0', app_port, app_debug)

View File

@ -23,7 +23,7 @@ class Connector(ABC):
self.category = category
self.data = []
self.is_more = False
self.on_error = False
self.on_error = True
self.page = page
self.return_type = return_type
@ -32,19 +32,18 @@ class Connector(ABC):
pass
@abstractmethod
def __search(self):
def search(self):
pass
@abstractmethod
def __get_history(self):
def get_history(self):
pass
def run(self):
if not len(self.data):
if self.on_error:
if self.return_type is ConnectorReturn.SEARCH:
self.__search()
self.search()
elif self.return_type is ConnectorReturn.HISTORY:
self.__get_history()
self.get_history()
return self
def curl_content(self, url, params=None, ajax=False):
@ -116,10 +115,11 @@ class Nyaa(Connector):
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):
self.__search()
def get_history(self):
self.search()
def __search(self):
def search(self):
if self.on_error:
response = self.curl_content(self.get_full_search_url())
if response['http_code'] is 200:
@ -156,7 +156,8 @@ class Nyaa(Connector):
'name': self.boldify(url.string),
'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,
'date': '%s:00' % tds[4].string,
'seeds': check_seeds,
@ -165,9 +166,8 @@ class Nyaa(Connector):
'class': 'is-%s' % tr['class'][0]
})
self.on_error = False
self.is_more = valid_trs is not len(trs)
else:
self.on_error = True
class Pantsu(Connector):
@ -184,10 +184,11 @@ class Pantsu(Connector):
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):
self.__search()
def get_history(self):
self.search()
def __search(self):
def search(self):
if self.on_error:
response = self.curl_content(self.get_full_search_url())
if response['http_code'] is 200:
@ -229,9 +230,8 @@ class Pantsu(Connector):
'class': 'is-%s' % tr['class'][0]
})
self.on_error = False
self.is_more = valid_trs is not len(trs)
else:
self.on_error = True
class YggTorrent(Connector):
@ -249,13 +249,11 @@ class YggTorrent(Connector):
self.base_url, sort_type, self.category, self.query, self.page
)
def __get_history(self):
self.__search()
def get_history(self):
self.search()
def __search(self):
if self.category is None:
self.on_error = True
else:
def search(self):
if self.category and self.on_error:
response = self.curl_content(self.get_full_search_url())
if response['http_code'] is 200:
@ -285,8 +283,9 @@ class YggTorrent(Connector):
'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),
'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)),
'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)),
'size': tds[5].string,
'date': datetime.fromtimestamp(int(tds[4].div.string)).strftime('%Y-%m-%d %H:%M:%S'),
'seeds': check_seeds,
@ -295,9 +294,8 @@ class YggTorrent(Connector):
'class': ''
})
self.on_error = False
self.is_more = valid_trs is not len(trs)
else:
self.on_error = True
class AnimeUltime(Connector):
@ -317,7 +315,8 @@ class AnimeUltime(Connector):
return '%s/%s-0-1/%s' % (self.base_url, sort_type, from_date)
def __search(self):
def search(self):
if self.on_error:
response = self.curl_content(self.get_full_search_url(), {'search': self.query})
if response['http_code'] is 200:
@ -351,14 +350,15 @@ class AnimeUltime(Connector):
self.data.append({
'lang': 'jp',
'href': '%s%s' % (self.get_file_url(), player[0]['data-serie']),
'href': '%s/file-0-1/%s' % (self.base_url, player[0]['data-serie']),
'name': self.boldify(name[0].string),
'type': ani_type[0].string.replace(':', '')
})
else:
self.on_error = True
def __get_history(self):
self.on_error = False
def get_history(self):
if self.on_error:
response = self.curl_content(self.get_full_search_url())
if response['http_code'] is 200:
@ -381,12 +381,14 @@ class AnimeUltime(Connector):
self.data.append({
'lang': 'jp',
'href': '%s%s' % (self.get_full_search_url('file'), link['href']),
'href': '%s/%s' % (self.base_url, link['href']),
'name': link.string,
'type': tds[4].string,
'date': release_date
})
self.on_error = False
class Other(Connector):
color = 'is-danger'
@ -396,8 +398,8 @@ class Other(Connector):
def get_full_search_url(self):
pass
def __search(self):
def search(self):
pass
def __get_history(self):
def get_history(self):
pass

View File

@ -5,11 +5,12 @@ services:
build: .
ports:
- "5000:5000"
entrypoint: flask run -h 0.0.0.0
entrypoint: python3 app.py
working_dir: /app
environment:
FLASK_APP: app.py
FLASK_ENV: development
FLASK_PORT: 5000
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_DATABASE: www

View File

@ -27,7 +27,7 @@
{% for connector in connectors %}
{% for torrent in connector.data %}
{% enfor %}
{% endfor %}
{% endfor %}
</tbody>