From eb16244e692735642f2c55a24ae596ea7940a077 Mon Sep 17 00:00:00 2001 From: Aaron Cohen Date: Thu, 27 Sep 2012 00:13:24 -0700 Subject: [PATCH] Adding more verbose errors when login fails --- headphones/searcher.py | 57 +++++++++++++++++++++--------------------- lib/pygazelle/api.py | 2 +- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/headphones/searcher.py b/headphones/searcher.py index e4f17d6f..dcc70f53 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -835,45 +835,44 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False): try: gazelle = gazelleapi.GazelleAPI(headphones.WHATCD_USERNAME, headphones.WHATCD_PASSWORD) - except: + except Exception, e: gazelle = None - logger.warn("What.cd credentials incorrect or site is down.") + logger.warn(u"What.cd credentials incorrect or site is down. Error: %s %s" % (e.__class__.__name__, str(e))) - search_results = {} if gazelle: logger.info(u"Searching %s..." % provider) search_results = gazelle.search_torrents(artistname=semi_clean_artist_term, groupname=semi_clean_album_term, format=format, encoding=bitrate) - # filter on format, size, and num seeders - logger.info(u"Filtering torrents by format, maximum size, and minimum seeders...") - all_torrents = search_results['results'] - match_torrents = [ torrent for torrent in all_torrents if torrent.size <= maxsize ] - match_torrents = [ torrent for torrent in match_torrents if torrent.seeders >= minimumseeders ] + # filter on format, size, and num seeders + logger.info(u"Filtering torrents by format, maximum size, and minimum seeders...") + all_torrents = search_results['results'] + match_torrents = [ torrent for torrent in all_torrents if torrent.size <= maxsize ] + match_torrents = [ torrent for torrent in match_torrents if torrent.seeders >= minimumseeders ] - logger.info(u"Remaining torrents: %s" % ", ".join(repr(torrent) for torrent in match_torrents)) + logger.info(u"Remaining torrents: %s" % ", ".join(repr(torrent) for torrent in match_torrents)) - # sort by times d/l'd - if not len(match_torrents): - logger.info(u"No results found from %s for %s after filtering" % (provider, term)) - elif len(match_torrents) > 1: - logger.info(u"Found %d matching releases from %s for %s - %s after filtering" % - (len(match_torrents), provider, artistterm, albumterm)) - logger.info("Sorting torrents by times snatched and preferred bitrate %s..." % bitrate) - match_torrents.sort(key=lambda x: int(x.snatched), reverse=True) -# if bitrate: -# match_torrents.sort(key=lambda x: re.match("mp3", x.getTorrentDetails(), flags=re.I), reverse=True) -# match_torrents.sort(key=lambda x: str(bitrate) in x.getTorrentFolderName(), reverse=True) - logger.info(u"New order: %s" % ", ".join(repr(torrent) for torrent in match_torrents)) + # sort by times d/l'd + if not len(match_torrents): + logger.info(u"No results found from %s for %s after filtering" % (provider, term)) + elif len(match_torrents) > 1: + logger.info(u"Found %d matching releases from %s for %s - %s after filtering" % + (len(match_torrents), provider, artistterm, albumterm)) + logger.info("Sorting torrents by times snatched and preferred bitrate %s..." % bitrate) + match_torrents.sort(key=lambda x: int(x.snatched), reverse=True) + # if bitrate: + # match_torrents.sort(key=lambda x: re.match("mp3", x.getTorrentDetails(), flags=re.I), reverse=True) + # match_torrents.sort(key=lambda x: str(bitrate) in x.getTorrentFolderName(), reverse=True) + logger.info(u"New order: %s" % ", ".join(repr(torrent) for torrent in match_torrents)) - pre_sorted_results = True - for torrent in match_torrents: - if not torrent.file_path: - torrent.group.update_group_data() # will load the file_path for the individual torrents - resultlist.append((torrent.file_path, - torrent.size, - gazelle.generate_torrent_link(torrent.id), - provider)) + pre_sorted_results = True + for torrent in match_torrents: + if not torrent.file_path: + torrent.group.update_group_data() # will load the file_path for the individual torrents + resultlist.append((torrent.file_path, + torrent.size, + gazelle.generate_torrent_link(torrent.id), + provider)) if headphones.ISOHUNT: provider = "isoHunt" diff --git a/lib/pygazelle/api.py b/lib/pygazelle/api.py index d2290350..9374b323 100644 --- a/lib/pygazelle/api.py +++ b/lib/pygazelle/api.py @@ -68,7 +68,7 @@ class GazelleAPI(object): 'password': self.password} r = self.session.post(loginpage, data=data) if r.status_code != 200: - raise LoginException + raise LoginException("Login error, http code %s" % r.status_code) accountinfo = self.request('index') self.userid = accountinfo['id'] self.authkey = accountinfo['authkey']