feat(audiobook_library): improve logging, add actions variable to choose what metadata to fix
This commit is contained in:
1 parent
add30d5f90
commit
e591602d18
1 file changed
+45
-15
@@ -89,9 +89,10 @@ metadata_fields = [
|
|||||||
]
|
]
|
||||||
SEP = r"\s*[-_:,.]+\s*"
|
SEP = r"\s*[-_:,.]+\s*"
|
||||||
series_patterns = [
|
series_patterns = [
|
||||||
|
rf"^(.+?){SEP}(?:Book|Band|Volume|Vol)\s+(\d+)(?:{SEP}(.+))$",
|
||||||
|
rf"^(.+?){SEP}(?:Book|Band|Volume|Vol)\s+(\d+)$",
|
||||||
rf"^(\d+){SEP}(.+)$",
|
rf"^(\d+){SEP}(.+)$",
|
||||||
rf"^(.+?){SEP}(\d+)$",
|
rf"^(.+?){SEP}(\d+)$",
|
||||||
rf"^(.+?){SEP}(?:Book|Band|Volume)\s+(\d+)(?:{SEP}(.+))$",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -1132,10 +1133,12 @@ class AudiobookLibrary:
|
|||||||
def init(self):
|
def init(self):
|
||||||
if not self.connect():
|
if not self.connect():
|
||||||
return False
|
return False
|
||||||
|
logger.info("Database initialized successfully")
|
||||||
|
|
||||||
return self.load_database_data()
|
return self.load_database_data()
|
||||||
|
|
||||||
def load_database_data(self) -> bool:
|
def load_database_data(self) -> bool:
|
||||||
|
logger.info("Load Database data")
|
||||||
if not self.db:
|
if not self.db:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
self.tables = self.db.execute(
|
self.tables = self.db.execute(
|
||||||
@@ -1189,6 +1192,7 @@ class AudiobookLibrary:
|
|||||||
# commit once after all updates
|
# commit once after all updates
|
||||||
|
|
||||||
def fix_genres(self):
|
def fix_genres(self):
|
||||||
|
logger.info("Fix genres in database")
|
||||||
for book in self.books:
|
for book in self.books:
|
||||||
genres = book.get("genres")
|
genres = book.get("genres")
|
||||||
if not genres or not any(g.strip() for g in genres):
|
if not genres or not any(g.strip() for g in genres):
|
||||||
@@ -1211,13 +1215,13 @@ class AudiobookLibrary:
|
|||||||
logger.trace(f"Too long or too short: {genre}")
|
logger.trace(f"Too long or too short: {genre}")
|
||||||
genre = genre.strip()
|
genre = genre.strip()
|
||||||
genre = genre.lstrip()
|
genre = genre.lstrip()
|
||||||
new_genres.append(genre)
|
if genre:
|
||||||
|
new_genres.append(genre)
|
||||||
elif isinstance(genre, list):
|
elif isinstance(genre, list):
|
||||||
if len(genres) > 1:
|
genre_buf = genre
|
||||||
genres = [g.strip() for g in genre if g]
|
if len(genre) > 1:
|
||||||
logger.trace(f"REPR: {repr(genres)}")
|
genre_buf = [g.strip() for g in genre if g]
|
||||||
logger.trace(f"GENRES: {genres}")
|
new_genres.extend(genre_buf)
|
||||||
new_genres.extend(genre)
|
|
||||||
|
|
||||||
new_genres = sorted(set(new_genres))
|
new_genres = sorted(set(new_genres))
|
||||||
logger.trace(f"{new_genres}")
|
logger.trace(f"{new_genres}")
|
||||||
@@ -1237,6 +1241,7 @@ class AudiobookLibrary:
|
|||||||
book["genres"] = new_genres
|
book["genres"] = new_genres
|
||||||
|
|
||||||
def fix_comments(self):
|
def fix_comments(self):
|
||||||
|
logger.info("Fix comments in database")
|
||||||
for book in self.books:
|
for book in self.books:
|
||||||
for file in book.get("audioFiles"):
|
for file in book.get("audioFiles"):
|
||||||
comment = file.get("metaTags").get("tagComment")
|
comment = file.get("metaTags").get("tagComment")
|
||||||
@@ -1606,6 +1611,23 @@ def main():
|
|||||||
help="Create structured directories for all books: /artist/series/book(read by X)/file.m4b",
|
help="Create structured directories for all books: /artist/series/book(read by X)/file.m4b",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
actions = [
|
||||||
|
"artis_dir",
|
||||||
|
"artists",
|
||||||
|
"composers",
|
||||||
|
"series",
|
||||||
|
"names",
|
||||||
|
"genres",
|
||||||
|
"comments",
|
||||||
|
"titles",
|
||||||
|
]
|
||||||
|
parser.add_argument(
|
||||||
|
"--actions",
|
||||||
|
nargs="+",
|
||||||
|
choices=actions,
|
||||||
|
default=actions,
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if "--sql-database" in sys.argv:
|
if "--sql-database" in sys.argv:
|
||||||
args.fix_db = True
|
args.fix_db = True
|
||||||
@@ -1626,14 +1648,22 @@ def main():
|
|||||||
library.api_instance.load_books()
|
library.api_instance.load_books()
|
||||||
library.api_instance.embed_metadata_from_file("~/embed_ids.txt")
|
library.api_instance.embed_metadata_from_file("~/embed_ids.txt")
|
||||||
#library.api_instance.embed_metadata_for_all_books(args)
|
#library.api_instance.embed_metadata_for_all_books(args)
|
||||||
library.fix_artist_dir()
|
if "artist_dir" in args.actions:
|
||||||
library.fix_artists(args.force_artist_from_path)
|
library.fix_artist_dir()
|
||||||
library.fix_composers()
|
if "artists" in args.actions:
|
||||||
library.fix_series()
|
library.fix_artists(args.force_artist_from_path)
|
||||||
library.fix_names()
|
if "composers" in args.actions:
|
||||||
library.fix_comments()
|
library.fix_composers()
|
||||||
library.fix_genres()
|
if "series" in args.actions:
|
||||||
library.fix_titles()
|
library.fix_series()
|
||||||
|
if "names" in args.actions:
|
||||||
|
library.fix_names()
|
||||||
|
if "comments" in args.actions:
|
||||||
|
library.fix_comments()
|
||||||
|
if "genres" in args.actions:
|
||||||
|
library.fix_genres()
|
||||||
|
if "titles" in args.actions:
|
||||||
|
library.fix_titles()
|
||||||
|
|
||||||
if args.fix_db:
|
if args.fix_db:
|
||||||
if not database_path.is_file():
|
if not database_path.is_file():
|
||||||
|
|||||||
Reference in new issue
Block a user