add more options to replaygain on process
This commit is contained in:
parent
6c6a3151ca
commit
07d4daf40d
1
.direnv/flake-profile
Symbolic link
1
.direnv/flake-profile
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
flake-profile-1-link
|
1
.direnv/flake-profile-1-link
Symbolic link
1
.direnv/flake-profile-1-link
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
/nix/store/636l6zba529dbpcnyr0vmnq5kynfcqpr-nix-shell-env
|
|
@ -33,6 +33,7 @@
|
||||||
'';
|
'';
|
||||||
|
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
|
buildInputs = with final; [ r128gain ffmpeg ];
|
||||||
|
|
||||||
propagatedBuildInputs = with final.python3Packages; [
|
propagatedBuildInputs = with final.python3Packages; [
|
||||||
mutagen
|
mutagen
|
||||||
|
@ -59,10 +60,10 @@
|
||||||
|
|
||||||
devShell = pkgs.mkShell {
|
devShell = pkgs.mkShell {
|
||||||
inputsFrom = [ self.packages.${system}.musicutil ];
|
inputsFrom = [ self.packages.${system}.musicutil ];
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [ nixUnstable ffmpeg r128gain ];
|
||||||
nixUnstable
|
propagatedBuildInputs = with pkgs.python3Packages; [
|
||||||
mutagen
|
mutagen
|
||||||
self.packages.${system}.fold-to-ascii
|
pkgs.fold-to-ascii
|
||||||
pyyaml
|
pyyaml
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,8 +15,7 @@ class ProcessCommandState:
|
||||||
class ProcessCommandArgs:
|
class ProcessCommandArgs:
|
||||||
src: str
|
src: str
|
||||||
dry_run: bool
|
dry_run: bool
|
||||||
skip_replaygain: bool
|
replaygain: str
|
||||||
|
|
||||||
|
|
||||||
def add_process_command(subparsers):
|
def add_process_command(subparsers):
|
||||||
process_parser = subparsers.add_parser('process')
|
process_parser = subparsers.add_parser('process')
|
||||||
|
@ -27,15 +26,18 @@ def add_process_command(subparsers):
|
||||||
process_parser.add_argument(
|
process_parser.add_argument(
|
||||||
'--dry-run', action='store_true')
|
'--dry-run', action='store_true')
|
||||||
process_parser.add_argument(
|
process_parser.add_argument(
|
||||||
'--skip-replaygain',
|
'--replaygain',
|
||||||
action='store_true')
|
type=str,
|
||||||
|
default="skip_existing",
|
||||||
|
help="skip,skip_existing,force"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_process_args(args) -> ProcessCommandArgs:
|
def get_process_args(args) -> ProcessCommandArgs:
|
||||||
command_args = ProcessCommandArgs()
|
command_args = ProcessCommandArgs()
|
||||||
command_args.src = args.src
|
command_args.src = args.src
|
||||||
command_args.dry_run = args.dry_run
|
command_args.dry_run = args.dry_run
|
||||||
command_args.skip_replaygain = args.skip_replaygain
|
command_args.replaygain = args.replaygain
|
||||||
return command_args
|
return command_args
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,9 +51,9 @@ class ProcessCommand():
|
||||||
self.scan_for_music()
|
self.scan_for_music()
|
||||||
self.load_tag_information()
|
self.load_tag_information()
|
||||||
self.rename_files()
|
self.rename_files()
|
||||||
if (not self.args.skip_replaygain) and (
|
if not self.args.dry_run:
|
||||||
not self.args.dry_run):
|
if self.args.replaygain != "skip":
|
||||||
self.add_replaygain_tags()
|
self.add_replaygain_tags()
|
||||||
|
|
||||||
def scan_for_music(self):
|
def scan_for_music(self):
|
||||||
print("Scanning For Music")
|
print("Scanning For Music")
|
||||||
|
@ -101,6 +103,9 @@ class ProcessCommand():
|
||||||
print("Adding ReplayGain Tags")
|
print("Adding ReplayGain Tags")
|
||||||
|
|
||||||
for file in self.state.files:
|
for file in self.state.files:
|
||||||
|
if self.args.replaygain == "skip_existing":
|
||||||
|
if file.tags.has_replaygain:
|
||||||
|
continue
|
||||||
print(
|
print(
|
||||||
f"Adding ReplayGain Tags to \"{file.filename}.{file.extension}\"")
|
f"Adding ReplayGain Tags to \"{file.filename}.{file.extension}\"")
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
class Tags:
|
class Tags:
|
||||||
title = ""
|
title = ""
|
||||||
artist = ""
|
artist = ""
|
||||||
|
has_replaygain = False
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return {
|
return {
|
||||||
"title": self.title,
|
"title": self.title,
|
||||||
"artist": self.artist
|
"artist": self.artist,
|
||||||
|
"has_replaygain": self.has_replaygain
|
||||||
}
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
|
@ -4,7 +4,7 @@ from ..meta import ffprobe_path
|
||||||
from subprocess import run as run_command
|
from subprocess import run as run_command
|
||||||
from json import loads as load_json_string
|
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
|
from mutagen.flac import FLAC
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,11 +12,16 @@ def load_tag_information_mutagen(file: File) -> Tags:
|
||||||
path = file.join_path_to()
|
path = file.join_path_to()
|
||||||
tags = Tags()
|
tags = Tags()
|
||||||
if file.extension == "mp3":
|
if file.extension == "mp3":
|
||||||
|
easymp3 = EasyMP3(path)
|
||||||
mp3 = MP3(path)
|
mp3 = MP3(path)
|
||||||
tags.title = mp3["title"][0]
|
tags.title = easymp3["title"][0]
|
||||||
tags.artist = mp3["artist"][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":
|
elif file.extension == "flac":
|
||||||
flac = FLAC(path)
|
flac = FLAC(path)
|
||||||
|
if "replaygain_track_peak" in flac.keys():
|
||||||
|
tags.has_replaygain = True
|
||||||
tags.title = flac["title"][0]
|
tags.title = flac["title"][0]
|
||||||
tags.artist = flac["artist"][0]
|
tags.artist = flac["artist"][0]
|
||||||
else:
|
else:
|
||||||
|
@ -46,6 +51,7 @@ def load_tag_information_ffmpeg(file: File) -> Tags:
|
||||||
artist = None
|
artist = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
print(file_tags.keys())
|
||||||
if "title" in file_tags.keys():
|
if "title" in file_tags.keys():
|
||||||
title = file_tags["title"]
|
title = file_tags["title"]
|
||||||
elif "TITLE" in file_tags.keys():
|
elif "TITLE" in file_tags.keys():
|
||||||
|
|
Loading…
Reference in a new issue