[mythtv] myth.rebuilddatabase.pl with new filenames

Michael T. Dean mtdean at thirdcontact.com
Wed Oct 19 16:33:00 UTC 2005


Steven wrote:

> looked at it but perl syntax gives me headaches...
> I had to restore my system partition after a reiserfs corruption and 
> noticed afterwards that my database backup script was no longer running.
> So i still have all my recordings but the rebuilddatase script doesn't 
> now how to handle the new filenames (nor the new column in the 
> recorded table) introduced in SVN.
>
> Any perl wizards care to take a look at this? It would be much 
> appreciated .

Sorry, not a perl wizard, but...

I did a quick patch to this about a week ago when I needed to import a 
couple of shows I had moved, but I wasn't yet ready to post it to Trac.  
Instead, I think we need some discussion about how to handle it, first.

The attached patch works, but doesn't take into account the fact that 
the filename can be anything the user wants.  Instead, it forces the 
user to name the file according to the old naming conventions 
(chanid_starttime_endtime.nuv --".nuv" extension included).  I took this 
approach for two primary reasons:
    - Allows the existing code to identify recordings from the 
oldrecordings table by providing chanid, starttime, and endtime in the 
filename
    - Allows a very small patch to get the job done.

However, if it finds any file with a ".nuv" extension that does not use 
the old naming conventions it will report "Non-nuv file found, would you 
like to import it?"  This should not generally be a problem for people 
with MPEG cards, but some users will get a lot of extraneous questions
    - users who updated after the basename column was added, but before 
the filename extensions were changed
     - users who use non-MPEG cards

So, the most straightforward approach is to create a new simple script 
that simply requests information and imports it.  This would be a major 
departure from the existing functionality, but--given that filenames can 
use any format they want (including any extension they want)--I would 
argue that the current "verification" facility is not very appropriate 
anymore.

For those who are worried about the filenames, once the info has been 
imported into the database, the mythrename.pl script can be used to 
change the filename (including the extension) to match the rest of the 
filenames.

More comments, suggestions (or, even better, a new and better 
myth.rebuilddatabase.pl) appreciated.

Mike
-------------- next part --------------
Index: contrib/myth.rebuilddatabase.pl
===================================================================
--- contrib/myth.rebuilddatabase.pl	(revision 7531)
+++ contrib/myth.rebuilddatabase.pl	(working copy)
@@ -234,6 +234,9 @@
 			print("    File: '$show'\n");
 			print("    Title: '$found_title'\n");
 		} else {
+			my $basename = $show;
+			$basename =~ s/$dir\/(.*)/$1/s;
+
 			my $guess = "select title, subtitle, description from oldrecorded where chanid=(?) and starttime=(?) and endtime=(?)";
 			$sth = $dbh->prepare($guess);
 			$sth->execute($channel, $starttime, $endtime)
@@ -278,18 +281,19 @@
 			}
 
 ## add records to db
-			my $i = "insert into recorded (chanid, starttime, endtime, title, subtitle, description, hostname) values ((?), (?), (?), (?), (?), (?), (?))";
+			my $i = "insert into recorded (chanid, starttime, endtime, title, subtitle, description, hostname, basename) values ((?), (?), (?), (?), (?), (?), (?), (?))";
 
 			$sth = $dbh->prepare($i);
 			if (!$test_mode) {
 				$sth->execute($channel, $starttime, $endtime, $newtitle,
-						$newsubtitle, $newdescription, $host)
+						$newsubtitle, $newdescription, $host, $basename)
 					or die "Could not execute ($i)\n";
 			} else {
 				print("Test mode: insert would have been done\n");
 				print("  Query: '$i'\n");
 				print("  Query params: '$channel', '$starttime', '$endtime',");
-				print("'$newtitle', '$newsubtitle', '$newdescription', '$host'\n");
+				print("'$newtitle', '$newsubtitle', '$newdescription',");
+				print("'$host', '$basename'\n");
 				
 			}
 		} ## if
@@ -299,6 +303,9 @@
         print("Do you want to import? (y/n): ");
         chomp(my $do_import = <STDIN>);
         if ($do_import eq "y") {
+			my $basename = $show;
+			$basename =~ s/$dir\/(.*)/$1/s;
+
             print("Enter channel: ");
             chomp(my $tmp_channel = <STDIN>);
             if ($tmp_channel) {$channel = $tmp_channel;}
@@ -324,18 +331,19 @@
 			if ($tmp_description) {$description = $tmp_description;}
 
 ## add records to db
-			my $i = "insert into recorded (chanid, starttime, endtime, title, subtitle, description, hostname) values ((?), (?), (?), (?), (?), (?), (?))";
+			my $i = "insert into recorded (chanid, starttime, endtime, title, subtitle, description, hostname, basename) values ((?), (?), (?), (?), (?), (?), (?), (?))";
 
 			$sth = $dbh->prepare($i);
 			if (!$test_mode) {
 				$sth->execute($channel, $starttime, $endtime, $title,
-						$subtitle, $description, $host)
+						$subtitle, $description, $host, $basename)
 					or die "Could not execute ($i)\n";
 			} else {
 				print("Test mode: insert would have been done\n");
 				print("  Query: '$i'\n");
 				print("  Query params: '$channel', '$starttime', '$endtime',");
-				print("'$title', '$subtitle', '$description', '$host'\n");
+				print("'$title', '$subtitle', '$description', '$host',");
+				print("'$basename'\n");
 				
 			}
 


More information about the mythtv-dev mailing list