from hashlib import sha256 as _hash
import os
import os.path
+import re as _re
import shutil
from subprocess import Popen, PIPE
from tempfile import mkstemp
.. _suggestions: http://www.xiph.org/vorbis/doc/v-comment.html
"""
def __init__(self, source_dir, target_dir, target_extension='ogg',
- cache_file=None):
+ cache_file=None, ignore_function=None):
self.source_dir = source_dir
self.target_dir = target_dir
self._source_extensions = ['flac', 'mp3', 'ogg', 'wav']
self._target_extension = target_extension
self._cache_file = cache_file
self._cache = self._read_cache()
+ self._ignore_function = ignore_function
f,self._tempfile = mkstemp(prefix='mkogg-')
def cleanup(self):
print 'skip', filename, ext
continue
source_path = os.path.join(dirpath, filename)
+ if (self._ignore_function is not None and
+ self._ignore_function(source_path)):
+ continue
rel_path = os.path.relpath(dirpath, self.source_dir)
target_path = os.path.join(
self.target_dir, rel_path,
p.add_option('-c', '--cache', dest='cache', metavar='PATH',
help=('Save conversion hashes in a cache file to avoid '
'repeated previous conversions.'))
+ p.add_option('-i', '--ignore', dest='ignore', metavar='REGEXP',
+ help=('Ignore source paths matching REGEXP.'))
p.add_option('--test', dest='test', action='store_true', default=False,
help='Run internal tests and exit')
if options.test:
sys.exit(test())
+ if options.ignore is not None:
+ ignore_regexp = _re.compile(options.ignore)
+ ignore_function = ignore_regexp.match
+ else:
+ ignore_function = None
+
source_dir,target_dir = args
c = Converter(source_dir, target_dir, target_extension=options.ext,
- cache_file=options.cache)
+ cache_file=options.cache, ignore_function=ignore_function)
try:
c.run()
finally: