00001 #!/usr/bin/perl -w
00002 #
00003 # Tell MythTV to truly delete all recordings in the "Deleted" recgroup
00004 #
00005 # @url $URL$
00006 # @date $Date$
00007 # @version $Revision$
00008 # @author $Author$
00009 #
00010
00011 # Libraries we'll use
00012 use English;
00013 use Getopt::Long;
00014 use File::Basename;
00015 use Cwd 'abs_path';
00016 use lib '.', dirname(abs_path($0 or $PROGRAM_NAME));
00017 use MythTV;
00018
00019 # Some variables we'll use here
00020 our ($command, $force, $usage);
00021
00022 # Load the cli options
00023 GetOptions('force' => \$force,
00024 'usage|help|h' => \$usage
00025 );
00026
00027 # Print usage
00028 if ($usage)
00029 {
00030 print <<EOF;
00031 Usage:
00032 $0 [options]
00033
00034 Deletes recording files and metadata for all recordings in the Deleted
00035 recording group.
00036
00037 options:
00038
00039 --force
00040
00041 Delete the recording metadata even if the file does not exist. Note that
00042 this option should only be used when all storage is connected to and file
00043 systems are mounted on all your backends. Otherwise, forcing deletion of the
00044 metadata may leave orphaned recording files on unconnected file systems.
00045
00046 This option is primarily useful for deleting metadata for a large number of
00047 recordings after losing a file system or otherwise losing many recording
00048 files. Rather than deleting them one by one using mythfrontend and having to
00049 confirm deletion of each recording when the file is not found, you may add a
00050 bunch of recordings to a playlist, then choose MENU|Playlist Options|Change
00051 Recording Group and add the recordings to the Deleted recording group (create
00052 a new group if necessary--its name /must/ be Deleted and is case-sensitive).
00053 Finally, run this script with the --force option. Note that if you have
00054 enabled the setting, "Auto Expire Instead of Delete Recording," this process
00055 will delete all the recordings you just put into the Deleted recording group
00056 and any others that were in there from normal recording deletion.
00057
00058 --help
00059
00060 Show this help text.
00061
00062 EOF
00063 exit;
00064 }
00065
00066 # Check whether to force metadata deletion for non-existent files.
00067 $command = $force ? 'FORCE_DELETE_RECORDING' : 'DELETE_RECORDING';
00068
00069 # Connect to the backend
00070 my $myth = new MythTV();
00071
00072 # Load all of the recordings
00073 my %rows = $myth->backend_rows('QUERY_RECORDINGS Descending');
00074
00075 # Parse each recording, and delete anything in the "Deleted" recgroup
00076 my $i = 0;
00077 foreach my $row (@{$rows{'rows'}}) {
00078 my $show = $myth->new_recording(@$row);
00079 next unless ($show->{'recgroup'} eq 'Deleted');
00080 print "DELETE: $show->{'title'}: $show->{'subtitle'}\n";
00081 my $err = $myth->backend_command(join($MythTV::BACKEND_SEP, $command, $show->to_string(), '0'));
00082 if ($err != -1) {
00083 print " error: $err\n";
00084 }
00085 else {
00086 $i++;
00087 }
00088 }
00089
00090 # Done
00091 if ($i > 0) {
00092 print
00093 "\n",
00094 "Depending on your configuration, it may be several minutes before\n",
00095 "MythTV completely flushes these recordings from your system.\n";
00096 }
00097 else {
00098 print "No recordings were found in the Deleted recording group.\n";
00099 }