From 998c73c20f55ad674d6379af291a9445a8d62f43 Mon Sep 17 00:00:00 2001 From: Cuan Date: Mon, 28 Mar 2022 22:19:01 -0400 Subject: [PATCH] Overhauled argument system --- README.md | 25 +++++++++++++------------ bin/flac2pod | 53 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index f3b07f6..fa80396 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,22 @@ # flac2pod -Seamlessly converts your existing FLAC library to be played on an iPod Classic. +Converts your existing FLAC library to be played on an iPod Classic. -This script makes use of ffmpeg to convert your existing FLAC music library to MP3-320 for easy iPod Classic use. It also takes advantage of "rg2sc" (https://github.com/rwinkhart/rg2sc) to convert any existing ReplayGain tags to Apple Sound Check tags that are compatible with Apple products. +This script makes use of ffmpeg to convert your existing FLAC music library to AAC-256 or MP3-320 for easy iPod Classic use. It also takes advantage of "rg2sc" (https://github.com/rwinkhart/rg2sc) to convert any existing ReplayGain tags to Apple Sound Check tags that are compatible with Apple products. # Usage -Simply run: +Simply run... ``` -flac2pod +flac2pod ``` -...and you will be prompted for your source and destination directories. +...to convert your library, or run... +``` +flac2pod --help +``` +...to see additional options. +In order for flac2pod to function, your source_dir must be structured as follows: -In order for flac2pod to function, your library must be structured as follows: - -library parent dir -> artist dir -> album dir -> FLAC files - - -When prompted for the source directory, you want to input your library parent directory. +source_dir -> artist dir -> album dir -> FLAC files # Installation @@ -24,4 +24,5 @@ flac2pod is available in the AUR as "flac2pod". If installing on a non-Arch-base - copy the flac2pod executable from https://github.com/rwinkhart/flac2pod/blob/master/bin/flac2pod to your /usr/bin/ - copy the rg2sc executable from https://github.com/rwinkhart/rg2sc/blob/master/bin/rg2sc to your /usr/bin -- install python-mutagen, ffmpeg, and lame +- install python-mutagen, ffmpeg, lame, and screen +- start converting diff --git a/bin/flac2pod b/bin/flac2pod index 7296203..32d1f68 100755 --- a/bin/flac2pod +++ b/bin/flac2pod @@ -2,11 +2,12 @@ # external modules +from argparse import ArgumentParser from os import cpu_count, path, walk from pathlib import Path -from sys import argv, exit as s_exit -from time import sleep from subprocess import check_output, Popen +from sys import exit as s_exit +from time import sleep # utility functions @@ -44,9 +45,9 @@ def scan_destination_convert(): _progress = round((_i_total / _total_files) * 100, 2) if not Path(f"{_file.replace(path.expanduser(source), path.expanduser(destination))}.mp3").is_file() and not \ Path(f"{_file.replace(path.expanduser(source), path.expanduser(destination))}.m4a").is_file(): - _file_s = _file.replace(' ', '\\ ').replace("'", "\\'").replace(')', '\\)').replace('(', '\\(').replace\ - ('&', '\\&').replace('`', '\\`').replace('$', '\\$') + '.flac' - if '--mp3' in arguments: + _file_s = _file.replace(' ', '\\ ').replace("'", "\\'").replace(')', '\\)').replace('(', '\\(')\ + .replace('&', '\\&').replace('`', '\\`').replace('$', '\\$') + '.flac' + if args.mp3: _file_d = _file.replace(path.expanduser(source), path.expanduser(destination)).replace(' ', '\\ ') \ .replace("'", "\\'").replace(')', '\\)').replace('(', '\\(').replace('&', '\\&') \ .replace('`', '\\`').replace('$', '\\$') + '.mp3' @@ -62,15 +63,15 @@ def scan_destination_convert(): _active_processes = int(check_output('ps -C ffmpeg | wc -l', shell=True)) - 1 _i += 1 print(f"\n{_progress}% | \u001b[38;5;0;48;5;15mConverting {_file_s} to {_file_d}...\u001b[0m\n") - if '--mp3' in arguments: - if '-s' in arguments: + if args.mp3: + if args.strip: _cmd = f"screen -DmS flac2pod{_i} ffmpeg -i {_file_s} -map 0:a -ab 320k -map_metadata 0" \ f" -id3v2_version 3 {_file_d}