add more options to replaygain on process

This commit is contained in:
ChaotiCryptidz 2022-02-10 12:44:15 +00:00
parent 6c6a3151ca
commit 07d4daf40d
7 changed files with 32 additions and 16 deletions

1
.direnv/flake-profile Symbolic link
View file

@ -0,0 +1 @@
flake-profile-1-link

View file

@ -0,0 +1 @@
/nix/store/636l6zba529dbpcnyr0vmnq5kynfcqpr-nix-shell-env

2
.envrc
View file

@ -1 +1 @@
use nix
use flake

View file

@ -33,6 +33,7 @@
'';
doCheck = false;
buildInputs = with final; [ r128gain ffmpeg ];
propagatedBuildInputs = with final.python3Packages; [
mutagen
@ -59,10 +60,10 @@
devShell = pkgs.mkShell {
inputsFrom = [ self.packages.${system}.musicutil ];
buildInputs = with pkgs; [
nixUnstable
buildInputs = with pkgs; [ nixUnstable ffmpeg r128gain ];
propagatedBuildInputs = with pkgs.python3Packages; [
mutagen
self.packages.${system}.fold-to-ascii
pkgs.fold-to-ascii
pyyaml
];
};

View file

@ -15,8 +15,7 @@ class ProcessCommandState:
class ProcessCommandArgs:
src: str
dry_run: bool
skip_replaygain: bool
replaygain: str
def add_process_command(subparsers):
process_parser = subparsers.add_parser('process')
@ -27,15 +26,18 @@ def add_process_command(subparsers):
process_parser.add_argument(
'--dry-run', action='store_true')
process_parser.add_argument(
'--skip-replaygain',
action='store_true')
'--replaygain',
type=str,
default="skip_existing",
help="skip,skip_existing,force"
)
def get_process_args(args) -> ProcessCommandArgs:
command_args = ProcessCommandArgs()
command_args.src = args.src
command_args.dry_run = args.dry_run
command_args.skip_replaygain = args.skip_replaygain
command_args.replaygain = args.replaygain
return command_args
@ -49,9 +51,9 @@ class ProcessCommand():
self.scan_for_music()
self.load_tag_information()
self.rename_files()
if (not self.args.skip_replaygain) and (
not self.args.dry_run):
self.add_replaygain_tags()
if not self.args.dry_run:
if self.args.replaygain != "skip":
self.add_replaygain_tags()
def scan_for_music(self):
print("Scanning For Music")
@ -101,6 +103,9 @@ class ProcessCommand():
print("Adding ReplayGain Tags")
for file in self.state.files:
if self.args.replaygain == "skip_existing":
if file.tags.has_replaygain:
continue
print(
f"Adding ReplayGain Tags to \"{file.filename}.{file.extension}\"")

View file

@ -1,11 +1,13 @@
class Tags:
title = ""
artist = ""
has_replaygain = False
def to_dict(self):
return {
"title": self.title,
"artist": self.artist
"artist": self.artist,
"has_replaygain": self.has_replaygain
}
def __repr__(self):

View file

@ -4,7 +4,7 @@ from ..meta import ffprobe_path
from subprocess import run as run_command
from json import loads as load_json_string
from mutagen.mp3 import EasyMP3 as MP3
from mutagen.mp3 import MP3, EasyMP3
from mutagen.flac import FLAC
@ -12,11 +12,16 @@ def load_tag_information_mutagen(file: File) -> Tags:
path = file.join_path_to()
tags = Tags()
if file.extension == "mp3":
easymp3 = EasyMP3(path)
mp3 = MP3(path)
tags.title = mp3["title"][0]
tags.artist = mp3["artist"][0]
tags.title = easymp3["title"][0]
tags.artist = easymp3["artist"][0]
if "REPLAYGAIN_TRACK_GAIN" in mp3.keys() or "TXXX:REPLAYGAIN_TRACK_PEAK" in mp3.keys():
tags.has_replaygain = True
elif file.extension == "flac":
flac = FLAC(path)
if "replaygain_track_peak" in flac.keys():
tags.has_replaygain = True
tags.title = flac["title"][0]
tags.artist = flac["artist"][0]
else:
@ -46,6 +51,7 @@ def load_tag_information_ffmpeg(file: File) -> Tags:
artist = None
try:
print(file_tags.keys())
if "title" in file_tags.keys():
title = file_tags["title"]
elif "TITLE" in file_tags.keys():