#633 tracks update is fixed

pull/652/head
meisnate12 3 years ago
parent 2120315c01
commit 86fa3dbe7c

@ -660,26 +660,24 @@ class MetadataFile(DataFile):
elif not isinstance(album_dict[album_methods["tracks"]], dict): elif not isinstance(album_dict[album_methods["tracks"]], dict):
logger.error("Metadata Error: tracks attribute must be a dictionary") logger.error("Metadata Error: tracks attribute must be a dictionary")
else: else:
tracks = {}
for track in album.tracks():
tracks[track.title] = track
tracks[int(track.index)] = track
for track_num, track_dict in album_dict[album_methods["tracks"]].items(): for track_num, track_dict in album_dict[album_methods["tracks"]].items():
updated = False updated = False
title = None title = None
track_methods = {tm.lower(): tm for tm in track_dict} track_methods = {tm.lower(): tm for tm in track_dict}
logger.info("") logger.info("")
logger.info(f"Updating track {track_num} on {album_name} of {mapping_name}...") logger.info(f"Updating track {track_num} on {album_name} of {mapping_name}...")
try: if track_num in tracks:
if isinstance(track_num, int): track = tracks[track_num]
track = album.track(track=track_num) elif "alt_title" in track_methods and track_dict[track_methods["alt_title"]] and track_dict[track_methods["alt_title"]] in tracks:
else: track = tracks[track_dict[track_methods["alt_title"]]]
track = album.track(title=track_num) title = track_num
except NotFound: else:
try: logger.error(f"Metadata Error: Track: {track_num} not found")
if "alt_title" not in track_methods or not track_dict[track_methods["alt_title"]]: continue
raise NotFound
track = album.track(title=track_dict[track_methods["alt_title"]])
title = track_num
except NotFound:
logger.error(f"Metadata Error: Track: {track_num} not found")
continue
if not title: if not title:
title = track.title title = track.title
@ -689,7 +687,7 @@ class MetadataFile(DataFile):
add_edit("track", track, track_dict, track_methods, key="index", var_type="int") add_edit("track", track, track_dict, track_methods, key="index", var_type="int")
add_edit("disc", track, track_dict, track_methods, key="parentIndex", var_type="int") add_edit("disc", track, track_dict, track_methods, key="parentIndex", var_type="int")
add_edit("original_artist", track, track_dict, track_methods, key="originalTitle") add_edit("original_artist", track, track_dict, track_methods, key="originalTitle")
if self.library.edit_item(album, title, "Track", edits): if self.library.edit_item(track, title, "Track", edits):
updated = True updated = True
if self.edit_tags("mood", track, track_dict, track_methods): if self.edit_tags("mood", track, track_dict, track_methods):
updated = True updated = True

Loading…
Cancel
Save