diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 114704a7..a6a55200 100755 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -53,12 +53,14 @@ def checkFolder(): else: download_dir = headphones.CONFIG.DOWNLOAD_TORRENT_DIR - # Qbittorrent - get folder from torrent hash - if album['TorrentHash']: - if headphones.CONFIG.TORRENT_DOWNLOADER == 4: + # Get folder from torrent hash + if album['TorrentHash'] and headphones.CONFIG.TORRENT_DOWNLOADER: + if headphones.CONFIG.TORRENT_DOWNLOADER == 1: + torrent_folder_name, single = transmission.getFolder(album['TorrentHash']) + elif headphones.CONFIG.TORRENT_DOWNLOADER == 4: torrent_folder_name, single = qbittorrent.getFolder(album['TorrentHash']) - if torrent_folder_name: - folder_name = torrent_folder_name + if torrent_folder_name: + folder_name = torrent_folder_name if folder_name: album_path = os.path.join(download_dir, folder_name).encode( diff --git a/headphones/searcher.py b/headphones/searcher.py index 3d2acde3..b0652f7f 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -928,11 +928,11 @@ def send_to_downloader(data, bestqual, album): logger.error("Error sending torrent to Transmission. Are you sure it's running?") return - folder_name = transmission.getTorrentFolder(torrentid) + folder_name = transmission.getName(torrentid) if folder_name: - logger.info('Torrent folder name: %s' % folder_name) + logger.info('Torrent name: %s' % folder_name) else: - logger.error('Torrent folder name could not be determined') + logger.error('Torrent name could not be determined') return # Set Seed Ratio @@ -1723,7 +1723,7 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None, if headphones.CONFIG.PIRATEBAY_PROXY_URL: providerurl = fix_url(set_proxy(headphones.CONFIG.PIRATEBAY_PROXY_URL)) else: - providerurl = fix_url("https://thepiratebay.se") + providerurl = fix_url("https://thepiratebay.org") # Build URL providerurl = providerurl + "/search/" + tpb_term + "/0/7/" # 7 is sort by seeders @@ -1951,7 +1951,7 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None, if headphones.CONFIG.TQUATTRECENTONZE: username = headphones.CONFIG.TQUATTRECENTONZE_USER password = headphones.CONFIG.TQUATTRECENTONZE_PASSWORD - API_URL = "http://api.t411.li" + API_URL = "http://api.t411.ai" AUTH_URL = API_URL + '/auth' DL_URL = API_URL + '/torrents/download/' provider = "t411" diff --git a/headphones/transmission.py b/headphones/transmission.py index 3e436617..54241751 100644 --- a/headphones/transmission.py +++ b/headphones/transmission.py @@ -17,6 +17,7 @@ import time import json import base64 import urlparse +import os from headphones import logger, request import headphones @@ -64,7 +65,31 @@ def addTorrent(link, data=None): return False -def getTorrentFolder(torrentid): +def getFolder(torrentid): + torrent_folder = None + single_file = False + method = 'torrent-get' + arguments = {'ids': torrentid, 'fields': ['files']} + + response = torrentAction(method, arguments) + + try: + torrent_files = response['arguments']['torrents'][0]['files'] + if torrent_files: + if len(torrent_files) == 1: + torrent_folder = torrent_files[0]['name'] + single_file = True + else: + torrent_folder = os.path.split(torrent_files[0]['name'])[0] + single_file = False + except: + torrent_folder = None + single_file = False + + return torrent_folder, single_file + + +def getName(torrentid): method = 'torrent-get' arguments = {'ids': torrentid, 'fields': ['name', 'percentDone']}