From 47ed1e6a7129fc1f6fe69534a85053f5f93a8098 Mon Sep 17 00:00:00 2001 From: Ade Date: Sat, 8 Nov 2014 08:33:45 +1300 Subject: [PATCH] Searcher and torrent fixes Should fix https://github.com/rembo10/headphones/issues/1990 and https://github.com/rembo10/headphones/issues/1991 --- headphones/searcher.py | 12 +++++++----- headphones/utorrent.py | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/headphones/searcher.py b/headphones/searcher.py index d874508c..5de7d785 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -87,7 +87,7 @@ def torrent_to_file(target_file, data): # Try to change permissions try: - os.chmod(target_file, int(headphones.FILE_PERMISSIONS, 8)) + os.chmod(target_file, int(headphones.CONFIG.FILE_PERMISSIONS, 8)) except OSError as e: logger.warn("Could not change permissions for file '%s': %s. " \ "Continuing.", target_file, e.message) @@ -762,7 +762,7 @@ def send_to_downloader(data, bestqual, album): except Exception as e: logger.error("Error opening magnet link: %s" % str(e)) return - elif headphones.MAGNET_LINKS == 2: + elif headphones.CONFIG.MAGNET_LINKS == 2: # Procedure adapted from CouchPotato torrent_hash = calculate_torrent_hash(bestqual[2]) @@ -795,8 +795,8 @@ def send_to_downloader(data, bestqual, album): return else: if bestqual[3] == "rutracker.org": - download_path = rutracker.get_torrent(bestqual[2], - headphones.TORRENTBLACKHOLE_DIR) + download_path, _ = rutracker.get_torrent(bestqual[2], + headphones.CONFIG.TORRENTBLACKHOLE_DIR) if not download_path: return @@ -806,6 +806,8 @@ def send_to_downloader(data, bestqual, album): # Extract folder name from torrent folder_name = read_torrent_name(download_path, bestqual[0]) + if folder_name: + logger.info('Torrent folder name: %s' % folder_name) elif headphones.CONFIG.TORRENT_DOWNLOADER == 1: logger.info("Sending torrent to Transmission") @@ -1361,7 +1363,7 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None): try: url = item.find("a", {"title": "Download this torrent"})['href'] except TypeError: - if headphones.MAGNET_LINKS != 0: + if headphones.CONFIG.MAGNET_LINKS != 0: url = item.findAll("a")[3]['href'] else: logger.info('"%s" only has a magnet link, skipping' % title) diff --git a/headphones/utorrent.py b/headphones/utorrent.py index ede1de55..67d9bad7 100644 --- a/headphones/utorrent.py +++ b/headphones/utorrent.py @@ -253,6 +253,8 @@ def addTorrent(link, hash): return torrent_folder else: labelTorrent(hash) + if headphones.SYS_PLATFORM != "win32": + torrent_folder = torrent_folder.replace('\\', '/') return os.path.basename(os.path.normpath(torrent_folder))