Separate interpreted and compiled for easier installation
This commit is contained in:
74
interpreted/ds
Executable file
74
interpreted/ds
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# ds - calculate and display the size of a given directory in a human readable format
|
||||
# Copyright Frederick Boniface 2023 - fredboniface.co.uk
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use File::Find;
|
||||
|
||||
if (@ARGV == 0) {
|
||||
print <<EOF;
|
||||
\nUsage: $0 <directory_path>
|
||||
|
||||
Calculate the size of a directory and its contents.\n
|
||||
EOF
|
||||
exit;
|
||||
}
|
||||
|
||||
my $dir_path = $ARGV[0];
|
||||
|
||||
unless (-d $dir_path) {
|
||||
die "$dir_path is not a directory\n"
|
||||
}
|
||||
|
||||
if ($dir_path eq '/') {
|
||||
die "You are not able to run 'ds' on the root directory\n"
|
||||
}
|
||||
|
||||
my $total_size = 0;
|
||||
|
||||
sub calculate_size {
|
||||
my $file = $File::Find::name;
|
||||
|
||||
return if -l $file;
|
||||
|
||||
if (-f $file) {
|
||||
$total_size += -s $file;
|
||||
}
|
||||
}
|
||||
|
||||
find(\&calculate_size, $dir_path);
|
||||
|
||||
sub format_size {
|
||||
my $size = shift;
|
||||
my @units = qw(B KB MB GB TB);
|
||||
my $unit_index = 0;
|
||||
|
||||
while ($size >= 1024 && $unit_index < @units -1) {
|
||||
$size /= 1024;
|
||||
$unit_index++;
|
||||
}
|
||||
|
||||
return sprintf("%.2f %s", $size, $units[$unit_index]);
|
||||
}
|
||||
|
||||
print "Total size of $dir_path:\n", format_size($total_size), "\n"
|
||||
111
interpreted/regain
Executable file
111
interpreted/regain
Executable file
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# regain - search folders below working directory and call regainer on each album found
|
||||
# Copyright Frederick Boniface 2023 - fredboniface.co.uk
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import logging
|
||||
import argparse
|
||||
|
||||
VERSION = "0.0.1"
|
||||
# Updated 2023/10/02
|
||||
|
||||
FORMATS = ["flac", "m4a", "aac", "alac", "mp3", "m3a", "ogg", "opus", "oga"]
|
||||
PATH_TO_REGAINER = "./regainer.py"
|
||||
DESCRIPTION = """
|
||||
regain - Calls regainer.py on any albums found in subdirectories.
|
||||
\n\n
|
||||
Run the regain command in a directory that contains albums and ReplayGain tags will be
|
||||
added to the files, including album tags.
|
||||
\n\n
|
||||
regain will walk through all subdirectories so can be run in your 'Music' folder, or
|
||||
individual artist/album folders and tag as many albums as neccessary.
|
||||
"""
|
||||
|
||||
def parse_arguments():
|
||||
parser = argparse.ArgumentParser(description=DESCRIPTION)
|
||||
parser.add_argument('--debug', action='store_true', help='Enable debug logging (including regainer output)')
|
||||
return parser.parse_args()
|
||||
|
||||
def configureLogging(debug_mode = False):
|
||||
log_level = logging.DEBUG if debug_mode else logging.INFO
|
||||
logging.basicConfig(level=log_level, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
def getWorkingDirectory():
|
||||
return os.getcwd()
|
||||
|
||||
def find_files_by_extension(workdir):
|
||||
file_lists = []
|
||||
|
||||
for root, _, files in os.walk(workdir):
|
||||
matching_files = [os.path.join(root, file) for file in files if file.endswith(tuple(FORMATS))]
|
||||
if matching_files:
|
||||
file_lists.append(matching_files)
|
||||
return file_lists
|
||||
|
||||
def countFiles(file_list_of_lists):
|
||||
count = 0
|
||||
for item in file_list_of_lists:
|
||||
count = count + len(item)
|
||||
return count
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = parse_arguments()
|
||||
configureLogging(args.debug)
|
||||
workdir = getWorkingDirectory()
|
||||
print(f"regain version {VERSION}")
|
||||
logging.info(f"WorkDir: {workdir}")
|
||||
logging.debug("Debug logs enabled")
|
||||
file_lists = find_files_by_extension(workdir)
|
||||
logging.debug(f"File lists: {file_lists}")
|
||||
file_count = countFiles(file_lists)
|
||||
if file_count == 0:
|
||||
logging.error("No files to process")
|
||||
print("You should run this command from the parent directory of any album folders")
|
||||
sys.exit(1)
|
||||
logging.info(f"Files for processing: {file_count}")
|
||||
|
||||
cmd = ["python", PATH_TO_REGAINER, "-f"]
|
||||
for sublist in file_lists:
|
||||
cmd.append("-a")
|
||||
for item in sublist:
|
||||
cmd.append(item)
|
||||
|
||||
logging.debug(f"Running command: {cmd}")
|
||||
logging.info("Running regainer.py")
|
||||
|
||||
if args.debug:
|
||||
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
output = result.stdout
|
||||
error = result.stderr
|
||||
# Handle the captured output as needed
|
||||
print("Output:", output)
|
||||
print("Error:", error)
|
||||
else:
|
||||
result = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
logging.debug(f"regainer.py has exited with code {result.returncode}")
|
||||
if result.returncode != 0:
|
||||
print("You can re-run with --debug to view the output from regainer")
|
||||
else:
|
||||
print("Files successfully tagged")
|
||||
1113
interpreted/regainer.py
Normal file
1113
interpreted/regainer.py
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user