summaryrefslogtreecommitdiff
path: root/Tools/master-timer/process_summary.pl
blob: ebe63009f119b7608ff8bddb60d7301a1a64a779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl -w

$dir = "/home/ms/.master-timer";

open (FI,"$dir/done") or die "Can't open \"done\"\n";
while (<FI>)
  {
    chomp;
    if ($_)
      {
        ($title,$subtitle) = split (/\|/,$_,2);
        $Done{$title}{$subtitle}=1;
      }
  }
close (FI);

&traverse('/video');

if ($hit)
  {
    rename ("$dir/done","$dir/done.bak");
    open (FO,">$dir/done");
    foreach $title (sort keys %Done)
      {
	foreach $subtitle (sort keys %{%Done->{$title}})
	  {
	    print FO "$title\|$subtitle\n";
	  }
      }
  }

sub traverse
  {
    local($dir) = shift;
    local($path);
    unless (opendir(DIR, $dir))
      {
	warn "Can't open $dir\n";
	closedir(DIR);
	return;
      }
    foreach (readdir(DIR))
      {
	next if $_ eq '.' || $_ eq '..';
	$path = "$dir/$_";
	if (-d $path) 	# a directory
	  {
	    &traverse($path);
	}
	if ($_ eq "summary.vdr")
	  {
	    open (FI,"$path") or die "Can't open \"$path\"\n";
	    @lines = <FI>;
	    close (FI);
	    if ($lines[0] =~ /^Title\:\s\"(.*)\"/)
	      {
		@titles = split (/\~/,$1);
		if ($lines[2] && $lines[2] =~ /^Subtitle\:\s\"(.*)\"/)
		  {
		    @subtitles = split (/\~/,$1);
		    foreach $num (0 .. $#titles)
		      {
			if ($titles[$num] && $subtitles[$num])
			  {
			    if (!$Done{$titles[$num]}{$subtitles[$num]})
			      {
				$Done{$titles[$num]}{$subtitles[$num]}=1;
				$hit = 1;
			      }
			  }
		      }
		  }
	      }
	  }
      }
    closedir(DIR);
  }