mirror of
https://github.com/rwinkhart/flac2pod.git
synced 2026-09-03 15:47:20 -04:00
Prevent crashes when a non-FLAC file is found
This commit is contained in:
+14
-7
@@ -1,6 +1,9 @@
|
|||||||
#!/bin/python3
|
#!/bin/python3
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
import mutagen.flac
|
||||||
|
|
||||||
from flac2pod import scan_source
|
from flac2pod import scan_source
|
||||||
from mutagen.flac import FLAC
|
from mutagen.flac import FLAC
|
||||||
from os import listdir, system
|
from os import listdir, system
|
||||||
@@ -29,13 +32,17 @@ if __name__ == "__main__":
|
|||||||
std_album = album.replace(' ', '\\ ').replace("'", "\\'").replace(')', '\\)') \
|
std_album = album.replace(' ', '\\ ').replace("'", "\\'").replace(')', '\\)') \
|
||||||
.replace('(', '\\(').replace('&', '\\&').replace('`', '\\`').replace('$', '\\$')
|
.replace('(', '\\(').replace('&', '\\&').replace('`', '\\`').replace('$', '\\$')
|
||||||
for song in listdir(album):
|
for song in listdir(album):
|
||||||
audio = FLAC(f"{album}/{song}")
|
try:
|
||||||
if audio.get('replaygain_track_gain') or audio.get('REPLAYGAIN_TRACK_GAIN'):
|
audio = FLAC(f"{album}/{song}")
|
||||||
gain = 1
|
if audio.get('replaygain_track_gain') or audio.get('REPLAYGAIN_TRACK_GAIN'):
|
||||||
else:
|
gain = 1
|
||||||
gain = 0
|
else:
|
||||||
break
|
gain = 0
|
||||||
if args.force or gain == 0:
|
break
|
||||||
|
except mutagen.flac.FLACNoHeaderError:
|
||||||
|
print(f"[{album}/*] Contains non-FLAC files, skipping album...")
|
||||||
|
gain = 2
|
||||||
|
if gain != 2 and (args.force or gain == 0):
|
||||||
print(f"[{album}/*] Adding ReplayGain data...")
|
print(f"[{album}/*] Adding ReplayGain data...")
|
||||||
system(f"metaflac --remove-replay-gain {std_album}/*")
|
system(f"metaflac --remove-replay-gain {std_album}/*")
|
||||||
command = f"metaflac --add-replay-gain {std_album}/*"
|
command = f"metaflac --add-replay-gain {std_album}/*"
|
||||||
|
|||||||
Reference in New Issue
Block a user