From ba552bd1f86c43dbbc6f92342278aa0d55d7799a Mon Sep 17 00:00:00 2001 From: Ade Date: Fri, 8 Aug 2014 22:23:06 +1200 Subject: [PATCH] Torrent seed ratio --- data/interfaces/default/config.html | 156 ++++++++++++++++++---------- headphones/__init__.py | 55 +++++++--- headphones/searcher.py | 34 ++++++ headphones/transmission.py | 11 ++ headphones/utorrent.py | 34 ++++-- headphones/webserve.py | 16 ++- 6 files changed, 234 insertions(+), 72 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index a05578f0..1b25722a 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -382,66 +382,117 @@
Torrents -
- -
-
-
- - + +
+ The Pirate Bay +
+
-
-
- -
-
- -
-
-
- - +
+
+ + +
+
+ + +
-
-
- -
-
-
- - +
+ +
+ Kick Ass Torrents +
+
-
- - +
+
+ + +
+
+ + +
-
-
- -
-
-
- - +
+ +
+ Waffles.fm +
+
-
- - +
+
+ + +
+
+ + +
+
+ + +
-
-
- -
-
-
- - +
+ +
+ rutracker.org +
+
-
- - +
+
+ + +
+
+ + +
+
+ + +
-
+
+ +
+ What.cd +
+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+ Mininova +
+ +
+
+
+ + +
+
+
+ @@ -1745,6 +1796,7 @@ initConfigCheckbox("#useomgwtfnzbs"); initConfigCheckbox("#usekat"); initConfigCheckbox("#usepiratebay"); + initConfigCheckbox("#usemininova"); initConfigCheckbox("#usewaffles"); initConfigCheckbox("#userutracker"); initConfigCheckbox("#usewhatcd"); diff --git a/headphones/__init__.py b/headphones/__init__.py index e80ffb7b..b73df6a6 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -190,18 +190,24 @@ TORRENTBLACKHOLE_DIR = None NUMBEROFSEEDERS = 10 KAT = None KAT_PROXY_URL = None +KAT_RATIO = None MININOVA = None +MININOVA_RATIO = None PIRATEBAY = None PIRATEBAY_PROXY_URL = None +PIRATEBAY_RATIO = None WAFFLES = None WAFFLES_UID = None WAFFLES_PASSKEY = None +WAFFLES_RATIO = None RUTRACKER = None RUTRACKER_USER = None RUTRACKER_PASSWORD = None +RUTRACKER_RATIO = None WHATCD = None WHATCD_USERNAME = None WHATCD_PASSWORD = None +WHATCD_RATIO = None DOWNLOAD_TORRENT_DIR = None INTERFACE = None @@ -346,8 +352,8 @@ def initialize(): LOSSLESS_DESTINATION_DIR, PREFERRED_QUALITY, PREFERRED_BITRATE, DETECT_BITRATE, ADD_ARTISTS, CORRECT_METADATA, MOVE_FILES, \ RENAME_FILES, FOLDER_FORMAT, FILE_FORMAT, FILE_UNDERSCORES, CLEANUP_FILES, KEEP_NFO, INCLUDE_EXTRAS, EXTRAS, AUTOWANT_UPCOMING, AUTOWANT_ALL, KEEP_TORRENT_FILES, PREFER_TORRENTS, OPEN_MAGNET_LINKS, \ ADD_ALBUM_ART, ALBUM_ART_FORMAT, EMBED_ALBUM_ART, EMBED_LYRICS, REPLACE_EXISTING_FOLDERS, DOWNLOAD_DIR, BLACKHOLE, BLACKHOLE_DIR, USENET_RETENTION, SEARCH_INTERVAL, \ - TORRENTBLACKHOLE_DIR, NUMBEROFSEEDERS, KAT, KAT_PROXY_URL, PIRATEBAY, PIRATEBAY_PROXY_URL, MININOVA, WAFFLES, WAFFLES_UID, WAFFLES_PASSKEY, \ - RUTRACKER, RUTRACKER_USER, RUTRACKER_PASSWORD, WHATCD, WHATCD_USERNAME, WHATCD_PASSWORD, DOWNLOAD_TORRENT_DIR, \ + TORRENTBLACKHOLE_DIR, NUMBEROFSEEDERS, KAT, KAT_PROXY_URL, KAT_RATIO, PIRATEBAY, PIRATEBAY_PROXY_URL, PIRATEBAY_RATIO, MININOVA, MININOVA_RATIO, WAFFLES, WAFFLES_UID, WAFFLES_PASSKEY, WAFFLES_RATIO, \ + RUTRACKER, RUTRACKER_USER, RUTRACKER_PASSWORD, RUTRACKER_RATIO, WHATCD, WHATCD_USERNAME, WHATCD_PASSWORD, WHATCD_RATIO, DOWNLOAD_TORRENT_DIR, \ LIBRARYSCAN, LIBRARYSCAN_INTERVAL, DOWNLOAD_SCAN_INTERVAL, UPDATE_DB_INTERVAL, MB_IGNORE_AGE, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \ NZBGET_USERNAME, NZBGET_PASSWORD, NZBGET_CATEGORY, NZBGET_HOST, HEADPHONES_INDEXER, NZBMATRIX, TRANSMISSION_HOST, TRANSMISSION_USERNAME, TRANSMISSION_PASSWORD, \ UTORRENT_HOST, UTORRENT_USERNAME, UTORRENT_PASSWORD, UTORRENT_LABEL, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, NEWZNAB_ENABLED, EXTRA_NEWZNABS, \ @@ -378,6 +384,9 @@ def initialize(): CheckSection('Newznab') CheckSection('NZBsorg') CheckSection('omgwtfnzbs') + CheckSection('Piratebay') + CheckSection('Kat') + CheckSection('Mininova') CheckSection('Waffles') CheckSection('Rutracker') CheckSection('What.cd') @@ -478,24 +487,34 @@ def initialize(): TORRENTBLACKHOLE_DIR = check_setting_str(CFG, 'General', 'torrentblackhole_dir', '') NUMBEROFSEEDERS = check_setting_str(CFG, 'General', 'numberofseeders', '10') - KAT = bool(check_setting_int(CFG, 'General', 'kat', 0)) - KAT_PROXY_URL = check_setting_str(CFG, 'General', 'kat_proxy_url', '') - PIRATEBAY = bool(check_setting_int(CFG, 'General', 'piratebay', 0)) - PIRATEBAY_PROXY_URL = check_setting_str(CFG, 'General', 'piratebay_proxy_url', '') - MININOVA = bool(check_setting_int(CFG, 'General', 'mininova', 0)) DOWNLOAD_TORRENT_DIR = check_setting_str(CFG, 'General', 'download_torrent_dir', '') + KAT = bool(check_setting_int(CFG, 'Kat', 'kat', 0)) + KAT_PROXY_URL = check_setting_str(CFG, 'Kat', 'kat_proxy_url', '') + KAT_RATIO = check_setting_str(CFG, 'Kat', 'kat_ratio', '') + + PIRATEBAY = bool(check_setting_int(CFG, 'Piratebay', 'piratebay', 0)) + PIRATEBAY_PROXY_URL = check_setting_str(CFG, 'Piratebay', 'piratebay_proxy_url', '') + PIRATEBAY_RATIO = check_setting_str(CFG, 'Piratebay', 'piratebay_ratio', '') + + MININOVA = bool(check_setting_int(CFG, 'Mininova', 'mininova', 0)) + MININOVA_RATIO = check_setting_str(CFG, 'Mininova', 'mininova_ratio', '') + WAFFLES = bool(check_setting_int(CFG, 'Waffles', 'waffles', 0)) WAFFLES_UID = check_setting_str(CFG, 'Waffles', 'waffles_uid', '') WAFFLES_PASSKEY = check_setting_str(CFG, 'Waffles', 'waffles_passkey', '') + WAFFLES_RATIO = check_setting_str(CFG, 'Waffles', 'waffles_ratio', '') RUTRACKER = bool(check_setting_int(CFG, 'Rutracker', 'rutracker', 0)) RUTRACKER_USER = check_setting_str(CFG, 'Rutracker', 'rutracker_user', '') RUTRACKER_PASSWORD = check_setting_str(CFG, 'Rutracker', 'rutracker_password', '') + RUTRACKER_RATIO = check_setting_str(CFG, 'Rutracker', 'rutracker_ratio', '') WHATCD = bool(check_setting_int(CFG, 'What.cd', 'whatcd', 0)) WHATCD_USERNAME = check_setting_str(CFG, 'What.cd', 'whatcd_username', '') WHATCD_PASSWORD = check_setting_str(CFG, 'What.cd', 'whatcd_password', '') + WHATCD_RATIO = check_setting_str(CFG, 'What.cd', 'whatcd_ratio', '') + WHATCD_PASSWORD = check_setting_str(CFG, 'What.cd', 'whatcd_password', '') SAB_HOST = check_setting_str(CFG, 'SABnzbd', 'sab_host', '') SAB_USERNAME = check_setting_str(CFG, 'SABnzbd', 'sab_username', '') @@ -895,27 +914,39 @@ def config_write(): new_config['General']['numberofseeders'] = NUMBEROFSEEDERS new_config['General']['torrentblackhole_dir'] = TORRENTBLACKHOLE_DIR - new_config['General']['kat'] = int(KAT) - new_config['General']['kat_proxy_url'] = KAT_PROXY_URL - new_config['General']['mininova'] = int(MININOVA) - new_config['General']['piratebay'] = int(PIRATEBAY) - new_config['General']['piratebay_proxy_url'] = PIRATEBAY_PROXY_URL new_config['General']['download_torrent_dir'] = DOWNLOAD_TORRENT_DIR + new_config['Kat'] = {} + new_config['Kat']['kat'] = int(KAT) + new_config['Kat']['kat_proxy_url'] = KAT_PROXY_URL + new_config['Kat']['kat_ratio'] = KAT_RATIO + + new_config['Mininova'] = {} + new_config['Mininova']['mininova'] = int(MININOVA) + new_config['Mininova']['mininova_ratio'] = MININOVA_RATIO + + new_config['Piratebay'] = {} + new_config['Piratebay']['piratebay'] = int(PIRATEBAY) + new_config['Piratebay']['piratebay_proxy_url'] = PIRATEBAY_PROXY_URL + new_config['Piratebay']['piratebay_ratio'] = PIRATEBAY_RATIO + new_config['Waffles'] = {} new_config['Waffles']['waffles'] = int(WAFFLES) new_config['Waffles']['waffles_uid'] = WAFFLES_UID new_config['Waffles']['waffles_passkey'] = WAFFLES_PASSKEY + new_config['Waffles']['waffles_ratio'] = WAFFLES_RATIO new_config['Rutracker'] = {} new_config['Rutracker']['rutracker'] = int(RUTRACKER) new_config['Rutracker']['rutracker_user'] = RUTRACKER_USER new_config['Rutracker']['rutracker_password'] = RUTRACKER_PASSWORD + new_config['Rutracker']['rutracker_ratio'] = RUTRACKER_RATIO new_config['What.cd'] = {} new_config['What.cd']['whatcd'] = int(WHATCD) new_config['What.cd']['whatcd_username'] = WHATCD_USERNAME new_config['What.cd']['whatcd_password'] = WHATCD_PASSWORD + new_config['What.cd']['whatcd_ratio'] = WHATCD_RATIO new_config['General']['search_interval'] = SEARCH_INTERVAL new_config['General']['libraryscan'] = int(LIBRARYSCAN) diff --git a/headphones/searcher.py b/headphones/searcher.py index ef889d5c..06293f08 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -698,6 +698,11 @@ def send_to_downloader(data, bestqual, album): except Exception as e: logger.exception("Unhandled exception") + # Set Seed Ratio + seed_ratio = getSeedRatio(bestqual[3]) + if seed_ratio != None: + transmission.setSeedRatio(torrentid, seed_ratio) + else:# if headphones.TORRENT_DOWNLOADER == 2: logger.info("Sending torrent to uTorrent") @@ -725,6 +730,11 @@ def send_to_downloader(data, bestqual, album): except Exception as e: logger.exception("Unhandled exception") + # Set Seed Ratio + seed_ratio = getSeedRatio(bestqual[3]) + if seed_ratio != None: + utorrent.setSeedRatio(_hash, seed_ratio) + myDB = db.DBConnection() myDB.action('UPDATE albums SET status = "Snatched" WHERE AlbumID=?', [album['AlbumID']]) myDB.action('INSERT INTO snatched VALUES( ?, ?, ?, ?, DATETIME("NOW", "localtime"), ?, ?, ?)', [album['AlbumID'], bestqual[0], bestqual[1], bestqual[2], "Snatched", folder_name, kind]) @@ -1351,3 +1361,27 @@ def CalculateTorrentHash(link, data): logger.debug('Torrent Hash: ' + str(tor_hash)) return tor_hash + +def getSeedRatio(provider): + seed_ratio = '' + if provider == 'rutracker.org': + seed_ratio = headphones.RUTRACKER_RATIO + elif provider == 'Kick Ass Torrents': + seed_ratio = headphones.KAT_RATIO + elif provider == 'What.cd': + seed_ratio = headphones.WHATCD_RATIO + elif provider == 'The Pirate Bay': + seed_ratio = headphones.PIRATEBAY_RATIO + elif provider == 'Waffles.fm': + seed_ratio = headphones.WAFFLES_RATIO + elif provider == 'Mininova': + seed_ratio = headphones.MININOVA_RATIO + if seed_ratio != '': + try: + seed_ratio_float = float(seed_ratio) + except: + seed_ratio_float = None + logger.warn('Could not get Seed Ratio for %s' % provider) + return seed_ratio_float + else: + return None \ No newline at end of file diff --git a/headphones/transmission.py b/headphones/transmission.py index 17ad434e..13a24de4 100644 --- a/headphones/transmission.py +++ b/headphones/transmission.py @@ -82,6 +82,17 @@ def getTorrentFolder(torrentid): return torrent_folder_name +def setSeedRatio(torrentid, ratio): + method = 'torrent-set' + if ratio != 0: + arguments = {'seedRatioLimit': ratio, 'seedRatioMode': 1, 'ids': torrentid} + else: + arguments = {'seedRatioMode': 2, 'ids': torrentid} + + response = torrentAction(method, arguments) + if not response: + return False + def torrentAction(method, arguments): host = headphones.TRANSMISSION_HOST diff --git a/headphones/utorrent.py b/headphones/utorrent.py index 914409f7..b98456c0 100644 --- a/headphones/utorrent.py +++ b/headphones/utorrent.py @@ -155,7 +155,16 @@ def labelTorrent(hash): if label: uTorrentClient.setprops(hash,'label',label) -def dirTorrent(hash, cacheid=None): +def setSeedRatio(hash, ratio): + uTorrentClient = utorrentclient() + uTorrentClient.setprops(hash, 'seed_override', '1') + if ratio != 0: + uTorrentClient.setprops(hash,'seed_ratio', ratio * 10) + else: + # TODO passing -1 should be unlimited + uTorrentClient.setprops(hash,'seed_ratio', -1.00) + +def dirTorrent(hash, cacheid=None, return_name=None): uTorrentClient = utorrentclient() @@ -174,7 +183,10 @@ def dirTorrent(hash, cacheid=None): for torrent in torrents: if (torrent[0].lower() == hash): - return torrent[26], cacheid + if not return_name: + return torrent[26], cacheid + else: + return torrent[2], cacheid return None, None @@ -184,6 +196,10 @@ def addTorrent(link, hash): # Get Active Directory from settings active_dir, completed_dir = getSettingsDirectories() + if not active_dir or not completed_dir: + logger.error('Could not get "Put new downloads in:" or "Move completed downloads to:" directories from uTorrent settings, please ensure they are set') + return None + uTorrentClient.add_url(link) # Get Torrent Folder Name @@ -197,8 +213,9 @@ def addTorrent(link, hash): time.sleep(6) torrent_folder, cacheid = dirTorrent(hash, cacheid) - if torrent_folder == active_dir: - return None + if torrent_folder == active_dir or not torrent_folder: + torrent_folder, cacheid = dirTorrent(hash, cacheid, return_name=True) + return torrent_folder else: labelTorrent(hash) return os.path.basename(os.path.normpath(torrent_folder)) @@ -206,6 +223,11 @@ def addTorrent(link, hash): def getSettingsDirectories(): uTorrentClient = utorrentclient() settings = uTorrentClient.get_settings() - active = settings['dir_active_download'][2] - completed = settings['dir_completed_download'][2] + active = None + completed = None + if 'dir_active_download' in settings: + active = settings['dir_active_download'][2] + if 'dir_completed_download' in settings: + completed = settings['dir_completed_download'][2] return active, completed + diff --git a/headphones/webserve.py b/headphones/webserve.py index af8198b6..fa1a9c54 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1008,18 +1008,24 @@ class WebInterface(object): "numberofseeders" : headphones.NUMBEROFSEEDERS, "use_kat" : checked(headphones.KAT), "kat_proxy_url" : headphones.KAT_PROXY_URL, + "kat_ratio": headphones.KAT_RATIO, "use_piratebay" : checked(headphones.PIRATEBAY), "piratebay_proxy_url" : headphones.PIRATEBAY_PROXY_URL, + "piratebay_ratio": headphones.PIRATEBAY_RATIO, "use_mininova" : checked(headphones.MININOVA), + "mininova_ratio": headphones.MININOVA_RATIO, "use_waffles" : checked(headphones.WAFFLES), "waffles_uid" : headphones.WAFFLES_UID, "waffles_passkey": headphones.WAFFLES_PASSKEY, + "waffles_ratio": headphones.WAFFLES_RATIO, "use_rutracker" : checked(headphones.RUTRACKER), "rutracker_user" : headphones.RUTRACKER_USER, "rutracker_password": headphones.RUTRACKER_PASSWORD, + "rutracker_ratio": headphones.RUTRACKER_RATIO, "use_whatcd" : checked(headphones.WHATCD), "whatcd_username" : headphones.WHATCD_USERNAME, "whatcd_password": headphones.WHATCD_PASSWORD, + "whatcd_ratio": headphones.WHATCD_RATIO, "pref_qual_0" : radio(headphones.PREFERRED_QUALITY, 0), "pref_qual_1" : radio(headphones.PREFERRED_QUALITY, 1), "pref_qual_3" : radio(headphones.PREFERRED_QUALITY, 3), @@ -1159,8 +1165,8 @@ class WebInterface(object): utorrent_host=None, utorrent_username=None, utorrent_password=None, utorrent_label=None,nzb_downloader=0, torrent_downloader=0, download_dir=None, blackhole_dir=None, usenet_retention=None, use_headphones_indexer=0, newznab=0, newznab_host=None, newznab_apikey=None, newznab_enabled=0, nzbsorg=0, nzbsorg_uid=None, nzbsorg_hash=None, omgwtfnzbs=0, omgwtfnzbs_uid=None, omgwtfnzbs_apikey=None, preferred_words=None, required_words=None, ignored_words=None, preferred_quality=0, preferred_bitrate=None, detect_bitrate=0, move_files=0, torrentblackhole_dir=None, download_torrent_dir=None, - numberofseeders=None, use_piratebay=0, piratebay_proxy_url=None, use_kat=0, kat_proxy_url=None, use_mininova=0, waffles=0, waffles_uid=None, waffles_passkey=None, whatcd=0, whatcd_username=None, whatcd_password=None, - rutracker=0, rutracker_user=None, rutracker_password=None, rename_files=0, correct_metadata=0, cleanup_files=0, keep_nfo=0, add_album_art=0, album_art_format=None, embed_album_art=0, embed_lyrics=0, replace_existing_folders=False, + numberofseeders=None, use_piratebay=0, piratebay_proxy_url=None, piratebay_ratio=None, use_kat=0, kat_proxy_url=None, kat_ratio=None, use_mininova=0, mininova_ratio=None, waffles=0, waffles_uid=None, waffles_passkey=None, waffles_ratio=None, whatcd=0, whatcd_username=None, whatcd_password=None, whatcd_ratio=None, + rutracker=0, rutracker_user=None, rutracker_password=None, rutracker_ratio=None, rename_files=0, correct_metadata=0, cleanup_files=0, keep_nfo=0, add_album_art=0, album_art_format=None, embed_album_art=0, embed_lyrics=0, replace_existing_folders=False, destination_dir=None, lossless_destination_dir=None, folder_format=None, file_format=None, file_underscores=0, include_extras=0, single=0, ep=0, compilation=0, soundtrack=0, live=0, remix=0, djmix=0, mixtape_street=0, broadcast=0, interview=0, spokenword=0, audiobook=0, other=0, autowant_upcoming=False, autowant_all=False, keep_torrent_files=False, prefer_torrents=0, open_magnet_links=0, interface=None, log_dir=None, cache_dir=None, music_encoder=0, encoder=None, xldprofile=None, bitrate=None, samplingfrequency=None, encoderfolder=None, advancedencoder=None, encoderoutputformat=None, encodervbrcbr=None, encoderquality=None, encoderlossless=0, @@ -1227,18 +1233,24 @@ class WebInterface(object): headphones.DOWNLOAD_TORRENT_DIR = download_torrent_dir headphones.KAT = use_kat headphones.KAT_PROXY_URL = kat_proxy_url + headphones.KAT_RATIO = kat_ratio headphones.PIRATEBAY = use_piratebay headphones.PIRATEBAY_PROXY_URL = piratebay_proxy_url + headphones.PIRATEBAY_RATIO = piratebay_ratio headphones.MININOVA = use_mininova + headphones.MININOVA_RATIO = mininova_ratio headphones.WAFFLES = waffles headphones.WAFFLES_UID = waffles_uid headphones.WAFFLES_PASSKEY = waffles_passkey + headphones.WAFFLES_RATIO = waffles_ratio headphones.RUTRACKER = rutracker headphones.RUTRACKER_USER = rutracker_user headphones.RUTRACKER_PASSWORD = rutracker_password + headphones.RUTRACKER_RATIO = rutracker_ratio headphones.WHATCD = whatcd headphones.WHATCD_USERNAME = whatcd_username headphones.WHATCD_PASSWORD = whatcd_password + headphones.WHATCD_RATIO = whatcd_ratio headphones.PREFERRED_QUALITY = int(preferred_quality) headphones.PREFERRED_BITRATE = preferred_bitrate headphones.PREFERRED_BITRATE_HIGH_BUFFER = preferred_bitrate_high_buffer