3 # test all the grabbers, by twitham@sbcglobal.net, 2024/01
5 # Similar to CU LRC's lib/scrapertest.py but for MythTV's *.py
6 # wrappers. This tester adds several additional benefits:
8 # -t test grabbers in priority order
9 # lookup any -a artist and -n title
10 # stop at first match (default) or -k keep going
11 # high resolution timing summary
12 # report lyric lines found in the summary
18 use Time::HiRes qw(gettimeofday tv_interval);
20 my $begin = [gettimeofday];
21 my($name, $path, $suffix) = fileparse($0);
23 my @opt = qw(k|keepgoing v|version t|test s|search d|debug
24 a|artist=s b|album=s n|title=s f|filename=s);
26 my $usage = "usage: $0 [-d] [-k] [-v | -t | -a artist -n title]
27 -d | --debug extra debugging lines to stderr
28 -k | --keepgoing don't stop at the first match
29 -v | --version show scraper version headers
30 -t | --test lookup known good artist/title
31 -a | --artist lookup given artist
32 -n | --title lookup given name/title
34 GetOptions(\%opt, @opt) or die $usage;
35 $opt{v} or $opt{t} or $opt{a} and $opt{n} or die $usage;
37 chdir $path or die $!;
38 opendir DIR, '.' or die $!;
41 # code reading hack works with current info format:
42 for my $py (grep /\.py$/, readdir DIR) {
45 m/'priority':\s*'(\d+)'/
47 m/info.'priority'.\s*=\s*'(\d+)'/
49 m/'syncronized':\s*(\S+)/
56 my(%found, %time, %lines);
57 @opt = map { $opt{$_} ? ("-$_", $opt{$_}) : () } qw/a b n f v d t/;
58 for my $py (sort { $pri{$a} <=> $pri{$b} } keys %pri) {
59 my $begin = [gettimeofday];
60 my @cmd = ('python3', $py, @opt);
61 warn "$pri{$py}\t$sync{$py}\t@cmd\n";
63 open PIPE, '-|', @cmd;
68 $lines{$py} = $out =~ s/<lyric>/<lyric>/g;
70 $time{$py} = tv_interval($begin, [gettimeofday]);
72 $out and !$opt{k} and last;
74 warn join("\t", qw(pri sync lyrics seconds command)), "\n";
75 for my $py (sort { $pri{$a} <=> $pri{$b} } keys %lines) {
76 warn "$pri{$py}\t$sync{$py}\t$lines{$py}\t$time{$py}\t$py\n";
78 warn "TOTAL seconds elapsed\t", tv_interval($begin, [gettimeofday]), "\n";