Load as Non-Album Track modification?

This one is still a bit above my pay grade :wink:

In Load as NaT, I’d like to have it skip any tracks that are not actually loaded/matched.
I’m sure it needs to happen at tracks = [t for t in objs if isinstance(t, Track, Album)]

    BaseAction,
    register_track_action,
    register_album_action,
)

class LoadAsNat(BaseAction):
    NAME = "Load as non-album track..."

    def callback(self, objs):
        tracks = [t for t in objs if isinstance(t, Track, Album)]

        if len(tracks) == 0:
            return

        for track in tracks:
            nat = self.tagger.load_nat(
                track.metadata['musicbrainz_recordingid'])
            for file in list(track.linked_files):
                file.move(nat)
                metadata = file.metadata
                metadata.delete('albumartist') 
                .
                .
                .
                metadata.delete('tracknumber')
                log.debug("[LoadAsNat] deleted tags: %r", metadata.deleted_tags)

register_track_action(LoadAsNat())
register_album_action(LoadAsNat())

When you’ve got an album missing only a few, particularly a non-artist compilation, and you want to just load the remainder as NaT. (singles)…

I think checking whether there are linked files should do the trick:

        for track in tracks:
            if not track.linked_files:
                continue
            nat = self.tagger.load_nat(
                track.metadata['musicbrainz_recordingid'])
            for file in list(track.linked_files):
                file.move(nat)
                # ...
2 Likes

Linked… there’s the keyword. :slight_smile:
thanks!

Couple more things:

Where in here is Album becoming [Single]?

I’d like to have it become the same as the title and change releasetype to single instead of dropping it.

If I put metadata["album"] = metadata["title"] in there the album doesn’t change to [Single], it changes to deleting the value.

Which then turns to [Single] after it’s saved, and shows as it will be saved next as [Single] if saved again. The latter behavior isn’t a concern. Though it does indicate to me that [Single] album title is happening outside of the plugin.

For the release type, I presume metadata["album"] = "single" should work.

When selecting this with only an Album selected, I presume there needs to be something different in the callback tracks = … area? Since I gather that is only parsing the active selection for selected tracks.

If the selection is an album, then let it parse for the matched tracks within that album is what I’m after.

from picard import log
from picard.track import Track
from picard.ui.itemviews import (
    BaseAction,
    register_track_action,
    register_album_action,
)


class LoadAsNat(BaseAction):
    NAME = "Convert to Single Release..."

    def callback(self, objs):
        tracks = [t for t in objs if isinstance(t, Track)]

        if len(tracks) == 0:
            return

        for track in tracks:
            if not track.linked_files:
                continue
            nat = self.tagger.load_nat(
                track.metadata['musicbrainz_recordingid'])
            for file in list(track.linked_files):
                file.move(nat)
                metadata = file.metadata
                metadata.delete('albumartist')
                metadata.delete('albumartistsort')
                metadata.delete('albumsort')
                metadata.delete('asin')
                metadata.delete('barcode')
                metadata.delete('catalognumber')
                metadata.delete('discnumber')
                metadata.delete('discsubtitle')
                metadata.delete('media')
                metadata.delete('musicbrainz_albumartistid')
                metadata.delete('musicbrainz_albumid')
                metadata.delete('musicbrainz_discid')
                metadata.delete('musicbrainz_releasegroupid')
                # metadata.delete('releasecountry')
                metadata.delete('releasestatus')
                metadata.delete('releasetype')
                metadata.delete('totaldiscs')
                metadata.delete('totaltracks')
                metadata.delete('tracknumber')
                metadata["album"] = metadata["title"]
                log.debug("[LoadAsNat] deleted tags: %r", metadata.deleted_tags)


register_track_action(LoadAsNat())
register_album_action(LoadAsNat())