Mythrename.pl
From MythTV
mythrename.pl is perl script written by Chris Peterson that renames mythtv recordings to more human-readable filenames. This allows you to archive them away and know what they are by reading the filename; however, the preferred approach is to have the script create symlinks, instead of renaming the files, with the --link argument. Then, with appropriate copy or move commands, the show can be archived with the link's name. Database and directory settings are automatically detected.
For more info, see the output of mythrename.pl --help (the output of which is below)
Location: /usr/share/doc/mythtv-0.21/contrib (insert actual mythtv version as appropriate).
Contents |
Basic Usage
Be very careful running mythrename.pl without any options as it may introduce non-ASCII characters or create very long filenames that could become a problem. Make sure to use the --link option if you are not sure what the results of a name change would be. Note that changing the filenames of recording files will break certain parts of MythTV, so really, you should only run mythrename.pl with the --link option.
To reset the names use this command (not guaranteed to be totally effective):
$ mythrename.pl --verbose --format "%c_%Y%m%d%H%i%s"
Perl prerequisites
Some users have been unable to use mythrename.pl without installing additional modules. The primary issue is Net::UPnP::ControlPoint? is not installed or an error that says something to that effect. Once Net::UPnP::ControlPoint is installed the error doesn't go away, as one must also install Net::UPnP::QueryResponse, as it is a prerequisite for UPnP::ControlPoint.
In gentoo and other linux distros you can install these by running "cpan" at a terminal, most likely as root. Answer the prompts that follow, then type "install Perl Net::UPnP::ControlPoint" at the cpan prompt and ALSO type "cpan> install Net::UPnP::QueryResponse", then run mythrename.pl either as a user with proper user:group permissions at a terminal or use the same command shown below as a "job" under mythtv-setup.
Example syntax of mythrename.pl:
$ /usr/share/mythtv/contrib/mythrename.pl --link /mnt/storage/Movies\ and\ Video/MYTHTVshows/ --format %T/%T%-%S
In Ubuntu 8.04, you will find the perl script in gzip form:
/usr/share/doc/mythtv-backend/contrib/mythrename.pl.gz
In Fedora 10 (probably others) with Mtv vers 0.21, you will find the perl script in :
/usr/share/doc/mythtv-docs-0.21/contrib/mythrename.pl
Help Output
./mythrename.pl usage:
options:
--link [destination directory]
If you would like mythrename.pl to work like the old mythlink.pl, specify
--link and an optional pathname. If no pathname is given, links will be
created in the show_names directory inside of the current mythtv data
directory on this machine. eg:
/var/video/show_names/
WARNING: ALL symlinks within the destination directory and its
subdirectories (recursive) will be removed when using the --link option.
--live
Include live tv recordings, affects both linking and renaming.
default: do not link/rename live tv recordings
--format
default: %T %- %Y-%m-%d, %g-%i %A %- %S
%T = Title (show name)
%S = Subtitle (episode name)
%R = Description
%C = Category
%U = RecGroup
%hn = Hostname of the machine where the file resides
%c = Channel: MythTV chanid
%cn = Channel: channum
%cc = Channel: callsign
%cN = Channel: channel name
%y = Recording start time: year, 2 digits
%Y = Recording start time: year, 4 digits
%n = Recording start time: month
%m = Recording start time: month, leading zero
%j = Recording start time: day of month
%d = Recording start time: day of month, leading zero
%g = Recording start time: 12-hour hour
%G = Recording start time: 24-hour hour
%h = Recording start time: 12-hour hour, with leading zero
%H = Recording start time: 24-hour hour, with leading zero
%i = Recording start time: minutes
%s = Recording start time: seconds
%a = Recording start time: am/pm
%A = Recording start time: AM/PM
%ey = Recording end time: year, 2 digits
%eY = Recording end time: year, 4 digits
%en = Recording end time: month
%em = Recording end time: month, leading zero
%ej = Recording end time: day of month
%ed = Recording end time: day of month, leading zero
%eg = Recording end time: 12-hour hour
%eG = Recording end time: 24-hour hour
%eh = Recording end time: 12-hour hour, with leading zero
%eH = Recording end time: 24-hour hour, with leading zero
%ei = Recording end time: minutes
%es = Recording end time: seconds
%ea = Recording end time: am/pm
%eA = Recording end time: AM/PM
%py = Program start time: year, 2 digits
%pY = Program start time: year, 4 digits
%pn = Program start time: month
%pm = Program start time: month, leading zero
%pj = Program start time: day of month
%pd = Program start time: day of month, leading zero
%pg = Program start time: 12-hour hour
%pG = Program start time: 24-hour hour
%ph = Program start time: 12-hour hour, with leading zero
%pH = Program start time: 24-hour hour, with leading zero
%pi = Program start time: minutes
%ps = Program start time: seconds
%pa = Program start time: am/pm
%pA = Program start time: AM/PM
%pey = Program end time: year, 2 digits
%peY = Program end time: year, 4 digits
%pen = Program end time: month
%pem = Program end time: month, leading zero
%pej = Program end time: day of month
%ped = Program end time: day of month, leading zero
%peg = Program end time: 12-hour hour
%peG = Program end time: 24-hour hour
%peh = Program end time: 12-hour hour, with leading zero
%peH = Program end time: 24-hour hour, with leading zero
%pei = Program end time: minutes
%pes = Program end time: seconds
%pea = Program end time: am/pm
%peA = Program end time: AM/PM
%oy = Original Airdate: year, 2 digits
%oY = Original Airdate: year, 4 digits
%on = Original Airdate: month
%om = Original Airdate: month, leading zero
%oj = Original Airdate: day of month
%od = Original Airdate: day of month, leading zero
%% = a literal % character
* The program start time is the time from the listings data and is not
affected by when the recording started. Therefore, using program start
(or end) times may result in duplicate names. In that case, the script
will append a "counter" value to the name.
* A suffix of .mpg or .nuv will be added where appropriate.
* To separate links into subdirectories, include the / format specifier
between the appropriate fields. For example, "%T/%S" would create
a directory for each title containing links for each recording named
by subtitle. You may use any number of subdirectories in your format
specifier. If used without the --link option, "/" will be replaced
with the "%-" separator character.
--separator
The string used to separate sections of the link name. Specifying the
separator allows trailing separators to be removed from the link name and
multiple separators caused by missing data to be consolidated. Indicate the
separator character in the format string using either a literal character
or the %- specifier.
default: '-'
--replacement
Characters in the link name which are not legal on some filesystems will
be replaced with the given character
illegal characters: \ : * ? < > | "
default: '-'
--underscores
Replace whitespace in filenames with underscore characters.
default: No underscores
--verbose
Print debug info.
default: No info printed to console
--help
Show this help text.
User Contributed Tips
If you use the %R option, you may notice that the description is much longer than 255 characters. I have remedied this problem by substituting these lines of code starting around line 359.
# Make the substitution
my $keys = join('|', sort keys %fields);
my $name = $format;
$name =~ s#/#$dest ? "\0" : $separator#ge;
$name =~ s/(?<!%)(?:%($keys))/$fields{$1}/g;
#Shrink the description, if it is too long. I use 251 to account for a 4 character file extension
if($fields{R} && length($name) > 251) {
$fields{R} = substr($fields{R}, 0, length($name)-251);
$name = $format;
$name =~ s#/#$dest ? "\0" : $separator#ge;
$name =~ s/(?<!%)(?:%($keys))/$fields{$1}/g;
}
$name =~ s/%%/%/g;
# Some basic cleanup for illegal (windows) filename characters, etc.
