Is there any difference between the solution posted by "chromium" (find ... -execdir mp3gain {}..) and "jth" (perl skript to avoid clipping)? Dont know if i understood what you are doing, just wanted to add gain-tags to my collection and started writing a python-Script calling the perl-Script of "jth" for every mp3-containing-folder in a specified location:
# -*- coding: utf-8 -*-
#/usr/bin/python
import sys
import os
import subprocess
def dirEntries(dir_name, subdir, *args):
fileList = []
for file in os.listdir(dir_name):
dirfile = os.path.join(dir_name, file)
if os.path.isfile(dirfile):
if not args:
fileList.append(dirfile)
else:
if os.path.splitext(dirfile)[1][1:] in args:
fileList.append(dirfile)
# recursively access file names in subdirectories
elif os.path.isdir(dirfile) and subdir:
fileList.extend(dirEntries(dirfile, subdir, *args))
return fileList
def dirNamesWithFiles(dir_name, subdir, *args):
folderList = []
for file in os.listdir(dir_name):
dirfile = os.path.join(dir_name, file)
if os.path.isfile(dirfile):
if not args:
folderList.append(os.path.dirname(dirfile))
else:
if os.path.splitext(dirfile)[1][1:] in args:
folderList.append(os.path.dirname(dirfile))
# recursively access file names in subdirectories
elif os.path.isdir(dirfile) and subdir:
folderList.extend(dirNamesWithFiles(dirfile, subdir, *args))
return folderList
perlPath='/home/n/applyMp3Gain.pl'
mp3Path='/home/n/Mp3-Files'
folders = set(dirNamesWithFiles(mp3Path, 1, 'mp3'))
for i in folders:
subprocess.call(["/usr/bin/perl", perlPath] + dirEntries(i, 0, 'mp3'))
You need to adjust "perlPath" and "mp3Path", perlPath should point to the script posted above by "jth". This script will call the perl-Script once for every subfolder where it finds mp3-files (case sensitive on extension..).
Perhaps some googlers need the script. best regards.
nils