mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-16 00:25:31 +01:00
Merge remote-tracking branch 'pabloalcantara/master' into develop
This commit is contained in:
@@ -109,6 +109,12 @@ MEDIA_FORMATS = ["mp3", "flac", "aac", "ogg", "ape", "m4a"]
|
||||
INTERFACE = None
|
||||
FOLDER_PERMISSIONS = None
|
||||
|
||||
ENCODE = None
|
||||
ENCODERFOLDER = None
|
||||
ENCODER = None
|
||||
BITRATE = None
|
||||
SAMPLINGFREQUENCY = None
|
||||
|
||||
def CheckSection(sec):
|
||||
""" Check if INI section exists, if not create it """
|
||||
try:
|
||||
@@ -166,7 +172,8 @@ def initialize():
|
||||
ADD_ALBUM_ART, EMBED_ALBUM_ART, DOWNLOAD_DIR, BLACKHOLE, BLACKHOLE_DIR, USENET_RETENTION, NZB_SEARCH_INTERVAL, \
|
||||
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
|
||||
NZBSORG, NZBSORG_UID, NZBSORG_HASH, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASSWORD, LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, \
|
||||
ENCODERFOLDER, ENCODER, BITRATE, SAMPLINGFREQUENCY, ENCODE
|
||||
|
||||
if __INITIALIZED__:
|
||||
return False
|
||||
@@ -246,7 +253,15 @@ def initialize():
|
||||
|
||||
INTERFACE = check_setting_str(CFG, 'General', 'interface', 'default')
|
||||
FOLDER_PERMISSIONS = check_setting_str(CFG, 'General', 'folder_permissions', '0755')
|
||||
|
||||
|
||||
ENCODERFOLDER = check_setting_str(CFG, 'General', 'encoderfolder', '')
|
||||
ENCODER = check_setting_str(CFG, 'General', 'encoder', 'ffmpeg')
|
||||
BITRATE = check_setting_str(CFG, 'General', 'bitrate', '128')
|
||||
SAMPLINGFREQUENCY= check_setting_str(CFG, 'General', 'samplingfrequency', '44100')
|
||||
ENCODE = check_setting_str(CFG, 'General', 'encode', 'false')
|
||||
|
||||
|
||||
|
||||
if not LOG_DIR:
|
||||
LOG_DIR = os.path.join(DATA_DIR, 'logs')
|
||||
|
||||
@@ -415,7 +430,13 @@ 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']['encode'] = ENCODE
|
||||
new_config['General']['encoder'] = ENCODER
|
||||
new_config['General']['bitrate'] = BITRATE
|
||||
new_config['General']['samplingfrequency'] = SAMPLINGFREQUENCY
|
||||
new_config['General']['encoderfolder'] = ENCODERFOLDER
|
||||
|
||||
new_config.write()
|
||||
|
||||
|
||||
|
||||
56
headphones/encode.py
Normal file
56
headphones/encode.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import os
|
||||
import headphones
|
||||
import argparse
|
||||
import shutil
|
||||
import time
|
||||
|
||||
from subprocess import call
|
||||
|
||||
def encode(albumPath):
|
||||
|
||||
tempDirEncode=os.path.join(albumPath,"temp")
|
||||
musicFiles=[]
|
||||
musicTempFiles=[]
|
||||
encoder =""
|
||||
if not os.path.exists(tempDirEncode):
|
||||
os.mkdir(tempDirEncode)
|
||||
else:
|
||||
shutil.rmtree(tempDirEncode)
|
||||
time.sleep(1)
|
||||
os.mkdir(tempDirEncode)
|
||||
|
||||
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))
|
||||
musicTempFiles.append(os.path.join(tempDirEncode, music))
|
||||
|
||||
if headphones.ENCODER=='lame':
|
||||
encoder=os.path.join(headphones.ENCODERFOLDER,'lame')
|
||||
else:
|
||||
encoder=os.path.join(headphones.ENCODERFOLDER,'ffmpeg')
|
||||
i=0
|
||||
for music in musicFiles:
|
||||
return_code=1
|
||||
if headphones.ENCODER == 'lame':
|
||||
cmd=encoder+' -h --resample ' + headphones.SAMPLINGFREQUENCY + ' -b ' + headphones.BITRATE
|
||||
cmd=cmd+' "'+os.path.join(music)+'"'
|
||||
cmd=cmd+' "'+os.path.join(musicTempFiles[i])+'"'
|
||||
return_code = call(cmd, shell=True)
|
||||
if return_code==0:
|
||||
os.remove(music)
|
||||
os.rename(musicTempFiles[i],music)
|
||||
i=i+1
|
||||
else:
|
||||
cmd=encoder+' -i'
|
||||
cmd=cmd+' "'+os.path.join(music)+'"'
|
||||
cmd=cmd+' -ac 2 -vn -ar ' + headphones.SAMPLINGFREQUENCY + ' -ab ' + headphones.BITRATE +'k'
|
||||
cmd=cmd+' "'+os.path.join(musicTempFiles[i])+'"'
|
||||
return_code = call(cmd, shell=True)
|
||||
print return_code
|
||||
if return_code==0:
|
||||
os.remove(music)
|
||||
os.rename(musicTempFiles[i],music)
|
||||
i=i+1
|
||||
|
||||
shutil.rmtree(tempDirEncode)
|
||||
@@ -1,8 +1,7 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
import encode
|
||||
import urllib, shutil, re
|
||||
|
||||
import lib.beets as beets
|
||||
from lib.beets import autotag
|
||||
from lib.beets.mediafile import MediaFile
|
||||
@@ -198,7 +197,10 @@ def verify(albumid, albumpath):
|
||||
def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list):
|
||||
|
||||
logger.info('Starting post-processing for: %s - %s' % (release['ArtistName'], release['AlbumTitle']))
|
||||
|
||||
#start enconding
|
||||
if headphones.ENCODE=='1':
|
||||
encode.encode(albumpath)
|
||||
|
||||
if headphones.EMBED_ALBUM_ART or headphones.ADD_ALBUM_ART:
|
||||
|
||||
album_art_path = albumart.getAlbumArt(albumid)
|
||||
|
||||
Reference in New Issue
Block a user