scan library fix
This commit is contained in:
parent
2705737c42
commit
cc21dd6403
@ -29,6 +29,6 @@ python3 main.py
|
||||
- [x] right-click menu
|
||||
- [x] editable lyrics window
|
||||
- [x] batch metadata changer (red text on fields that have differing info)
|
||||
- [ ] playlists
|
||||
- [x] playlists
|
||||
- [ ] delete songs from library (del key || right-click delete)
|
||||
- [ ] .wav, .ogg, .flac convertor
|
||||
|
||||
@ -12,7 +12,7 @@ def add_files_to_library(files):
|
||||
files = list() of fully qualified paths to audio file(s)
|
||||
Returns a list of dictionaries of metadata
|
||||
"""
|
||||
print("Running add_files_to_library.py")
|
||||
# print("Running add_files_to_library.py")
|
||||
if not files:
|
||||
return []
|
||||
extensions = config.get("settings", "extensions").split(",")
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
# import os
|
||||
#
|
||||
#
|
||||
# def get_id3_tags(file):
|
||||
# def get_id3_tags(filename):
|
||||
# """Get the ID3 tags for an audio file
|
||||
#
|
||||
# # Parameters
|
||||
@ -19,7 +19,7 @@
|
||||
# audio = ID3()
|
||||
# try:
|
||||
# if not audio["TIT2"] or audio["TIT2"].text[0] == "":
|
||||
# title = os.path.splitext(os.path.basename(file))[0]
|
||||
# title = os.path.splitext(os.path.basename(filename))[0]
|
||||
# frame = TIT2(encoding=3, text=[title])
|
||||
# audio["TIT2"] = frame
|
||||
# audio.save() # type: ignore
|
||||
@ -29,21 +29,25 @@
|
||||
|
||||
|
||||
import os
|
||||
from mutagen.id3 import ID3, TIT2
|
||||
from mutagen.id3 import ID3, TIT2, ID3NoHeaderError
|
||||
|
||||
|
||||
def get_id3_tags(file):
|
||||
def get_id3_tags(filename):
|
||||
"""Get the ID3 tags for an audio file"""
|
||||
print(f"get id3 tags filename: {filename}")
|
||||
|
||||
try:
|
||||
# Open the MP3 file and read its content
|
||||
audio = ID3(file)
|
||||
audio = ID3(filename)
|
||||
except ID3NoHeaderError:
|
||||
audio = ID3()
|
||||
|
||||
if os.path.exists(file):
|
||||
audio.save(os.path.abspath(file))
|
||||
try:
|
||||
if os.path.exists(filename):
|
||||
audio.save(os.path.abspath(filename))
|
||||
|
||||
# If 'TIT2' tag is not set, add it with a default value (title will be the filename without extension)
|
||||
title = os.path.splitext(os.path.basename(file))[0]
|
||||
title = os.path.splitext(os.path.basename(filename))[0]
|
||||
list_of_id3_tags = list(audio.keys())
|
||||
if "TIT2" in list_of_id3_tags:
|
||||
audio.save()
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import os
|
||||
from configparser import ConfigParser
|
||||
from utils import add_files_to_library
|
||||
|
||||
from utils.add_files_to_library import add_files_to_library
|
||||
|
||||
config = ConfigParser()
|
||||
config.read("config.ini")
|
||||
@ -8,6 +9,12 @@ config.read("config.ini")
|
||||
|
||||
def scan_for_music():
|
||||
root_dir = config.get("directories", "library")
|
||||
extensions = config.get("settings", "extensions").split(",")
|
||||
files_to_add = []
|
||||
# for dirpath, dirnames, filenames ...
|
||||
for _, _, filenames in os.walk(root_dir):
|
||||
add_files_to_library(filenames)
|
||||
for dirpath, _, filenames in os.walk(root_dir):
|
||||
for file in filenames:
|
||||
filename = os.path.join(dirpath, file)
|
||||
if any(filename.lower().endswith(ext) for ext in extensions):
|
||||
files_to_add.append(filename)
|
||||
add_files_to_library(files_to_add)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user