View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 9 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Fri Feb 24, 2012 8:42 am 
Offline
Joined: Tue Aug 08, 2006 7:08 pm
Posts: 554
Location: UK
On finishing watching a file there appears to be a bit of activity from the system, if you delete the file before this stops, an orphaned ..mpg.png file is left. These files are not big, but they could build up over time so I wrote a short script to delete them:
Code:
#!/usr/bin/perl -s

if (defined ($ARGV[0])) {
   $CMDDIR = $ARGV[0] ;
}
else {
   $CMDDIR = "." ;
}

print "DIR is:".$CMDDIR."\n";

if ( -d $CMDDIR ) {
   print "And it is a Directory \n";
   chdir ($CMDDIR) ;

   opendir(DIR, ".") or die "Can't open current directory $! \n";
   
   print "Testing 1\n";

#find .mpg...png files in directory
   @pngnames = grep { /\.mpg.*png$/ } readdir(DIR) or die "No Target Files present:$!\n";
   closedir(DIR);

   foreach $pngname (@pngnames) {
      next if $pngname =~ /^\.\.?$/ ; # skip .. and .

#Shouldn't be any directory entries
      if (-d $name) {
         next;   #can skip to the next name in the loop
      }

# create name of mpg from the png
      $mpgname = $pngname;
      $mpgname =~ s/\..*png$// ;
      $mpgname = $mpgname.".mpg" ;

#If the mpg does not exist, delete the png file
      if (!( -e $mpgname)) {
         print $pngname." Is an Orphan from ".$mpgname." \n";
         print "Deleting... \n";
         unlink ($pngname) ;

      }
   }
}



Just pass the directory path to the tv directory in the command line.
It's not that intelligent, if no pathname is passed, it just uses the current directory, it doesn't do anything clever like looking up the db.

Regards
Bruce S.

_________________
Updated 2011/11/19: Athlon64 3700+ Asus A8N4-SLI Deluxe
1Gb PC 3200, 200Gb+250Gb+500Gb SATA HDD,
SATA DVD-RW Optiarc , Gigabyte GV-NX66128DP
Hauppauage Nova-T 500,+ 2x Nova HD S2 LinHes R6.02


Top
 Profile  
 
PostPosted: Fri Feb 24, 2012 4:30 pm 
Offline
Joined: Wed Nov 16, 2005 8:55 pm
Posts: 1381
Location: Farmington, MI USA
bruce_s01 wrote:
On finishing watching a file there appears to be a bit of activity from the system, if you delete the file before this stops, an orphaned ..mpg.png file is left. These files are not big, but they could build up over time so I wrote a short script to delete them:
Code:
#!/usr/bin/perl -s

if (defined ($ARGV[0])) {
   $CMDDIR = $ARGV[0] ;
}
else {
   $CMDDIR = "." ;
}

print "DIR is:".$CMDDIR."\n";

if ( -d $CMDDIR ) {
   print "And it is a Directory \n";
   chdir ($CMDDIR) ;

   opendir(DIR, ".") or die "Can't open current directory $! \n";
   
   print "Testing 1\n";

#find .mpg...png files in directory
   @pngnames = grep { /\.mpg.*png$/ } readdir(DIR) or die "No Target Files present:$!\n";
   closedir(DIR);

   foreach $pngname (@pngnames) {
      next if $pngname =~ /^\.\.?$/ ; # skip .. and .

#Shouldn't be any directory entries
      if (-d $name) {
         next;   #can skip to the next name in the loop
      }

# create name of mpg from the png
      $mpgname = $pngname;
      $mpgname =~ s/\..*png$// ;
      $mpgname = $mpgname.".mpg" ;

#If the mpg does not exist, delete the png file
      if (!( -e $mpgname)) {
         print $pngname." Is an Orphan from ".$mpgname." \n";
         print "Deleting... \n";
         unlink ($pngname) ;

      }
   }
}



Just pass the directory path to the tv directory in the command line.
It's not that intelligent, if no pathname is passed, it just uses the current directory, it doesn't do anything clever like looking up the db.

Regards
Bruce S.

Nice tip! A bash alternative (not trying to hijack, this is one of the things I love about Linux - "How can I skin this cat"!):
Code:
#!/bin/bash

for file in *.mpg.png
do
   [ ! -f "${file%.*}" ] && {
      rm -f $file
   }
done


WARNING: Unlike Bruce's script this one has no intelligence, it will blindly remove any .mpg.png files that have no corresponding .mpg file in your current working directory.


Top
 Profile  
 
PostPosted: Fri Feb 24, 2012 8:06 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
I remember a couple old scripts for doing this too. This old thread includes some examples, and someone (maybe brfransen?) wrote a fancy combined one that found files with no db entry and db entries with no file, that defaulted to safe "report only" mode and could be told to clean up... http://forum.linhes.org/viewtopic.php?f=6&t=6150


Top
 Profile  
 
PostPosted: Fri Feb 24, 2012 9:05 pm 
Offline
Joined: Tue Aug 15, 2006 11:14 am
Posts: 1198
Location: Orlando FL
If you remove a png file won't myth just make a new one when you scroll over it or play it?

_________________
My System


Top
 Profile  
 
PostPosted: Sat Feb 25, 2012 11:12 am 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
Yes, but I think the point is to delete .png files that no longer have a corresponding .mpg file or DB record.

OBTW - The script I was trying to remember last night was myth.find_orphans.pl which seems to have fallen by the wayside. http://www.mythtv.org/wiki/Myth.find_orphans.pl The modern replacement is this script: http://www.mythtv.org/wiki/Find_orphans.py


Top
 Profile  
 
PostPosted: Sat Feb 25, 2012 6:02 pm 
Offline
Site Admin
Joined: Fri Jun 11, 2004 7:58 am
Posts: 507
you will find that a modified versino of find_orphans.py is already included.


Top
 Profile  
 
PostPosted: Sun Feb 26, 2012 11:55 am 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
Seems to be missing in 6.04, but that may just mean that I don't have some optional package installed.


Top
 Profile  
 
PostPosted: Sun Feb 26, 2012 12:16 pm 
Offline
Site Admin
Joined: Fri Jun 11, 2004 7:58 am
Posts: 507
7.2+ only


Top
 Profile  
 
PostPosted: Mon Jun 18, 2012 5:50 am 
Offline
Joined: Tue Aug 08, 2006 7:08 pm
Posts: 554
Location: UK
Perhaps I should have looked a bit more closely. :)

_________________
Updated 2011/11/19: Athlon64 3700+ Asus A8N4-SLI Deluxe
1Gb PC 3200, 200Gb+250Gb+500Gb SATA HDD,
SATA DVD-RW Optiarc , Gigabyte GV-NX66128DP
Hauppauage Nova-T 500,+ 2x Nova HD S2 LinHes R6.02


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu