1 Commits
Author SHA1 Message Date
RandyTheSilly 6732731c11 Fixed non-FLAC file copy function 2022-05-19 02:11:36 -04:00
+11 -9
View File
@@ -3,7 +3,7 @@
# external modules # external modules
from argparse import ArgumentParser from argparse import ArgumentParser
from mutagen.flac import FLAC, FLACNoHeaderError from mutagen.flac import FLAC
from os import cpu_count, path, walk from os import cpu_count, path, walk
from pathlib import Path from pathlib import Path
from shutil import copy from shutil import copy
@@ -29,7 +29,8 @@ def scan_source(_source):
for _album in sorted(_album_dirs): for _album in sorted(_album_dirs):
for _root, _directories, _files in walk(path.expanduser(_album)): for _root, _directories, _files in walk(path.expanduser(_album)):
for _filename in _files: for _filename in _files:
if _filename.endswith('.flac'): if _filename.endswith('.flac') or _filename.endswith('.mp3') or _filename.endswith('.mp4') \
or _filename.endswith('.m4a'):
_full_paths.append(f"{_album}/{_filename}") _full_paths.append(f"{_album}/{_filename}")
return _album_dirs, _full_paths return _album_dirs, _full_paths
@@ -45,13 +46,19 @@ def scan_destination_convert():
for _file in source_directories[1]: for _file in source_directories[1]:
_i_total += 1 _i_total += 1
_progress = round((_i_total / _total_files) * 100, 2) _progress = round((_i_total / _total_files) * 100, 2)
if not Path(f"{(_file.replace(path.expanduser(source), path.expanduser(destination)))[:-5]}.m4a").is_file(): if not Path(f"{(_file.replace(path.expanduser(source), path.expanduser(destination)))[:-5]}.m4a").is_file()\
and not Path(f"{(_file.replace(path.expanduser(source), path.expanduser(destination)))}").is_file():
if not _file.endswith('.flac'):
print(f"[{_file}] Not a FLAC file, copying...")
copy(f"{_file}", f"{_file.replace(path.expanduser(source), path.expanduser(destination))}")
else:
_file_s = _file.replace(' ', '\\ ').replace("'", "\\'").replace(')', '\\)').replace('(', '\\(') \ _file_s = _file.replace(' ', '\\ ').replace("'", "\\'").replace(')', '\\)').replace('(', '\\(') \
.replace(']', '\\]').replace('[', '\\[').replace('&', '\\&').replace('`', '\\`') \ .replace(']', '\\]').replace('[', '\\[').replace('&', '\\&').replace('`', '\\`') \
.replace('$', '\\$') .replace('$', '\\$')
_file_d = _file.replace(path.expanduser(source), path.expanduser(destination)).replace(' ', '\\ ') \ _file_d = _file.replace(path.expanduser(source), path.expanduser(destination)).replace(' ', '\\ ') \
.replace("'", "\\'").replace(')', '\\)').replace('(', '\\(').replace(']', '\\]') \ .replace("'", "\\'").replace(')', '\\)').replace('(', '\\(').replace(']', '\\]') \
.replace('[', '\\[').replace('&', '\\&').replace('`', '\\`').replace('$', '\\$')[:-5] + '.m4a' .replace('[', '\\[').replace('&', '\\&').replace('`', '\\`').replace('$', '\\$')[
:-5] + '.m4a'
_active_processes = int(check_output('ps -C ffmpeg | wc -l', shell=True)) - 1 _active_processes = int(check_output('ps -C ffmpeg | wc -l', shell=True)) - 1
if _active_processes >= cpu_count(): if _active_processes >= cpu_count():
while _active_processes >= cpu_count(): while _active_processes >= cpu_count():
@@ -61,7 +68,6 @@ def scan_destination_convert():
_i += 1 _i += 1
print(f"\n{_progress}% | \u001b[38;5;0;48;5;15mConverting {_file_s} to {_file_d}...\u001b[0m\n") print(f"\n{_progress}% | \u001b[38;5;0;48;5;15mConverting {_file_s} to {_file_d}...\u001b[0m\n")
# get relevant ReplayGain info # get relevant ReplayGain info
try:
_audio = FLAC(f"{_file}") _audio = FLAC(f"{_file}")
if args.albumgain: if args.albumgain:
if _audio.get('REPLAYGAIN_ALBUM_GAIN'): if _audio.get('REPLAYGAIN_ALBUM_GAIN'):
@@ -89,10 +95,6 @@ def scan_destination_convert():
_rgpeak = float(_audio.get('replaygain_track_peak')[0]) _rgpeak = float(_audio.get('replaygain_track_peak')[0])
else: else:
_rgpeak = None _rgpeak = None
except FLACNoHeaderError:
print(f"[{_file}] Not a FLAC file, copying...")
copy(f"{_file}", f"{_file.replace(path.expanduser(source), path.expanduser(destination))}")
_rggain, _rgpeak = None, None
# determine ffmpeg arguments # determine ffmpeg arguments
if args.bake and _rggain is not None: if args.bake and _rggain is not None:
_bake_args, _flac2pod_rg_tags = '-filter:a "volume=' + str(_rggain) + 'dB"', '' _bake_args, _flac2pod_rg_tags = '-filter:a "volume=' + str(_rggain) + 'dB"', ''