[mythtv-users] mythrename.pl subdirectories (was Re: streaming to windows (directly through myth))

Michael T. Dean mtdean at thirdcontact.com
Tue Jan 24 06:41:32 UTC 2006


On 01/23/2006 03:59 PM, Tom Lichti wrote:
> Right. Have you tried my new and improved mythrename.pl? It finally 
> works correctly, and most of my stuff made it into SVN.
>   
As a matter of fact, I have.  It's nice--especially the no LiveTV one.  
And, I've been meaning to do up a change for the one that hasn't yet 
made it into SVN, but never made time for it.  So, your question 
provided the motivation I needed to finally get it done.

The implementation you used for #874 ( 
http://svn.mythtv.org/trac/ticket/874 ) was a good quick hack for 
starting off the subdirectory thing.  However, there were a few things I 
thought we could improve upon.  For example, it made promises about the 
future ("In the future you will be able to pick the field to sub on"); 
took a shortcut ("Any titles with spaces in the name will have the 
spaces changed to underscores to simplify deleting"--I didn't see how 
this simplifies deleting but I didn't look that deep into your code, but 
I hope you were talking about for your code); and only allows creating 
subs based on title, and, therefore, only one level deep.

To make it truly user-customizable, we need the directory names to be 
just another part of the format specifier.  The hard part is the fact 
that we need to replace any "illegal" characters (those that are 
illegal) in directory names as well as filenames, that the path 
separator ("/") is illegal inside directory/file names (so would be 
replaced), and that the "%F" used for the format specifier could exist 
inside a generated name after expansion (so we can't "defer" 
replacement).  Therefore, I used a "placeholder" for the path 
separators.  The placeholder needed to be a character that could never 
exist inside the filename or that would be replaced (i.e. it can't be 
either a legal or illegal character).  The only character that meets 
this criteria is the null character (which, technically is illegal (on 
Windows, and on most *nix filesystems is the *only* illegal character), 
but we aren't replacing it because it shouldn't be there).

Also, I removed the phrase, 'This assumes that recgroup = "LiveTV" for 
live tv recordings,' since the recgroup is *always* LiveTV for LiveTV 
recordings (it's not translated and the user does not have the option to 
change it), so there's no sense worrying the user with the message (if 
anything, it could be made a comment in the Perl source, but doesn't 
belong in the usage message).  And the comment about including time for 
channel-surfers shouldn't be there, either.  There's code to prevent 
problems with duplicate filenames (see code after "# Check for 
duplicates"), but based on your comment, I'm assuming it has a bug (but 
I didn't look into it)...

I'd appreciate your testing this patch and providing feedback (does it 
do everything yours does/work well for you/etc.).  Once I hear from you, 
I can post it on #874, or feel free to do so yourself.  In case you do 
it, I'm including some comments below for Trac.

Thanks,
Mike

This patch allows the user to create subdirectories within a directory 
of links to recordings by using a format specifier to separate directory 
and filenames.  This allows the user to create directories based on any 
desired field or combination of fields as well as creating any number of 
subdirectory levels within the destination directory.

Note that /all/ links within the destination directory and its 
subdirectories (recursive) will be removed when creating links to 
recordings.  Also, any empty directories beneath the destination 
directory will be removed when creating links.

If the user specifies the path separator format specifier ("%F") but is 
attempting to rename files, the path separator will be replaced with the 
replacement character ("%-"), thereby preventing the user from 
attempting to move files.  This behavior is required because the Perl 
implementation of rename varies wildly and usually will not work across 
filesystem boundaries.

BTW, I used "%F" as an abbreviation of "folder" since "%d" (as in 
"directory") was already used (for day of month) and I thought it would 
be easier for most users to remember than "%P" for "path separator".  
However, I included all three terms in the field description just for 
safe measure. ;)
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mythrename-subdirectories.patch
Url: http://mythtv.org/pipermail/mythtv-users/attachments/20060124/e3b61207/mythrename-subdirectories.diff


More information about the mythtv-users mailing list