From 99a66e4955ec29d8f09bc68e563c7974c396e01f Mon Sep 17 00:00:00 2001 From: rembo10 Date: Fri, 11 Jan 2013 06:25:05 -0500 Subject: [PATCH] Added option to customize album art name --- data/interfaces/default/config.html | 28 +++++++++++++++++++++++++++- headphones/__init__.py | 5 ++++- headphones/postprocessor.py | 27 +++++++++++++++++++++++---- headphones/webserve.py | 4 +++- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index bf9790d8..95d3e2e7 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -371,7 +371,13 @@ - + +
+
+ as .jpg +
+ Use $Artist/$artist, $Album/$album, $Year/$year +
@@ -886,6 +892,26 @@ $("#encoderoptions").slideUp(); } }); + + if ($("#add_album_art").is(":checked")) + { + $("#album_art_options").show(); + } + else + { + $("#album_art_options").hide(); + } + + $("#add_album_art").click(function(){ + if ($("#add_album_art").is(":checked")) + { + $("#album_art_options").slideDown(); + } + else + { + $("#album_art_options").slideUp(); + } + }); if ($("#prowl").is(":checked")) { diff --git a/headphones/__init__.py b/headphones/__init__.py index dbf1c384..7bc31b73 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -104,6 +104,7 @@ MOVE_FILES = False RENAME_FILES = False CLEANUP_FILES = False ADD_ALBUM_ART = False +ALBUM_ART_FORMAT = None EMBED_ALBUM_ART = False EMBED_LYRICS = False DOWNLOAD_DIR = None @@ -274,7 +275,7 @@ def initialize(): 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, CLEANUP_FILES, INCLUDE_EXTRAS, EXTRAS, AUTOWANT_UPCOMING, AUTOWANT_ALL, KEEP_TORRENT_FILES, \ - ADD_ALBUM_ART, EMBED_ALBUM_ART, EMBED_LYRICS, DOWNLOAD_DIR, BLACKHOLE, BLACKHOLE_DIR, USENET_RETENTION, SEARCH_INTERVAL, \ + 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, 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, \ @@ -355,6 +356,7 @@ def initialize(): FILE_FORMAT = check_setting_str(CFG, 'General', 'file_format', 'Track Artist - Album [Year]- Title') CLEANUP_FILES = bool(check_setting_int(CFG, 'General', 'cleanup_files', 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)) EMBED_LYRICS = bool(check_setting_int(CFG, 'General', 'embed_lyrics', 0)) DOWNLOAD_DIR = check_setting_str(CFG, 'General', 'download_dir', '') @@ -678,6 +680,7 @@ def config_write(): new_config['General']['file_format'] = FILE_FORMAT new_config['General']['cleanup_files'] = int(CLEANUP_FILES) 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) new_config['General']['embed_lyrics'] = int(EMBED_LYRICS) new_config['General']['download_dir'] = DOWNLOAD_DIR diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 785ab393..c3f8ac18 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -354,7 +354,7 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list, cleanupFiles(albumpath) if headphones.ADD_ALBUM_ART and artwork: - addAlbumArt(artwork, albumpath) + addAlbumArt(artwork, albumpath, release) if headphones.CORRECT_METADATA: correctMetadata(albumid, release, downloaded_track_list) @@ -425,11 +425,30 @@ def embedAlbumArt(artwork, downloaded_track_list): f.art = artwork f.save() -def addAlbumArt(artwork, albumpath): +def addAlbumArt(artwork, albumpath, release): logger.info('Adding album art to folder') - artwork_file_name = os.path.join(albumpath, 'folder.jpg') - file = open(artwork_file_name, 'wb') + try: + year = release['ReleaseDate'][:4] + except TypeError: + year = '' + + values = { '$Artist': release['ArtistName'], + '$Album': release['AlbumTitle'], + '$Year': year, + '$artist': release['ArtistName'].lower(), + '$album': release['AlbumTitle'].lower(), + '$year': year + } + + album_art_name = helpers.replace_all(headphones.ALBUM_ART_FORMAT.strip(), values).replace('/','_') + ".jpg" + + album_art_name = album_art_name.replace('?','_').replace(':', '_').encode(headphones.SYS_ENCODING, 'replace') + + if album_art_name.startswith('.'): + album_art_name = album_art_name.replace(0, '_') + + file = open(os.path.join(albumpath, album_art_name), 'wb') file.write(artwork) file.close() diff --git a/headphones/webserve.py b/headphones/webserve.py index 8eeb982f..8f13bdbe 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -624,6 +624,7 @@ class WebInterface(object): "correct_metadata" : checked(headphones.CORRECT_METADATA), "cleanup_files" : checked(headphones.CLEANUP_FILES), "add_album_art" : checked(headphones.ADD_ALBUM_ART), + "album_art_format" : headphones.ALBUM_ART_FORMAT, "embed_album_art" : checked(headphones.EMBED_ALBUM_ART), "embed_lyrics" : checked(headphones.EMBED_LYRICS), "dest_dir" : headphones.DESTINATION_DIR, @@ -702,7 +703,7 @@ class WebInterface(object): newznab_enabled=0, nzbsorg=0, nzbsorg_uid=None, nzbsorg_hash=None, nzbsrus=0, nzbsrus_uid=None, nzbsrus_apikey=None, nzbx=0, preferred_quality=0, preferred_bitrate=None, detect_bitrate=0, move_files=0, torrentblackhole_dir=None, download_torrent_dir=None, numberofseeders=10, 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, 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, destination_dir=None, lossless_destination_dir=None, folder_format=None, file_format=None, 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, bitrate=None, samplingfrequency=None, encoderfolder=None, advancedencoder=None, encoderoutputformat=None, encodervbrcbr=None, encoderquality=None, encoderlossless=0, @@ -773,6 +774,7 @@ class WebInterface(object): headphones.RENAME_FILES = rename_files headphones.CLEANUP_FILES = cleanup_files headphones.ADD_ALBUM_ART = add_album_art + headphones.ALBUM_ART_FORMAT = album_art_format headphones.EMBED_ALBUM_ART = embed_album_art headphones.EMBED_LYRICS = embed_lyrics headphones.DESTINATION_DIR = destination_dir