kwyntes Posted January 4 Share Posted January 4 (edited) I'm writing a script to (semi-)automatically embed covert art files from selected_aa into the song files themselves, and I'd like some clarification on how exactly Poweramp selects image files for a track. It seems as though it first tries to look for an image file with the name {artist tag content} - {album tag content}.jpg and if that file isn't found, it looks for the filename {artist tag content} - {title tag content}.jpg , ignoring the albumartist field entirely. I've also noticed the tag contents had leading/trailing whitespace removed, and special characters replaced with underscores. I've found the characters []()&/"\' but I'm not sure if that's all of them. Is this correct? Or is there more to it? It's hard for me to confirm because I have a lot of files to go through, and there's also some leftover album art that's not in use anymore (from deleted/retagged songs). Thanks in advance! Edited January 4 by kwyntes additional info Link to comment Share on other sites More sharing options...
andrewilley Posted January 4 Share Posted January 4 Leading/trailing whitespace and many special characters cannot exist in filenames (exactly which ones varies by file system) so to be safe most are replaced with underscore for simplicity. The naming convention was designed to be able to find the images based on the tag text, not really to be reverse-engineered back the other way. But yes, there are also variations for when you are dealing with non-album material, etc. Max could elaborate on the exact logic naming though. Andre Link to comment Share on other sites More sharing options...
kwyntes Posted January 4 Author Share Posted January 4 (edited) 21 minutes ago, andrewilley said: Leading/trailing whitespace and many special characters cannot exist in filenames (exactly which ones varies by file system) so to be safe most are replaced with underscore for simplicity. What I found was that if the artist tag ends in a space, the resulting image filename will still have only a single space before the dash in the filename. 21 minutes ago, andrewilley said: The naming convention was designed to be able to find the images based on the tag text, not really to be reverse-engineered back the other way. I'm not trying to reverse-engineer it the other way, I'm trying to do the same thing Poweramp does to find the appropriate images for a given song file. What I've managed to find right now is this, and while it seems to work, I'd like to know if this is actually equivalent to what Poweramp does internally. SPECIAL_CHARS = # windows disallowed '<>:"/\\|?*' + # found myself '()[]&\'' special_chars_rx = f'[{re.escape(SPECIAL_CHARS)}]' aa_fname_single = f'{re.sub(special_chars_rx, '_', artist_tag).strip()} - {re.sub(special_chars_rx, '_', title_tag).strip()}.jpg' aa_fname_album = f'{re.sub(special_chars_rx, '_', artist_tag).strip()} - {re.sub(special_chars_rx, '_', album_tag).strip()}.jpg' if os.path.isfile(aa_fname_album): # embed aa_fname_album into the song file elif os.path.isfile(aa_fname_single): # embed aa_fname_single into the song file Edited January 4 by kwyntes fix formatting Link to comment Share on other sites More sharing options...
andrewilley Posted January 4 Share Posted January 4 @kwyntes As I said, the exact logic would be something for Max to answer, but you've got the general gist I think. Also if there are no tags at all, I think the base filename is used. Andre Link to comment Share on other sites More sharing options...
Solution maxmp Posted January 4 Solution Share Posted January 4 The filename part of the path depends on category type. For the non-stream tracks it would be this function: https://gist.github.com/maxmpz/6e83a36e16c3fd4fd7cfe1d5cd440f29 Where relevant PathUtils methods are here: https://gist.github.com/maxmpz/dab88451c0f54c6851074e7146cd5b8d Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now