[mythtv] Re: [mythtv-commits] Ticket #857: Patch to mythrename.pl
to work correctly with slave backends
Tom Lichti
tom at redpepperracing.com
Fri Dec 23 10:42:01 EST 2005
Michael T. Dean wrote:
> Tom Lichti wrote:
>
>> Tom Lichti wrote:
>>
>>>> Although I'll admit that your approach had one benefit mine didn't:
>>>> you could list the directories to quickly see/count what different
>>>> titles you have available. (Didn't lose sight of the forest for
>>>> the trees.)
>>>
>>> Not sure I see your point here, doesn't your solution do basically
>>> the same thing?
>>
>> Never mind, I see it now... :)
>
> Yeah. Basically with yours you can do the same as:
>
> ls /path/to/view/directory | awk '{split($0,a,"-"); print a[1]}' |
> sort --unique
>
> with a simple:
>
> ls /path/to/view
>
> which is much easier to type (and remember ;). I guess there's always:
>
> mysql -u mythtv -p mythconverg -e 'select distinct(title) from recorded'
Actually, I've got what appears to be a working patch for mythrename. It
only subs on title at the moment. Can you try it out (if you so desire)
and let me know if it works for you? I need to fix the format/indenting...
Also, on your posted patch, how did you get the filenames the way you
did? Mine seems convoluted compared to yours. I'm referring to this part:
Index: contrib/mythrename.pl
===================================================================
--- contrib/mythrename.pl (revision 8364)
+++ contrib/mythrename.pl (working copy)
I assume you are using a local SVN repo? Anyway, here's my patch:
--- /usr/local/src/mythtv/contrib/mythrename.pl 2005-12-23
09:54:45.000000000 -0500
+++ mythrename.pl 2005-12-23 10:25:19.000000000 -0500
@@ -22,7 +22,7 @@
use File::Path;
# Some variables we'll use here
- our ($dest, $format, $usage, $underscores);
+ our ($dest, $format, $usage, $underscores, $sub);
our ($dformat, $dseparator, $dreplacement, $separator, $replacement);
our ($db_host, $db_user, $db_name, $db_pass, $video_dir);
our ($hostname, $dbh, $sh, $sh2, $q, $q2, $count);
@@ -45,7 +45,8 @@
'separator=s' => \$separator,
'replacement=s' => \$replacement,
'usage|help|h' => \$usage,
- 'underscores' => \$underscores
+ 'underscores' => \$underscores,
+ 'sub' => \$sub
);
# Print usage
@@ -64,6 +65,11 @@
/var/video/show_names/
+--sub
+
+ If you would like to make subdirectories per title, specify --sub.
+ In the future you will be able to pick what field to sub on.
+
--format
default: $dformat
@@ -352,10 +359,39 @@
$name .= ".$count";
}
$name .= $suffix;
+
+################ big changes here
+
+# Link destination
+ if (defined($sub)) {
+ # Double-check the destination
+ $sub = "$dest/$info{'title'}";
+ # Alert the user
+ print "Link destination sub-directory: $sub\n";
+ # Create nonexistent paths
+ unless (-e $sub) {
+ mkpath($sub, 0, 0755) or die "Failed to create $sub: $!\n";
+ }
+ # Bad path
+ die "$sub is not a directory.\n" unless (-d $sub);
+ # Delete any old links
+ foreach my $file (<$sub/*>) {
+ next unless (-l $file);
+ unlink $file or die "Couldn't remove old symlink $file: $!\n";
+ }
+ symlink "$video_dir/".$info{'basename'}, "$sub/$name"
+ or die "Can't create symlink $sub/$name: $!\n";
+ print "$sub/$name\n";
+ } else {
+
+
+################ end big changes
+
# Create the link
symlink "$video_dir/".$info{'basename'}, "$dest/$name"
or die "Can't create symlink $dest/$name: $!\n";
print "$dest/$name\n";
+ }
}
# Rename the file
else {
More information about the mythtv-dev
mailing list