Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: Help wanted: script to convert /video1 to /video01



On Tue, 30 Mar 2004 13:07:13 +0200, Thomas Biebl
<thomas.biebl@tga-net.de> wrote:

> So i would appreciate if you could post it to the list.

Enjoy,
Emil


#!/usr/bin/perl
#
# written by Emil.Naepflein@philosys.de
# 
# Use this tool on your own risk!

use File::Find ();
use Getopt::Std;

$Usage = qq {
Usage: $0 [-F] [<primary video path>]

Options: -F             fix first wrong link
         -s             show missing summary files
};

die $Usage if (!getopts('Fs')) || (@ARGV > 1);

$primarydir = "/video/00";
@secondarydirs = ("/video/04", "/video/05", "/video/06", "/video/07", 
		  "/video/08", 
		  "/video/09", "/video/10", "/video/11", "/video/12", 
		  "/video/13" );
@Genre = ("", "%Action", "%Dokumentation", "%Drama", "%Kinderfilm",
         "%Komödie", "%Musik", "%Science_Fiction", "%Thriller", "../local");

!@ARGV && (@ARGV = ( $primarydir ));

# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;
*prune  = *File::Find::prune;

print("Checking consistency of $ARGV[0]\n");

print("==== Checking primary masterfiles...\n");
File::Find::finddepth({wanted => \&checkpmaster, follow => 1}, $ARGV[0]);

print("==== Checking zero length files...\n");
File::Find::finddepth({wanted => \&checklength}, $ARGV[0]);

if (@secondarydirs)  {
    print("==== Checking links from primary to secondary directories...\n");
    File::Find::finddepth({wanted => \&checklinks}, $ARGV[0]);

    print("==== Checking secondaries for master files\n");
    File::Find::finddepth({wanted => \&checksmaster}, @secondarydirs);

    print("==== Checking secondaries for not referenced data\n");
    File::Find::finddepth({wanted => \&checksdata}, @secondarydirs);

    print("==== Checking secondaries for empty directories\n");
    File::Find::finddepth({wanted => \&checksempty}, @secondarydirs);
}

exit;

sub checkpmaster {
    if (/001.vdr/)  {
	$primary = $name;
	$primary =~ s#001.vdr##;

	! -f $primary . "index.vdr" && printf("%sindex.vdr missing\n", $primary);
	($opt_s) && ($primary =~ m/%/) && ! -f $primary . "summary.vdr" && printf("%ssummary.vdr missing\n", $primary);
    }
}


sub checklength {
    /\d\d\d.vdr/ && -z $_ && print("$name\n");
}


sub checklinks {
    if (/.*\.vdr/ && -l $_ && ! -e $_)  {
	printf("%s\n   -> %s\n   Searching...\n", $name, readlink($_));
	$pattern = $name;
	$pattern =~ s#$primarydir##;
	$pattern =~ s#^/##;
        foreach $Genre ( @Genre )  {
            $pattern =~ s#$Genre##;
        }
	$pattern =~ s#^/##;
	$count = 0; $target = "";
	File::Find::finddepth({wanted => \&checklinks1, follow => 1}, @secondarydirs);
	$count == 0 && print("   **** ERROR: no target found\n");
	$count > 1 && print("   **** ERROR: more than one target found\n");
        if ($count == 1)  {
	    print("   linking to $target?\n");
	    if ($opt_F)  {
		unlink($name);
	     	symlink($target, $name);
		print("   linking... done\n");
		exit;
	    }
	}
    }
}

sub checklinks1 {
    if ($name =~ m#$pattern#)  {
	$count++;
	$target = $name;
    }
}


sub checksmaster {
    (/resume.vdr/) && print("$name\n");
}


sub checksdata {
    if (/\d\d\d.vdr/)  {
	$primary = $name;
	foreach $dir (@secondarydirs)  {
	    $primary =~ s#$dir##;
	}

	$linkfound = 0;
	$deleted = 0;
	$wronglink = 0;
	foreach $Genre ( @Genre )  {
	    $primary = $name;
	    foreach $dir (@secondarydirs)  {
	        $primary =~ s#$dir##;
	    }
#printf("%s\n", $primarydir . "/" . $Genre . $primary);
	    if (! -f $primarydir . "/" . $Genre . "$primary")  {
                $primary =~ s#\.rec/#.del/#;
	        if ( -f $primarydir . "/" . $Genre . $primary)  {
		    $linkfound = 1;
		    $deleted = 1;
	        }
	    } 
	    elsif ((stat($name))[0] != (stat($primarydir . "/" . $Genre . $primary))[0] ||
	           (stat($name))[1] != (stat($primarydir . "/" . $Genre . $primary))[1])  {
		$linkfound = 1;
		$wronglink = 1;
	    }
	    else  {
		$linkfound = 1;
	    }
        }
	(!$linkfound) && ($deleted) && print("$name deleted\n");
	(!$linkfound) && ($wronglink) && print("$name wrong link\n");
	(!$linkfound) && print("$name no link\n");
    }
}


sub checksempty {
    	if (-d $_ && /lost+found/)  {
		print("$_\n");
		opendir(DIR, $_) || die "can't opendir $_: $!";
		@files = grep { /^[^\.]/ } readdir(DIR);
		closedir DIR;

		(!@files) && print("$name\n");
	}
}




-- 
Info:
To unsubscribe send a mail to ecartis@linuxtv.org with "unsubscribe vdr" as subject.



Home | Main Index | Thread Index