[mythtv-users] mythmusic and MySQL

Brad DerManouelian myth at dermanouelian.com
Mon Aug 4 02:43:48 UTC 2008


On Aug 3, 2008, at 6:09 PM, Yan Seiner wrote:

> I'm seeing some sort of weirdness with my music collection.  Songs
> appear 1 to 4 times.  I've wiped out all the mythmusic tables, reset  
> the
> version, and myth dutifully recreated all my music - again with the
> duplicates.
>
> There must be some SQL query that will a) find all duplicate titles  
> and
> b) print out the offending files as
> Title - location
>
> Could some SQL guru take a shot at that?

You're better off figuring out why you're getting the dupes since they  
will just come back the next time you scan for music.
Besides, you'll need to figure out why you're getting dupes (meaning,  
which columns are dupes so you don't get rid of something by mistake)  
to remove the ones that are actually dupes anyway.

I ran into this a while back because I realized that everyone in my  
family was dumping their mp3's into the same directory on the server  
(this is good!) but some tracks were named with the track numbers  
preceding the track name but most weren't so I had TONS of dupes. I  
wrote this perl script to read the metadata from the mp3's and rename  
the tracks accordingly. I got rid of about 3,000 of my 15,000 files  
this way. Feel free to use/modify as you wish. Don't blame me if it  
erases your hard drive or sets your cat on fire or something. It works  
for me.

#!/usr/bin/perl -w
use strict;
use File::Find;
use MP3::Info;

my $dir = shift || die("Usage: $0 <music directory>\n");
my $counter_tag = 0;
my $counter_notag = 0;
my $counter_process = 0;
my $counter_total = 0;
my @failed;

find(\&rename_files, $dir);
print "Found $counter_total files. Renamed $counter_process of them.  
$counter_tag were named from the MP3 tag. $counter_notag had the  
numbers stripped off.\n\n";
foreach my $failure (@failed)
{
	print $failure . " failed.\n";
}
exit 1;

sub rename_files
{
	if ( -d )
	{
		print "Looking in: " . $_ . "\n";
		return;
	}
	if ( $_ =~ /^\d\d .*(\....)/ )
	{
		# This track starts with 2 numbers so I think it needs to be renamed
		my $filename = $File::Find::name;
		my $origname = $filename;
		my $tag = get_mp3tag($filename);
		if ( $tag->{TITLE} )
		{
			# I found a title tag in the ID3 tags
			$filename = $File::Find::dir . "/" . $tag->{TITLE} . $1;
			return if ( $origname eq $filename );
			$counter_tag++;
		}
		else
		{
			# No Title in ID3 tag, so just strip off the numbers at the beginning
			$filename =~ s/.*\/(\d\d )(.*\....)/$2/g;
			$filename = $File::Find::dir . "/" . $filename;
			return if ( $origname eq $filename );
			$counter_notag++;
		}
		rename($origname,$filename) || push( @failed, $origname);
		$counter_process++;
	}
	$counter_total++;
}




More information about the mythtv-users mailing list