Private GIT

Skip to content
Snippets Groups Projects
Commit 39c5dc61 authored by Yoann Laissus's avatar Yoann Laissus Committed by miigotu
Browse files

Update the YggTorrent provider due to the new version of the website

parent 7f82bb14
No related branches found
No related tags found
No related merge requests found
...@@ -48,7 +48,7 @@ class YggTorrentProvider(TorrentProvider): # pylint: disable=too-many-instance- ...@@ -48,7 +48,7 @@ class YggTorrentProvider(TorrentProvider): # pylint: disable=too-many-instance-
self.minleech = None self.minleech = None
# URLs # URLs
self.url = 'https://yggtorrent.com/' self.url = 'https://yggtorrent.is/'
self.urls = { self.urls = {
'login': urljoin(self.url, 'user/login'), 'login': urljoin(self.url, 'user/login'),
'search': urljoin(self.url, 'engine/search') 'search': urljoin(self.url, 'engine/search')
...@@ -69,16 +69,25 @@ class YggTorrentProvider(TorrentProvider): # pylint: disable=too-many-instance- ...@@ -69,16 +69,25 @@ class YggTorrentProvider(TorrentProvider): # pylint: disable=too-many-instance-
'pass': self.password, 'pass': self.password,
} }
response = self.get_url(self.urls['login'], post_data=login_params, returns='text') response = self.get_url(self.urls['login'], post_data=login_params, returns='response')
if not response: # When you call /login if it's OK, it's return 200 with no body, i retry in main if it's logged !
response = self.get_url(self.url, returns='text') # The login is now an AJAX call (401 : Bad credentials, 200 : Logged in, other : server failure)
if not response: # The provider is dead !!! if response.status_code == 401:
logger.log('Unable to connect to provider', logger.WARNING) logger.log('Invalid username or password. Check your settings', logger.WARNING)
return False return False
elif response.status_code == 200:
# It seems we are logged, let's verify that !
response = self.get_url(self.url, returns='response')
if 'logout' not in response: if response.status_code != 200:
logger.log('Unable to connect to provider', logger.WARNING)
return False
if 'logout' not in response.text:
logger.log('Invalid username or password. Check your settings', logger.WARNING) logger.log('Invalid username or password. Check your settings', logger.WARNING)
return False return False
else:
logger.log('Unable to connect to provider', logger.WARNING)
return False
return True return True
...@@ -112,15 +121,16 @@ class YggTorrentProvider(TorrentProvider): # pylint: disable=too-many-instance- ...@@ -112,15 +121,16 @@ class YggTorrentProvider(TorrentProvider): # pylint: disable=too-many-instance-
try: try:
search_params = { search_params = {
'category': "2145", 'category': "2145",
'subcategory' : "2184", 'sub_category' : "2184",
'q': re.sub(r'[()]', '', search_string) 'name': re.sub(r'[()]', '', search_string),
'do': 'search'
} }
data = self.get_url(self.urls['search'], params=search_params, returns='text') data = self.get_url(self.urls['search'], params=search_params, returns='text')
if not data: if not data:
continue continue
with BS4Parser(data, 'html5lib') as html: with BS4Parser(data, 'html5lib') as html:
torrent_table = html.find(class_='table table-striped') torrent_table = html.find(class_='table')
torrent_rows = torrent_table('tr') if torrent_table else [] torrent_rows = torrent_table('tr') if torrent_table else []
# Continue only if at least one Release is found # Continue only if at least one Release is found
...@@ -131,23 +141,20 @@ class YggTorrentProvider(TorrentProvider): # pylint: disable=too-many-instance- ...@@ -131,23 +141,20 @@ class YggTorrentProvider(TorrentProvider): # pylint: disable=too-many-instance-
# Skip column headers # Skip column headers
for result in torrent_rows[1:]: for result in torrent_rows[1:]:
cells = result('td') cells = result('td')
if len(cells) < 5: if len(cells) < 9:
continue continue
download_url = "" title = cells[1].find('a').get_text(strip=True)
title = cells[0].find('a', class_='torrent-name').get_text(strip=True) id = cells[2].find('a')['target']
for download_img in cells[0].select('a[href] img'): download_url = urljoin(self.url, 'engine/download_torrent?id=' + id)
if download_img['src'] == urljoin(self.url,"static/icons/icon_download.gif"):
download_url = urljoin(self.url, download_img.parent['href'])
break
if not (title and download_url): if not (title and download_url):
continue continue
seeders = try_int(cells[4].get_text(strip=True)) seeders = try_int(cells[7].get_text(strip=True))
leechers = try_int(cells[5].get_text(strip=True)) leechers = try_int(cells[8].get_text(strip=True))
torrent_size = cells[2].get_text() torrent_size = cells[5].get_text()
size = convert_size(torrent_size) or -1 size = convert_size(torrent_size) or -1
# Filter unseeded torrent # Filter unseeded torrent
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment