From 799aa5c26aaf4814529c3d2ebf2c3b34ae793513 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Thu, 3 Apr 2014 22:12:48 -0700 Subject: [PATCH 1/2] Added option to replace existing folders instead of creating duplicates --- data/interfaces/default/config.html | 27 ++++++++++- data/interfaces/default/css/style.css | 3 ++ headphones/__init__.py | 3 ++ headphones/postprocessor.py | 64 ++++++++++++++++++--------- headphones/webserve.py | 4 +- 5 files changed, 77 insertions(+), 24 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 1cd0f7de..080be032 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -500,7 +500,12 @@
Post-Processing
- + +
+
+ +
+
@@ -1215,6 +1220,26 @@ } }); + if ($("#move_files").is(":checked")) + { + $("#move_files_options").show(); + } + else + { + $("#move_files_options").hide(); + } + + $("#move_files").click(function(){ + if ($("#move_files").is(":checked")) + { + $("#move_files_options").slideDown(); + } + else + { + $("#move_files_options").slideUp(); + } + }); + if ($("#growl").is(":checked")) { $("#growloptions").show(); diff --git a/data/interfaces/default/css/style.css b/data/interfaces/default/css/style.css index 7aedee4a..6a5abe23 100644 --- a/data/interfaces/default/css/style.css +++ b/data/interfaces/default/css/style.css @@ -393,6 +393,9 @@ form .checkbox small { margin: 0 !important; width: auto; } +form .indent input { + margin-left: 15px; +} ul, ol { margin-left: 2em; diff --git a/headphones/__init__.py b/headphones/__init__.py index edd377c0..3fc8bc92 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -115,6 +115,7 @@ ADD_ALBUM_ART = False ALBUM_ART_FORMAT = None EMBED_ALBUM_ART = False EMBED_LYRICS = False +REPLACE_EXISTING_FOLDERS = False NZB_DOWNLOADER = None # 0: sabnzbd, 1: nzbget, 2: blackhole TORRENT_DOWNLOADER = None # 0: blackhole, 1: transmission, 2: utorrent DOWNLOAD_DIR = None @@ -441,6 +442,7 @@ def initialize(): ALBUM_ART_FORMAT = check_setting_str(CFG, 'General', 'album_art_format', 'folder') EMBED_ALBUM_ART = bool(check_setting_int(CFG, 'General', 'embed_album_art', 0)) EMBED_LYRICS = bool(check_setting_int(CFG, 'General', 'embed_lyrics', 0)) + REPLACE_EXISTING_FOLDERS = bool(check_setting_int(CFG, 'General', 'replace_existing_folders', 0)) NZB_DOWNLOADER = check_setting_int(CFG, 'General', 'nzb_downloader', 0) TORRENT_DOWNLOADER = check_setting_int(CFG, 'General', 'torrent_downloader', 0) DOWNLOAD_DIR = check_setting_str(CFG, 'General', 'download_dir', '') @@ -849,6 +851,7 @@ def config_write(): new_config['General']['album_art_format'] = ALBUM_ART_FORMAT new_config['General']['embed_album_art'] = int(EMBED_ALBUM_ART) new_config['General']['embed_lyrics'] = int(EMBED_LYRICS) + new_config['General']['replace_existing_folders'] = int(REPLACE_EXISTING_FOLDERS) new_config['General']['nzb_downloader'] = NZB_DOWNLOADER new_config['General']['torrent_downloader'] = TORRENT_DOWNLOADER new_config['General']['download_dir'] = DOWNLOAD_DIR diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 04c1c526..c45e5ca9 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -608,18 +608,28 @@ def moveFiles(albumpath, release, tracks): if make_lossless_folder: # Only rename the folder if they use the album name, otherwise merge into existing folder if os.path.exists(lossless_destination_path) and 'album' in last_folder.lower(): - - temp_folder = folder - - i = 1 - while True: - newfolder = temp_folder + '[%i]' % i - lossless_destination_path = os.path.normpath(os.path.join(headphones.LOSSLESS_DESTINATION_DIR, newfolder)).encode(headphones.SYS_ENCODING, 'replace') - if os.path.exists(lossless_destination_path): - i += 1 - else: - temp_folder = newfolder - break + + create_duplicate_folder = False + + if headphones.REPLACE_EXISTING_FOLDERS: + try: + shutil.rmtree(lossless_destination_path) + except Exception, e: + logger.error("Error deleting existing folder: %s. Creating duplicate folder. Error: %s" % (lossless_destination_path.decode(headphones.SYS_ENCODING, 'replace'), str(e))) + create_duplicate_folder = True + + if not headphones.REPLACE_EXISTING_FOLDERS or create_duplicate_folder: + temp_folder = folder + + i = 1 + while True: + newfolder = temp_folder + '[%i]' % i + lossless_destination_path = os.path.normpath(os.path.join(headphones.LOSSLESS_DESTINATION_DIR, newfolder)).encode(headphones.SYS_ENCODING, 'replace') + if os.path.exists(lossless_destination_path): + i += 1 + else: + temp_folder = newfolder + break if not os.path.exists(lossless_destination_path): try: @@ -631,18 +641,28 @@ def moveFiles(albumpath, release, tracks): if make_lossy_folder: if os.path.exists(lossy_destination_path) and 'album' in last_folder.lower(): + + create_duplicate_folder = False + + if headphones.REPLACE_EXISTING_FOLDERS: + try: + shutil.rmtree(lossy_destination_path) + except Exception, e: + logger.error("Error deleting existing folder: %s. Creating duplicate folder. Error: %s" % (lossy_destination_path.decode(headphones.SYS_ENCODING, 'replace'), str(e))) + create_duplicate_folder = True - temp_folder = folder + if not headphones.REPLACE_EXISTING_FOLDERS or create_duplicate_folder: + temp_folder = folder - i = 1 - while True: - newfolder = temp_folder + '[%i]' % i - lossy_destination_path = os.path.normpath(os.path.join(headphones.DESTINATION_DIR, newfolder)).encode(headphones.SYS_ENCODING, 'replace') - if os.path.exists(lossy_destination_path): - i += 1 - else: - temp_folder = newfolder - break + i = 1 + while True: + newfolder = temp_folder + '[%i]' % i + lossy_destination_path = os.path.normpath(os.path.join(headphones.DESTINATION_DIR, newfolder)).encode(headphones.SYS_ENCODING, 'replace') + if os.path.exists(lossy_destination_path): + i += 1 + else: + temp_folder = newfolder + break if not os.path.exists(lossy_destination_path): try: diff --git a/headphones/webserve.py b/headphones/webserve.py index b21f10d7..700405e1 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -939,6 +939,7 @@ class WebInterface(object): "album_art_format" : headphones.ALBUM_ART_FORMAT, "embed_album_art" : checked(headphones.EMBED_ALBUM_ART), "embed_lyrics" : checked(headphones.EMBED_LYRICS), + "replace_existing_folders" : checked(headphones.REPLACE_EXISTING_FOLDERS), "dest_dir" : headphones.DESTINATION_DIR, "lossless_dest_dir" : headphones.LOSSLESS_DESTINATION_DIR, "folder_format" : headphones.FOLDER_FORMAT, @@ -1048,7 +1049,7 @@ class WebInterface(object): 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, 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_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, + 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, replace_existing_folders=None, 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, prefer_torrents=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, @@ -1142,6 +1143,7 @@ class WebInterface(object): headphones.ALBUM_ART_FORMAT = album_art_format headphones.EMBED_ALBUM_ART = embed_album_art headphones.EMBED_LYRICS = embed_lyrics + headphones.REPLACE_EXISTING_FOLDERS = replace_existing_folders headphones.DESTINATION_DIR = destination_dir headphones.LOSSLESS_DESTINATION_DIR = lossless_destination_dir headphones.FOLDER_FORMAT = folder_format From a364c435e4c3a15cda1d7fc5c38e9ad32f965a94 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Thu, 3 Apr 2014 22:37:32 -0700 Subject: [PATCH 2/2] Fixed a bug with nzbs --- headphones/searcher.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/headphones/searcher.py b/headphones/searcher.py index d99a8d81..fc427609 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -130,7 +130,7 @@ def searchforalbum(albumid=None, new=False, losslessOnly=False): do_sorted_search(album, new, losslessOnly) else: - logger.info("Got to zero") + album = myDB.action('SELECT * from albums WHERE AlbumID=?', [albumid]).fetchone() logger.info('Searching for %s' % album['AlbumTitle']) do_sorted_search(album, new, losslessOnly) @@ -672,27 +672,27 @@ def send_to_downloader(data, bestqual, album): nzb = classes.NZBDataSearchResult() nzb.extraInfo.append(data) - nzb.name = nzb_folder_name + nzb.name = folder_name nzbget.sendNZB(nzb) elif headphones.NZB_DOWNLOADER == 0: nzb = classes.NZBDataSearchResult() nzb.extraInfo.append(data) - nzb.name = nzb_folder_name + nzb.name = folder_name sab.sendNZB(nzb) # If we sent the file to sab, we can check how it was renamed and insert that into the snatched table (replace_spaces, replace_dots) = sab.checkConfig() if replace_dots: - nzb_folder_name = helpers.sab_replace_dots(nzb_folder_name) + folder_name = helpers.sab_replace_dots(folder_name) if replace_spaces: - nzb_folder_name = helpers.sab_replace_spaces(nzb_folder_name) + folder_name = helpers.sab_replace_spaces(folder_name) else: - nzb_name = nzb_folder_name + '.nzb' + nzb_name = folder_name + '.nzb' download_path = os.path.join(headphones.BLACKHOLE_DIR, nzb_name) try: prev = os.umask(headphones.UMASK)