From 2f07d952b222321787acdf9ceb1c3dfdd01dcf9b Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sun, 8 Sep 2013 14:57:17 +0530 Subject: [PATCH 1/6] Added file_permissions to config & post processor --- headphones/__init__.py | 5 ++++- headphones/postprocessor.py | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/headphones/__init__.py b/headphones/__init__.py index 78803803..fcf72106 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -197,6 +197,7 @@ DOWNLOAD_TORRENT_DIR = None INTERFACE = None FOLDER_PERMISSIONS = None +FILE_PERMISSIONS = None MUSIC_ENCODER = False ENCODERFOLDER = None @@ -304,7 +305,7 @@ def initialize(): NZBGET_USERNAME, NZBGET_PASSWORD, NZBGET_CATEGORY, NZBGET_HOST, HEADPHONES_INDEXER, NZBMATRIX, TRANSMISSION_HOST, TRANSMISSION_USERNAME, TRANSMISSION_PASSWORD, \ UTORRENT_HOST, UTORRENT_USERNAME, UTORRENT_PASSWORD, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, NEWZNAB_ENABLED, EXTRA_NEWZNABS, \ NZBSORG, NZBSORG_UID, NZBSORG_HASH, NZBSRUS, NZBSRUS_UID, NZBSRUS_APIKEY, NZB_DOWNLOADER, TORRENT_DOWNLOADER, PREFERRED_WORDS, REQUIRED_WORDS, IGNORED_WORDS, \ - LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, ENCODERFOLDER, ENCODER_PATH, ENCODER, XLDPROFILE, BITRATE, SAMPLINGFREQUENCY, \ + LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, FILE_PERMISSIONS, ENCODERFOLDER, ENCODER_PATH, ENCODER, XLDPROFILE, BITRATE, SAMPLINGFREQUENCY, \ MUSIC_ENCODER, ADVANCEDENCODER, ENCODEROUTPUTFORMAT, ENCODERQUALITY, ENCODERVBRCBR, ENCODERLOSSLESS, DELETE_LOSSLESS_FILES, \ PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, PUSHOVER_ENABLED, PUSHOVER_PRIORITY, PUSHOVER_KEYS, PUSHOVER_ONSNATCH, MIRRORLIST, \ MIRROR, CUSTOMHOST, CUSTOMPORT, CUSTOMSLEEP, HPUSER, HPPASS, XBMC_ENABLED, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, XBMC_UPDATE, \ @@ -470,6 +471,7 @@ def initialize(): INTERFACE = check_setting_str(CFG, 'General', 'interface', 'default') FOLDER_PERMISSIONS = check_setting_str(CFG, 'General', 'folder_permissions', '0755') + FILE_PERSMISSIONS = check_setting_str(CFG, 'General', 'file_permissions', '0644') ENCODERFOLDER = check_setting_str(CFG, 'General', 'encoderfolder', '') ENCODER_PATH = check_setting_str(CFG, 'General', 'encoder_path', '') @@ -873,6 +875,7 @@ def config_write(): new_config['General']['lastfm_username'] = LASTFM_USERNAME new_config['General']['interface'] = INTERFACE new_config['General']['folder_permissions'] = FOLDER_PERMISSIONS + new_config['General']['file_permissions'] = FILE_PERMISSIONS new_config['General']['music_encoder'] = int(MUSIC_ENCODER) new_config['General']['encoder'] = ENCODER diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 132ec931..485028fb 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -395,6 +395,8 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list, else: albumpaths = [albumpath] + updateFilePermissions(albumpaths) + myDB = db.DBConnection() myDB.action('UPDATE albums SET status = "Downloaded" WHERE AlbumID=?', [albumid]) myDB.action('UPDATE snatched SET status = "Processed" WHERE AlbumID=?', [albumid]) @@ -860,7 +862,20 @@ def renameFiles(albumpath, downloaded_track_list, release): except Exception, e: logger.error('Error renaming file: %s. Error: %s' % (downloaded_track.decode(headphones.SYS_ENCODING, 'replace'), e)) continue - + +def updateFilePermissions(albumpaths): + + for folder in albumpaths: + logger.info("Updating file permissions in " + folder.decode(headphones.SYS_ENCODING, 'replace')) + for r,d,f in os.walk(folder): + for files in f: + full_path = os.path.join(r, files) + try: + os.chmod(full_path, headphones.FILE_PERMISSIONS) + except: + logger.error("Could not change permissions for file: " + full_path.decode(headphones.SYS_ENCODING, 'replace')) + continue + def renameUnprocessedFolder(albumpath): i = 0 From 2e1c9d7f84fa173c7bc82977a7e044b65f6d9d3e Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sun, 8 Sep 2013 15:03:23 +0530 Subject: [PATCH 2/6] Added file permissions & folder permissions to config page --- data/interfaces/default/config.html | 8 ++++++++ headphones/webserve.py | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index a087b2af..3be397e2 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -685,6 +685,14 @@
+
+ + +
+
+ + +
diff --git a/headphones/webserve.py b/headphones/webserve.py index 1807409f..5aa452ef 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -696,7 +696,9 @@ class WebInterface(object): "customsleep": headphones.CUSTOMSLEEP, "hpuser": headphones.HPUSER, "hppass": headphones.HPPASS, - "cache_sizemb":headphones.CACHE_SIZEMB, + "cache_sizemb": headphones.CACHE_SIZEMB, + "file_permissions": headphones.FILE_PERMISSIONS, + "folder_permissions": headphones.FOLDER_PERMISSIONS } # Need to convert EXTRAS to a dictionary we can pass to the config: it'll come in as a string like 2,5,6,8 @@ -731,7 +733,7 @@ class WebInterface(object): xbmc_update=0, xbmc_notify=0, nma_enabled=False, nma_apikey=None, nma_priority=0, nma_onsnatch=0, synoindex_enabled=False, pushover_enabled=0, pushover_onsnatch=0, pushover_keys=None, pushover_priority=0, mirror=None, customhost=None, customport=None, customsleep=None, hpuser=None, hppass=None, preferred_bitrate_high_buffer=None, preferred_bitrate_low_buffer=None, preferred_bitrate_allow_lossless=0, cache_sizemb=None, - enable_https=0, https_cert=None, https_key=None, **kwargs): + enable_https=0, https_cert=None, https_key=None, file_permissions=None, folder_permissions=None, **kwargs): headphones.HTTP_HOST = http_host headphones.HTTP_PORT = http_port @@ -860,6 +862,8 @@ class WebInterface(object): headphones.HPUSER = hpuser headphones.HPPASS = hppass headphones.CACHE_SIZEMB = int(cache_sizemb) + headphones.FILE_PERMISSIONS = file_permissions + headphones.FOLDER_PERMISSIONS = folder_permissions # Handle the variable config options. Note - keys with False values aren't getting passed From d9cd120ca8c0ddcac52fb32b01491d18485710fb Mon Sep 17 00:00:00 2001 From: rembo10 Date: Mon, 9 Sep 2013 14:20:34 +0530 Subject: [PATCH 3/6] Fixed a typo, int() the permissions string --- headphones/__init__.py | 2 +- headphones/postprocessor.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/headphones/__init__.py b/headphones/__init__.py index fcf72106..3959f1fc 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -471,7 +471,7 @@ def initialize(): INTERFACE = check_setting_str(CFG, 'General', 'interface', 'default') FOLDER_PERMISSIONS = check_setting_str(CFG, 'General', 'folder_permissions', '0755') - FILE_PERSMISSIONS = check_setting_str(CFG, 'General', 'file_permissions', '0644') + FILE_PERMISSIONS = check_setting_str(CFG, 'General', 'file_permissions', '0644') ENCODERFOLDER = check_setting_str(CFG, 'General', 'encoderfolder', '') ENCODER_PATH = check_setting_str(CFG, 'General', 'encoder_path', '') diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 485028fb..ba61ef91 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -871,7 +871,7 @@ def updateFilePermissions(albumpaths): for files in f: full_path = os.path.join(r, files) try: - os.chmod(full_path, headphones.FILE_PERMISSIONS) + os.chmod(full_path, int(headphones.FILE_PERMISSIONS)) except: logger.error("Could not change permissions for file: " + full_path.decode(headphones.SYS_ENCODING, 'replace')) continue From 5c60019d38b9bde54ff80c4ad09e3d00fc5a9ede Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sat, 21 Sep 2013 11:33:18 +0530 Subject: [PATCH 4/6] Use int(x,8) for file permissions --- headphones/postprocessor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index ba61ef91..368bd770 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -871,7 +871,7 @@ def updateFilePermissions(albumpaths): for files in f: full_path = os.path.join(r, files) try: - os.chmod(full_path, int(headphones.FILE_PERMISSIONS)) + os.chmod(full_path, int(headphones.FILE_PERMISSIONS, 8)) except: logger.error("Could not change permissions for file: " + full_path.decode(headphones.SYS_ENCODING, 'replace')) continue From 6f8f2c292b8685392f70ec077db54af61642f2d4 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Mon, 23 Sep 2013 18:27:27 +0530 Subject: [PATCH 5/6] Added ability to use a piratebay proxy to the backend --- headphones/__init__.py | 5 ++++- headphones/searcher.py | 15 ++++++++++++++- headphones/webserve.py | 4 +++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/headphones/__init__.py b/headphones/__init__.py index 3959f1fc..234d2cea 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -184,6 +184,7 @@ ISOHUNT = None KAT = None MININOVA = None PIRATEBAY = None +PIRATEBAY_PROXY_URL = None WAFFLES = None WAFFLES_UID = None WAFFLES_PASSKEY = None @@ -299,7 +300,7 @@ 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, INCLUDE_EXTRAS, EXTRAS, AUTOWANT_UPCOMING, AUTOWANT_ALL, KEEP_TORRENT_FILES, \ ADD_ALBUM_ART, ALBUM_ART_FORMAT, EMBED_ALBUM_ART, EMBED_LYRICS, DOWNLOAD_DIR, BLACKHOLE, BLACKHOLE_DIR, USENET_RETENTION, SEARCH_INTERVAL, \ - TORRENTBLACKHOLE_DIR, NUMBEROFSEEDERS, ISOHUNT, KAT, PIRATEBAY, MININOVA, WAFFLES, WAFFLES_UID, WAFFLES_PASSKEY, \ + TORRENTBLACKHOLE_DIR, NUMBEROFSEEDERS, ISOHUNT, KAT, PIRATEBAY, PIRATEBAY_PROXY_URL, MININOVA, WAFFLES, WAFFLES_UID, WAFFLES_PASSKEY, \ RUTRACKER, RUTRACKER_USER, RUTRACKER_PASSWORD, WHATCD, WHATCD_USERNAME, WHATCD_PASSWORD, DOWNLOAD_TORRENT_DIR, \ LIBRARYSCAN, LIBRARYSCAN_INTERVAL, DOWNLOAD_SCAN_INTERVAL, 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, \ @@ -410,6 +411,7 @@ def initialize(): ISOHUNT = bool(check_setting_int(CFG, 'General', 'isohunt', 0)) KAT = bool(check_setting_int(CFG, 'General', 'kat', 0)) 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', '') @@ -768,6 +770,7 @@ def config_write(): new_config['General']['kat'] = int(KAT) 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['Waffles'] = {} diff --git a/headphones/searcher.py b/headphones/searcher.py index 3472499a..eb227622 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -1075,7 +1075,20 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False): # Pirate Bay if headphones.PIRATEBAY: provider = "The Pirate Bay" - providerurl = url_fix("http://thepiratebay.sx/search/" + term + "/0/99/") + if headphones.PIRATEBAY_PROXY_URL: + #Might need to clean up the user submitted url + pirate_proxy = headphones.PIRATEBAY_PROXY_URL + + if not pirate_proxy.startswith('http'): + pirate_proxy = 'http://' + pirate_proxy + if pirate_proxy.endswith('/'): + pirate_proxy = pirate_proxy[:-1] + + providerurl = url_fix(pirate_proxy + "/search/" + term + "/0/99/") + + else: + providerurl = url_fix("http://thepiratebay.sx/search/" + term + "/0/99/") + if headphones.PREFERRED_QUALITY == 3 or losslessOnly: category = '104' #flac maxsize = 10000000000 diff --git a/headphones/webserve.py b/headphones/webserve.py index 5aa452ef..3477c293 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -619,6 +619,7 @@ class WebInterface(object): "use_isohunt" : checked(headphones.ISOHUNT), "use_kat" : checked(headphones.KAT), "use_piratebay" : checked(headphones.PIRATEBAY), + "piratebay_proxy_url" : headphones.PIRATEBAY_PROXY_URL, "use_mininova" : checked(headphones.MININOVA), "use_waffles" : checked(headphones.WAFFLES), "waffles_uid" : headphones.WAFFLES_UID, @@ -724,7 +725,7 @@ class WebInterface(object): utorrent_host=None, utorrent_username=None, utorrent_password=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, nzbsrus=0, nzbsrus_uid=None, nzbsrus_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, use_isohunt=0, use_kat=0, use_mininova=0, waffles=0, waffles_uid=None, waffles_passkey=None, whatcd=0, whatcd_username=None, whatcd_password=None, + numberofseeders=None, use_piratebay=0, piratebay_proxy_url=None, use_isohunt=0, use_kat=0, 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, add_album_art=0, album_art_format=None, embed_album_art=0, embed_lyrics=0, 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, spokenword=0, audiobook=0, autowant_upcoming=False, autowant_all=False, keep_torrent_files=False, interface=None, log_dir=None, cache_dir=None, music_encoder=0, encoder=None, xldprofile=None, @@ -788,6 +789,7 @@ class WebInterface(object): headphones.ISOHUNT = use_isohunt headphones.KAT = use_kat headphones.PIRATEBAY = use_piratebay + headphones.PIRATEBAY_PROXY_URL = piratebay_proxy_url headphones.MININOVA = use_mininova headphones.WAFFLES = waffles headphones.WAFFLES_UID = waffles_uid From 8a6c37bcf6ef3f71e8aea028b0130baa42687a13 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Mon, 23 Sep 2013 18:44:11 +0530 Subject: [PATCH 6/6] Added piratebay proxy url to config page --- data/interfaces/default/config.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 3be397e2..b4246cfe 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -359,7 +359,13 @@
Torrents
- + +
+
+
+ + +
@@ -1253,6 +1259,7 @@ initConfigCheckbox("#usenewznab"); initConfigCheckbox("#usenzbsrus"); initConfigCheckbox("#usenzbsorg"); + initConfigCheckbox("#usepiratebay"); initConfigCheckbox("#usewaffles"); initConfigCheckbox("#userutracker"); initConfigCheckbox("#usewhatcd");