MythTV  master
testlyrics.pl
Go to the documentation of this file.
1 #!/usr/bin/perl
2 
3 # test all the grabbers, by twitham@sbcglobal.net, 2024/01
4 
5 # Similar to CU LRC's lib/scrapertest.py but for MythTV's *.py
6 # wrappers. This tester adds several additional benefits:
7 
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
13 
14 use warnings;
15 use strict;
16 use Getopt::Long;
17 use File::Basename;
18 use Time::HiRes qw(gettimeofday tv_interval);
19 
20 my $begin = [gettimeofday];
21 my($name, $path, $suffix) = fileparse($0);
22 
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);
25 my %opt;
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
33 ";
34 GetOptions(\%opt, @opt) or die $usage;
35 $opt{v} or $opt{t} or $opt{a} and $opt{n} or die $usage;
36 
37 chdir $path or die $!;
38 opendir DIR, '.' or die $!;
39 my(%pri, %sync);
40 
41 # code reading hack works with current info format:
42 for my $py (grep /\.py$/, readdir DIR) {
43  if (open FILE, $py) {
44  while (<FILE>) {
45  m/'priority':\s*'(\d+)'/
46  and $pri{$py} = $1;
47  m/info.'priority'.\s*=\s*'(\d+)'/
48  and $pri{$py} = $1;
49  m/'syncronized':\s*(\S+)/
50  and $sync{$py} = $1;
51  }
52  }
53 }
54 closedir DIR;
55 
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";
62  my $out = '';
63  open PIPE, '-|', @cmd;
64  while (<PIPE>) {
65  $out .= $_;
66  }
67  close PIPE;
68  $lines{$py} = $out =~ s/<lyric>/<lyric>/g;
69  $lines{$py} ||= 0;
70  $time{$py} = tv_interval($begin, [gettimeofday]);
71  $out and print $out;
72  $out and !$opt{k} and last;
73 }
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";
77 }
78 warn "TOTAL seconds elapsed\t", tv_interval($begin, [gettimeofday]), "\n";