diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 9742cf3e..cddd77e4 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -263,6 +263,8 @@

Re-encode downloads during postprocessing

Note: this option requires the lame or ffmpeg encoder +
+

Re-encode only LossLess format (.flac)



<% if config['encoder'] == 'lame': diff --git a/data/interfaces/remix/config.html b/data/interfaces/remix/config.html index 9742cf3e..8674f6ab 100644 --- a/data/interfaces/remix/config.html +++ b/data/interfaces/remix/config.html @@ -263,6 +263,8 @@

Re-encode downloads during postprocessing

Note: this option requires the lame or ffmpeg encoder +
+

Re-encode only LossLess format (.flac)



<% if config['encoder'] == 'lame': diff --git a/headphones/__init__.py b/headphones/__init__.py index f888ec26..eeec7ed3 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -122,6 +122,7 @@ ADVANCEDENCODER = None ENCODEROUTPUTFORMAT = None ENCODERQUALITY = None ENCODERVBRCBR = None +ENCODERLOSSLESS = True def CheckSection(sec): """ Check if INI section exists, if not create it """ @@ -181,7 +182,8 @@ def initialize(): LIBRARYSCAN_INTERVAL, DOWNLOAD_SCAN_INTERVAL, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \ NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, \ NZBSORG, NZBSORG_UID, NZBSORG_HASH, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASSWORD, LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, \ - ENCODERFOLDER, ENCODER, BITRATE, SAMPLINGFREQUENCY, ENCODE, ADVANCEDENCODER, ENCODEROUTPUTFORMAT, ENCODERQUALITY, ENCODERVBRVBR + ENCODERFOLDER, ENCODER, BITRATE, SAMPLINGFREQUENCY, ENCODE, ADVANCEDENCODER, ENCODEROUTPUTFORMAT, ENCODERQUALITY, ENCODERVBRVBR, \ + ENCODERLOSSLESS if __INITIALIZED__: return False @@ -272,6 +274,7 @@ def initialize(): ENCODEROUTPUTFORMAT = check_setting_str(CFG, 'General', 'encoderoutputformat', 'mp3') ENCODERQUALITY = check_setting_int(CFG, 'General', 'vorbisquality', 5) ENCODERVBRCBR = check_setting_str(CFG, 'General', 'encodervbrcbr', 'cbr') + ENCODERLOSSLESS = bool(check_setting_int(CFG, 'General', 'encoderlossless', 1)) if not LOG_DIR: LOG_DIR = os.path.join(DATA_DIR, 'logs') @@ -459,6 +462,7 @@ def config_write(): new_config['General']['encoderoutputformat'] = ENCODEROUTPUTFORMAT new_config['General']['encoderquality'] = ENCODERQUALITY new_config['General']['encodervbrcbr'] = ENCODERVBRCBR + new_config['General']['encoderlossless'] = ENCODERLOSSLESS new_config.write() diff --git a/headphones/encode.py b/headphones/encode.py index d8cd032f..fa530ac3 100644 --- a/headphones/encode.py +++ b/headphones/encode.py @@ -31,10 +31,18 @@ def encode(albumPath): for r,d,f in os.walk(albumPath): for music in f: if any(music.endswith('.' + x) for x in headphones.MEDIA_FORMATS): - musicFiles.append(os.path.join(r, music)) - musicTemp = os.path.normpath(os.path.splitext(music)[0]+'.'+headphones.ENCODEROUTPUTFORMAT).encode(headphones.SYS_ENCODING) - musicTempFiles.append(os.path.join(tempDirEncode, musicTemp)) - + if (headphones.ENCODERLOSSLESS): + if (music.endswith('.flac')): + musicFiles.append(os.path.join(r, music)) + musicTemp = os.path.normpath(os.path.splitext(music)[0]+'.'+headphones.ENCODEROUTPUTFORMAT).encode(headphones.SYS_ENCODING) + musicTempFiles.append(os.path.join(tempDirEncode, musicTemp)) + else: + logger.warn('Music "%s" is already encoded' % (music)) + else: + musicFiles.append(os.path.join(r, music)) + musicTemp = os.path.normpath(os.path.splitext(music)[0]+'.'+headphones.ENCODEROUTPUTFORMAT).encode(headphones.SYS_ENCODING) + musicTempFiles.append(os.path.join(tempDirEncode, musicTemp)) + if headphones.ENCODER=='lame': encoder=os.path.join(headphones.ENCODERFOLDER,'lame') elif headphones.ENCODER=='ffmpeg': @@ -42,7 +50,6 @@ def encode(albumPath): i=0 for music in musicFiles: infoMusic=MediaFile(music) - if headphones.ENCODER == 'lame': if not any(music.endswith('.' +headphones.ENCODEROUTPUTFORMAT) for x in ["mp3", "wav"]): logger.warn('Lame cant encode "%s" format for "%s", use ffmpeg' % (os.path.splitext(music)[1],music)) @@ -65,8 +72,8 @@ def encode(albumPath): else: command(encoder,music,musicTempFiles[i],albumPath) ifencoded=1 - i=i+1 - + i=i+1 + shutil.rmtree(tempDirEncode) time.sleep(1) for r,d,f in os.walk(albumPath): @@ -76,8 +83,6 @@ def encode(albumPath): if ifencoded==0: logger.info('Encoding for folder "%s" is not needed' % (albumPath)) - else: - logger.info('Encoding for folder "%s" is completed in %s' % (albumPath,getTimeEncode(startAlbumTime))) return musicFinalFiles diff --git a/headphones/webserve.py b/headphones/webserve.py index 9466cb99..7ec86da6 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -359,7 +359,8 @@ class WebInterface(object): "encoderoutputformat": headphones.ENCODEROUTPUTFORMAT, "samplingfrequency": int(headphones.SAMPLINGFREQUENCY), "encodervbrcbr": (headphones.ENCODERVBRCBR), - "encoderquality": int(headphones.ENCODERQUALITY) + "encoderquality": int(headphones.ENCODERQUALITY), + "encoderlossless": checked(headphones.ENCODERLOSSLESS) } return serve_template(templatename="config.html", title="Settings", config=config) config.exposed = True @@ -370,7 +371,7 @@ class WebInterface(object): usenet_retention=None, nzbmatrix=0, nzbmatrix_username=None, nzbmatrix_apikey=None, newznab=0, newznab_host=None, newznab_apikey=None, nzbsorg=0, nzbsorg_uid=None, nzbsorg_hash=None, newzbin=0, newzbin_uid=None, newzbin_password=None, preferred_quality=0, preferred_bitrate=None, detect_bitrate=0, move_files=0, rename_files=0, correct_metadata=0, cleanup_files=0, add_album_art=0, embed_album_art=0, embed_lyrics=0, destination_dir=None, folder_format=None, file_format=None, include_extras=0, interface=None, log_dir=None, - encode=0, encoder=None, bitrate=None, samplingfrequency=None, encoderfolder=None, advancedencoder=None, encoderoutputformat=None, encodervbrcbr=None, encoderquality=None): + encode=0, encoder=None, bitrate=None, samplingfrequency=None, encoderfolder=None, advancedencoder=None, encoderoutputformat=None, encodervbrcbr=None, encoderquality=None, encoderlossless=0): headphones.HTTP_HOST = http_host headphones.HTTP_PORT = http_port @@ -423,6 +424,7 @@ class WebInterface(object): headphones.ENCODEROUTPUTFORMAT = encoderoutputformat headphones.ENCODERVBRCBR = encodervbrcbr headphones.ENCODERQUALITY = int(encoderquality) + headphones.ENCODERLOSSLESS = encoderlossless headphones.config_write()