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