First of all - HUGE fan of Plex and PlexAmp, and am a lifetime PlexPass user for many years now.
My question has three parts, but connected to the same concepts (count of tracks in an album). The existing “Album Format”, and somehow an album track count.
1.) Having a filter rule that can show me all the albums that in my library that have (only, less than, or more than) N number of tracks. This will help identify albums that need to be cleaned up, or filled. It will also help to identify albums that are not being rightly identified as singles.
2.) How do I change the “Album Format”? There are many albums that Plex is not identifying as singles, but they are in-fact singles. But I don’t see how to change that metdata for an album. I have probably two-three-hundred albums that are being considered normal albums, but are singles.
3.) Both of these used together can help clean and make the library more accurate, but also used in filter rules. I want to be able to create a collection of singles by genre, or maybe I want a collection of albums, not including singles…
I noticed others have also asked for a way to edit the “Album Type” attribute as well.
Are you using MusicBrainz Picard for your file naming and folder structure? If you associate your file with the “single” from MusicBrainz it will show up as a single in Plex. HERE is a thread explaining it more.
Thank you Mark,
Unfortunately, I didn’t start with Picard when I first setup my library a few years ago. I had been using iTunes before migrating over Plex. Years later and by now, I’ve spent probably a hundred hours doing it all in Plex. But you are right, for the issue of Single classification, I could’ve used Picard. Maybe that is still the best solution for that part of my question.
But I’d still like some help/feature request on being able to use a filter rule that can be used based on number of tracks in an album.
If you’re going to stick with Plex I would redo everything with MusicBrainz. I’ve spent countless hours organizing thing as well. I’ve been playing this game 10 years now.
When you say you’re “doing it all in Plex,” does that mean you’re editing in Plex or using something like Mp3tag to edit the meta data?
I think most people would agree that editing the actual meta data is the best long term solution.
Wow, this is cool, thanks so much. I’m not great at python, but let me do some googling and see if I can figure out how to get the plexDB path, and run this. I’ll report back with how it worked. Really appreciate the support/help!
I was able to make this work perfectly after finding the plexdb. One question though - is it possible to add an select element to the SQL select statement that will only include albums that haven’t been marked ‘Single’? Not a big deal, just curious if that’s a simple thing.
Thanks again, this is really cool to see how python can query the MySQL dB.
Sure. This version excludes singles and EPs. It also changes the way it finds albums and now prints the artist.
import sys
import sqlite3
if len(sys.argv) < 3:
print(f"Usage: python3 {sys.argv[0]} <database path> <minimum track count>")
sys.exit(-1)
db_path = sys.argv[1]
min_tracks = sys.argv[2]
print(f"Listing track counts by album...\n")
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute("SELECT id FROM tags WHERE tag is 'Album'")
album_tag = cursor.fetchone()[0]
print(f"Album tag: {album_tag}\n")
cursor.execute("SELECT id,name FROM library_sections WHERE section_type is '8'")
for row in cursor.fetchall():
section_id = row[0]
section_name = row[1]
print(f"Library Name: {section_name}\n")
albums = conn.cursor()
albums.execute(f"""SELECT metadata_items.id,title,parent_id from metadata_items
INNER JOIN taggings ON metadata_items.id = taggings.metadata_item_id
WHERE metadata_items.library_section_id is '{section_id}'
AND metadata_items.metadata_type is '9'
AND taggings.tag_id is {album_tag};""")
for album in albums.fetchall():
album_id = album[0]
album_title = album[1]
album_parent = album[2]
tracks = conn.cursor()
tracks.execute(f"SELECT COUNT(*) FROM metadata_items WHERE parent_id is '{album_id}';")
track_count = tracks.fetchone()[0]
if track_count <= int(min_tracks):
artists = conn.cursor()
artists.execute(f"select title from metadata_items where id is '{album_parent}';")
for artist in artists.fetchall():
album_artist = artist[0]
print(f"Album Artist: {album_artist}");
print(f"Album Title: {album_title}")
print(f"Track Count: {track_count}\n")
conn.close()
Please note that there are likely a hundred different ways to do this, all of them likely better than the logic I’ve chosen. Please don’t take this as a good example of Python programming or constructing SQL queries .