reuse existing voiceover files

and remove any that are not referenced while updating the database
This commit is contained in:
Arno Hautala 2022-01-11 22:12:33 -05:00
parent 42f1d55b1c
commit 3b32ef9ba9

View file

@ -204,7 +204,6 @@ class Text2Speech(object):
os.remove(tmp_file.name)
return True
class Record(object):
def __init__(self, parent):
@ -233,9 +232,24 @@ class Record(object):
def text_to_speech(self, text, dbid, playlist = False):
if self.track_voiceover and not playlist or self.playlist_voiceover and playlist:
p = self.parent
speakable = dict()
# find the speakable dict somewhere in the parent path
while True:
if hasattr(p, 'speakable'):
speakable = p.speakable
break
elif hasattr(p, 'parent'):
p = p.parent
else:
break
# Create the voiceover wav file
fn = ''.join(format(x, '02x') for x in reversed(dbid))
path = os.path.join(self.base, "iPod_Control", "Speakable", "Tracks" if not playlist else "Playlists", fn + ".wav")
if path in speakable:
speakable[path] = True
return True
speakable[path] = True
return Text2Speech.text2speech(path, text)
return False
@ -607,11 +621,14 @@ class Shuffler(object):
self.trackgain = trackgain
self.auto_dir_playlists = auto_dir_playlists
self.auto_id3_playlists = auto_id3_playlists
self.speakable = dict()
def initialize(self):
# remove existing voiceover files (they are either useless or will be overwritten anyway)
# make note of existing voiceover files (they can be removed if they're not referenced while writing the database)
for dirname in ('iPod_Control/Speakable/Playlists', 'iPod_Control/Speakable/Tracks'):
shutil.rmtree(os.path.join(self.path, dirname), ignore_errors=True)
for root, dirs, files in os.walk(os.path.join(self.path, dirname)):
for file in files:
self.speakable[os.path.join(root,file)] = False
for dirname in ('iPod_Control/iTunes', 'iPod_Control/Music', 'iPod_Control/Speakable/Playlists', 'iPod_Control/Speakable/Tracks'):
make_dir_if_absent(os.path.join(self.path, dirname))
@ -664,6 +681,11 @@ class Shuffler(object):
print("Error: Writing iPod database failed.")
sys.exit(1)
for path,seen in self.speakable.items():
if not seen:
#print ('delete: {}'.format(path))
os.remove(path)
print("Database written successfully:")
print("Tracks", len(self.tracks))
print("Albums", len(self.albums))