add a stats command
This commit is contained in:
parent
387d1e6945
commit
86f4865ac7
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
from musicutil.commands.stats_command import StatsCommand, add_stats_command, get_stats_args
|
||||||
|
|
||||||
from .commands.genhtml_command import GenHTMLCommand, add_genhtml_command, get_genhtml_args
|
from .commands.genhtml_command import GenHTMLCommand, add_genhtml_command, get_genhtml_args
|
||||||
from .commands.process_command import ProcessCommand, add_process_command, get_process_args
|
from .commands.process_command import ProcessCommand, add_process_command, get_process_args
|
||||||
from .commands.copy_command import CopyCommand, add_copy_command, get_copy_args
|
from .commands.copy_command import CopyCommand, add_copy_command, get_copy_args
|
||||||
|
@ -16,6 +18,7 @@ def main():
|
||||||
add_process_command(subparsers)
|
add_process_command(subparsers)
|
||||||
add_transcode_command(subparsers)
|
add_transcode_command(subparsers)
|
||||||
add_genhtml_command(subparsers)
|
add_genhtml_command(subparsers)
|
||||||
|
add_stats_command(subparsers)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -27,6 +30,8 @@ def main():
|
||||||
TranscodeCommand(get_transcode_args(args)).run()
|
TranscodeCommand(get_transcode_args(args)).run()
|
||||||
elif args.subparser_name == "genhtml":
|
elif args.subparser_name == "genhtml":
|
||||||
GenHTMLCommand(get_genhtml_args(args)).run()
|
GenHTMLCommand(get_genhtml_args(args)).run()
|
||||||
|
elif args.subparser_name == "stats":
|
||||||
|
StatsCommand(get_stats_args(args)).run()
|
||||||
else:
|
else:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
||||||
|
|
54
musicutil/commands/stats_command.py
Normal file
54
musicutil/commands/stats_command.py
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
from musicutil.utils.load_tag_information import load_tag_information
|
||||||
|
from musicutil.utils.scan_for_music import scan_for_music
|
||||||
|
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
class StatsArgs():
|
||||||
|
src: str
|
||||||
|
|
||||||
|
def add_stats_command(subparsers):
|
||||||
|
stats_parser = subparsers.add_parser('stats')
|
||||||
|
stats_parser.add_argument(
|
||||||
|
'src',
|
||||||
|
type=str,
|
||||||
|
help='src base music directory')
|
||||||
|
|
||||||
|
def get_stats_args(args) -> StatsArgs:
|
||||||
|
command_args = StatsArgs()
|
||||||
|
command_args.src = args.src
|
||||||
|
return command_args
|
||||||
|
|
||||||
|
class StatsCommand():
|
||||||
|
def __init__(self, args: StatsArgs):
|
||||||
|
self.args = args
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
print("Generating HTML...")
|
||||||
|
print("Scanning For Music...")
|
||||||
|
files = scan_for_music(self.args.src)
|
||||||
|
print("Loading Tag Information")
|
||||||
|
for file in files:
|
||||||
|
tags = load_tag_information(file)
|
||||||
|
file.tags = tags
|
||||||
|
|
||||||
|
|
||||||
|
# So far we only support MP3 and Flac so only have these
|
||||||
|
mp3_files_count = len([True for file in files if file.extension == "mp3"])
|
||||||
|
flac_files_count = len([True for file in files if file.extension == "flac"])
|
||||||
|
|
||||||
|
lossy_files_count = mp3_files_count
|
||||||
|
lossless_files_count = flac_files_count
|
||||||
|
total_files_count = lossy_files_count + lossless_files_count
|
||||||
|
|
||||||
|
lossy_percent = (lossy_files_count/total_files_count)
|
||||||
|
lossless_percent = (lossless_files_count/total_files_count)
|
||||||
|
|
||||||
|
print("Stats:")
|
||||||
|
print(f"Total Files: {total_files_count}")
|
||||||
|
print(f"Lossy#: {lossy_files_count}/{total_files_count}")
|
||||||
|
print(f"Lossless#: {lossless_files_count}/{total_files_count}")
|
||||||
|
print(f"Lossy%: {lossy_percent:.2%}")
|
||||||
|
print(f"Lossless%: {lossless_percent:.2%}")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue