For some reason, every so often after PMS updates my libraries it will combine or stack media that is not related. When it does it after adding new media, it's pretty easy to see since it's in the Recently Added view. However, it sometimes stacks media that has been in my library for a very long time. I used to have to visually search through the PlexWeb gui to look for the little stack icons on each movie. Well now that my library is over 2600 items, that's a little ridiculous. So i wrote this script to search through the database and find media items that point to the same metadata. Here's the code for the script. Just copy into a new text file, replace $data_dir with the location of your PMS database directory, and name it whatever you want (as long as it end in .pl). It requires Text::TabularDisplay so on OSX you install with "sudo cpan install Text::TabularDisplay"
#!/usr/bin/perluse strict;
use DBI;
use Text::TabularDisplay;my $data_dir = ‘/Users/rcork/Library/Application Support/Plex Media Server/Plug-in Support/Databases’;
my $dbh = DBI->connect(“dbi:SQLite:dbname=$data_dir/com.plexapp.plugins.library.db”,"","");
my $sth = $dbh->prepare(
“select a.title, c.file
from metadata_items a
left join media_items b on a.id = b.metadata_item_id
left join media_parts c on b.id = c.media_item_id
where a.id in (
select metadata_item_id from media_items group by metadata_item_id having count(*) > 1
)”);
$sth->execute or die("Unable to execute query: $dbh->errstr
");my @columns = (“Title”,“File”);
my $table = Text::TabularDisplay->new(@columns);
while ( my @row = $sth->fetchrow_array) {
$table->add(@row);
}
if ( $table->items>0 ) {
print $table->render . "
";
}
else {
print "No Combined/Stacked Media
";
}$dbh->disconnect;
I'm not a perl developer so there's not a lot of error handling (if any really). I just thought i'd put this out there in case it helps anyone else out.