From 23e3dd91b3f3337c424fffdf538d5a7bb578b6ea Mon Sep 17 00:00:00 2001 From: Begall Date: Mon, 2 Jun 2014 21:22:31 +0100 Subject: [PATCH] Add ability to rename .nfo file to .nfo-orig --- data/interfaces/default/config.html | 1 + headphones/__init__.py | 5 ++++- headphones/postprocessor.py | 23 +++++++++++++++++++---- headphones/webserve.py | 4 +++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 5ee7a95b..f832b35d 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -525,6 +525,7 @@ +
diff --git a/headphones/__init__.py b/headphones/__init__.py index 82e2a5d6..a84dc54a 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -111,6 +111,7 @@ CORRECT_METADATA = False MOVE_FILES = False RENAME_FILES = False CLEANUP_FILES = False +KEEP_NFO = False ADD_ALBUM_ART = False ALBUM_ART_FORMAT = None EMBED_ALBUM_ART = False @@ -347,7 +348,7 @@ def initialize(): HTTP_PORT, HTTP_HOST, HTTP_USERNAME, HTTP_PASSWORD, HTTP_ROOT, HTTP_PROXY, LAUNCH_BROWSER, API_ENABLED, API_KEY, GIT_PATH, GIT_USER, GIT_BRANCH, DO_NOT_OVERRIDE_GIT_BRANCH, \ CURRENT_VERSION, LATEST_VERSION, CHECK_GITHUB, CHECK_GITHUB_ON_STARTUP, CHECK_GITHUB_INTERVAL, MUSIC_DIR, DESTINATION_DIR, \ 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, PREFER_TORRENTS, OPEN_MAGNET_LINKS, \ + 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, 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, \ @@ -453,6 +454,7 @@ def initialize(): FILE_FORMAT = check_setting_str(CFG, 'General', 'file_format', 'Track Artist - Album [Year] - Title') FILE_UNDERSCORES = bool(check_setting_int(CFG, 'General', 'file_underscores', 0)) CLEANUP_FILES = bool(check_setting_int(CFG, 'General', 'cleanup_files', 0)) + KEEP_NFO = bool(check_setting_int(CFG, 'General', 'keep_nfo', 0)) ADD_ALBUM_ART = bool(check_setting_int(CFG, 'General', 'add_album_art', 0)) 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)) @@ -882,6 +884,7 @@ def config_write(): new_config['General']['file_format'] = FILE_FORMAT new_config['General']['file_underscores'] = int(FILE_UNDERSCORES) new_config['General']['cleanup_files'] = int(CLEANUP_FILES) + new_config['General']['keep_nfo'] = int(KEEP_NFO) new_config['General']['add_album_art'] = int(ADD_ALBUM_ART) new_config['General']['album_art_format'] = ALBUM_ART_FORMAT new_config['General']['embed_album_art'] = int(EMBED_ALBUM_ART) diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index e8f18d28..5ca5509d 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -388,6 +388,9 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list, if headphones.CLEANUP_FILES: cleanupFiles(albumpath) + + if headphones.KEEP_NFO: + renameNFO(albumpath) if headphones.ADD_ALBUM_ART and artwork: addAlbumArt(artwork, albumpath, release) @@ -557,11 +560,23 @@ def cleanupFiles(albumpath): for r,d,f in os.walk(albumpath): for files in f: if not any(files.lower().endswith('.' + x.lower()) for x in headphones.MEDIA_FORMATS): - logger.debug('Removing: %s' % files) - try: - os.remove(os.path.join(r, files)) + if not (headphones.KEEP_NFO and files.lower().endswith('.nfo')): + logger.debug('Removing: %s' % files) + try: + os.remove(os.path.join(r, files)) + except Exception, e: + logger.error(u'Could not remove file: %s. Error: %s' % (files.decode(headphones.SYS_ENCODING, 'replace'), e)) + +def renameNFO(albumpath): + for r,d,f in os.walk(albumpath): + for file in f: + if file.lower().endswith('.nfo'): + logger.debug('Renaming: "%s" to "%s"' % (file.decode(headphones.SYS_ENCODING, 'replace'), file.decode(headphones.SYS_ENCODING, 'replace') + '-orig')) + try: + new_file_name = os.path.join(r, file)[:-3] + 'orig.nfo' + os.rename(os.path.join(r, file), new_file_name) except Exception, e: - logger.error(u'Could not remove file: %s. Error: %s' % (files.decode(headphones.SYS_ENCODING, 'replace'), e)) + logger.error(u'Could not rename file: %s. Error: %s' % (os.path.join(r, file).decode(headphones.SYS_ENCODING, 'replace'), e)) def moveFiles(albumpath, release, tracks): diff --git a/headphones/webserve.py b/headphones/webserve.py index 3a7c6f16..f923fe88 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1014,6 +1014,7 @@ class WebInterface(object): "rename_files" : checked(headphones.RENAME_FILES), "correct_metadata" : checked(headphones.CORRECT_METADATA), "cleanup_files" : checked(headphones.CLEANUP_FILES), + "keep_nfo" : checked(headphones.KEEP_NFO), "add_album_art" : checked(headphones.ADD_ALBUM_ART), "album_art_format" : headphones.ALBUM_ART_FORMAT, "embed_album_art" : checked(headphones.EMBED_ALBUM_ART), @@ -1138,7 +1139,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, replace_existing_folders=False, + 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, 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, 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, @@ -1232,6 +1233,7 @@ class WebInterface(object): headphones.CORRECT_METADATA = correct_metadata headphones.RENAME_FILES = rename_files headphones.CLEANUP_FILES = cleanup_files + headphones.KEEP_NFO = keep_nfo headphones.ADD_ALBUM_ART = add_album_art headphones.ALBUM_ART_FORMAT = album_art_format headphones.EMBED_ALBUM_ART = embed_album_art