lib/App/DrivePlayer/MetadataFetcher.pm

filter: Statementstmt 11.6% 35 / 301 Branchbran 0.0% 0 / 190 Conditioncond 0.0% 0 / 105 MC/DCmcdc 0.0% 0 / 64 Subroutinesub 15.7% 6 / 38 Podpod 25.0% 2 / 8 totaltotal 6.0% 43 / 706 CC 136 SCAR 49.0
CC
136
Cov
6%
read_embedded_tags
380.0
fetch_by_fingerprint
342.0
fetch
210.0
CRAP 134.4
« lib/App/DrivePlayer/SheetDB.pm ↑ Summary blib/lib/App/DrivePlayer/GUI.pm »
1 package App::DrivePlayer::MetadataFetcher;
2  
3 1 ▶use App::DrivePlayer::Setup;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use File::Temp qw( tempfile );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use JSON::PP qw( decode_json );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use URI::Escape qw( uri_escape_utf8 );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Time::HiRes qw( sleep time usleep );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 my $log = do { eval { require Log::Log4perl; Log::Log4perl->get_logger(__PACKAGE__) } };
11  
12 1 Readonly my $USER_AGENT => 'DrivePlayer/1.0 (https://github.com/mvsjes2/drive_player)';
13 1 Readonly my $ITUNES_BASE => 'https://itunes.apple.com/search';
14 1 Readonly my $MB_BASE => 'https://musicbrainz.org/ws/2';
15 1 Readonly my $AID_BASE => 'https://api.acoustid.org/v2/lookup';
16 1 Readonly my $DRIVE_URL => 'https://www.googleapis.com/drive/v3/files/%s?alt=media';
17 1 Readonly my $MB_MIN_GAP => 1.1;
18 1 Readonly my $DOWNLOAD_MB => 5; # MB to download for fingerprinting
19  
20 1 my $last_mb_req = 0;
21  
22 has yield => (
23 is => 'ro',
24 isa => Maybe[CodeRef],
25 0 ▶ default => sub { undef },
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 1 );
27  
28 has acoustid_key => (
29 is => 'ro',
30 isa => Str,
31 0 ▶ default => sub { '' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 1 );
33  
34 has token_fn => (
35 is => 'ro',
36 isa => Maybe[CodeRef],
37 0 ▶ default => sub { undef },
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 1 );
39  
40 has _fp_stage => (
41 is => 'rw',
42 0 ▶ default => sub { undef },
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 1 );
44  
45 # Returns a short description of where the last fingerprint lookup stopped.
46 0 ▶sub last_fp_stage { $_[0]->_fp_stage }
Subroutine last_fp_stage: not called CC=1 SCAR=6.9
Pod undocumented
47  
48 # ------------------------------------------------------------------
49 # Public: text-based lookup (iTunes -> MusicBrainz, with title cleaning)
50 # ------------------------------------------------------------------
51  
52 0 ▶sub fetch {
Subroutine fetch: not called CC=14 SCAR=53.5
Pod documented
53 0 my ($self, %args) = @_;
54 0 ▶ my $title = $args{title} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $title = $args{"title"} or return 0 0 0
55 0 ▶ my $artist = _clean_field($args{artist} // '');
Condition0%0/2
$args{"artist"} // ""
l!l
00
MC/DC0%0/1
$args{"artist"} // ""
$args{"artist"}
Truth table0%0/2
A
A= $args{"artist"}
Aresult
11
00
56 0 ▶ my $album = _clean_field($args{album} // '');
Condition0%0/2
$args{"album"} // ""
l!l
00
MC/DC0%0/1
$args{"album"} // ""
$args{"album"}
Truth table0%0/2
A
A= $args{"album"}
Aresult
11
00
57  
58 0 ▶ $log->debug("Text search: title='$title' artist='$artist'") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
59  
60 # 1. Try with original values
61 0 ▶ my $meta = $self->_fetch_itunes($title, $artist, $album)
Condition0%0/3
$self->_fetch_itunes($title, $artist, $album) // $self->_fetch_musicbrainz($title, $artist, $album)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_fetch_itunes($title, $artist, $album) // $self->_fetch_musicbrainz($title, $artist, $album)
$self->_fetch_itunes($title, $artist, $album) $self->_fetch_musicbrainz($title, $artist, $album)
Truth table0%0/3
A // B
A= $self->_fetch_itunes($title, $artist, $album)B= $self->_fetch_musicbrainz($title, $artist, $album)
ABresult
1X1
011
000
62 // $self->_fetch_musicbrainz($title, $artist, $album);
63 0 ▶ if ($meta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta) 0 0 0
64 0 ▶ $log->debug("Text search hit for '$title'") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
65 0 return $meta;
66 }
67  
68 # 2. Try with cleaned title
69 0 my $clean = _clean_title($title);
70 0 ▶ if ($clean eq $title) {
Branch: 1 branch
BranchTrueFalseTotal
if ($clean eq $title) 0 0 0
71 0 ▶ $log->debug("Text search miss for '$title' (no clean variant)") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
72 0 return;
73 }
74  
75 0 ▶ $log->debug("Retrying with cleaned title '$clean'") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
76 0 ▶ $meta = $self->_fetch_itunes($clean, $artist, $album)
Condition0%0/3
$self->_fetch_itunes($clean, $artist, $album) // $self->_fetch_musicbrainz($clean, $artist, $album)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_fetch_itunes($clean, $artist, $album) // $self->_fetch_musicbrainz($clean, $artist, $album)
$self->_fetch_itunes($clean, $artist, $album) $self->_fetch_musicbrainz($clean, $artist, $album)
Truth table0%0/3
A // B
A= $self->_fetch_itunes($clean, $artist, $album)B= $self->_fetch_musicbrainz($clean, $artist, $album)
ABresult
1X1
011
000
77 // $self->_fetch_musicbrainz($clean, $artist, $album);
78 0 ▶ $log->debug($meta ? "Text search hit (cleaned) for '$title'" : "Text search miss for '$title'") if $log;
Branch: 2 branches
BranchTrueFalseTotal
if $log 0 0 0
$meta ? : 0 0 0
79 0 return $meta;
80 }
81  
82 # ------------------------------------------------------------------
83 # Public: AcoustID fingerprint lookup
84 # ------------------------------------------------------------------
85  
86 0 ▶sub fetch_by_fingerprint {
Subroutine fetch_by_fingerprint: not called CC=18 SCAR=58.3
Pod documented
87 0 my ($self, %args) = @_;
88 0 ▶ my $drive_id = $args{drive_id} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $drive_id = $args{"drive_id"} or return 0 0 0
89 0 $self->_fp_stage(undef);
90  
91 0 ▶ return unless $self->acoustid_key && $self->token_fn;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->acoustid_key and $self->token_fn 0 0 0
Condition0%0/3
$self->acoustid_key and $self->token_fn
!ll&&!rl&&r
000
MC/DC0%0/2
$self->acoustid_key and $self->token_fn
$self->acoustid_key $self->token_fn
Truth table0%0/3
A and B
A= $self->acoustid_keyB= $self->token_fn
ABresult
0X0
100
111
92 0 ▶ return unless fpcalc_available();
Branch: 1 branch
BranchTrueFalseTotal
unless fpcalc_available() 0 0 0
93  
94 0 $self->_fp_stage('downloading audio');
95 0 ▶ $log->info("Fingerprint: downloading audio for drive_id=$drive_id") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
96 0 my $tmpfile = $self->_download_partial($drive_id);
97 0 ▶ unless ($tmpfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmpfile) 0 0 0
98 0 $self->_fp_stage('download failed (token expired or Drive error)');
99 0 ▶ $log->warn("Fingerprint: download failed for drive_id=$drive_id") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
100 0 return;
101 }
102  
103 0 $self->_fp_stage('running fpcalc');
104 0 ▶ $log->debug("Fingerprint: running fpcalc on $tmpfile") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
105 0 my $fp = _fingerprint($tmpfile);
106 0 unlink $tmpfile;
107 0 ▶ unless ($fp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fp) 0 0 0
108 0 $self->_fp_stage('fpcalc produced no fingerprint');
109 0 ▶ $log->warn("Fingerprint: fpcalc produced no output for drive_id=$drive_id") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
110 0 return;
111 }
112  
113 0 $self->_fp_stage('querying AcoustID');
114 0 ▶ $log->debug("Fingerprint: querying AcoustID (duration=$fp->{duration}s)") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
115 0 my $aid = $self->_query_acoustid($fp);
116 0 ▶ unless ($aid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($aid) 0 0 0
117 0 $self->_fp_stage('no AcoustID match (score too low or track unknown)');
118 0 ▶ $log->info("Fingerprint: no AcoustID match for drive_id=$drive_id") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
119 0 return;
120 }
121  
122 0 $self->_fp_stage('fetching MusicBrainz metadata');
123 0 ▶ $log->info("Fingerprint: AcoustID matched MusicBrainz recording $aid") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
124 0 my $meta = $self->_fetch_musicbrainz_by_id($aid);
125 0 ▶ $self->_fp_stage($meta ? undef : 'MusicBrainz returned no data');
Branch: 1 branch
BranchTrueFalseTotal
$meta ? : 0 0 0
126 0 ▶ $log->info($meta ? "Fingerprint: metadata found for drive_id=$drive_id" : "Fingerprint: MusicBrainz returned no data for $aid") if $log;
Branch: 2 branches
BranchTrueFalseTotal
if $log 0 0 0
$meta ? : 0 0 0
127 0 return $meta;
128 }
129  
130 # ------------------------------------------------------------------
131 # Title cleaning
132 # ------------------------------------------------------------------
133  
134 0 ▶sub _clean_field {
Subroutine _clean_field: not called CC=1 SCAR=6.9
135 0 my ($s) = @_;
136 0 $s =~ s/_/ /g;
137 0 $s =~ s/\s+/ /g;
138 0 $s =~ s/^\s+|\s+$//g;
139 0 return $s;
140 }
141  
142 0 ▶sub _clean_title {
Subroutine _clean_title: not called CC=2 SCAR=17.9
143 0 my ($t) = @_;
144  
145 # Normalise underscores and whitespace before any pattern matching
146 0 $t =~ s/_/ /g;
147 0 $t =~ s/\s+/ /g;
148 0 $t =~ s/^\s+|\s+$//g;
149  
150 # Strip leading track number: "01.", "01 -", "(01)", "[01]", "01 "
151 0 $t =~ s/^\s*[\(\[]?\d{1,3}[\)\]]?[\s.\-]+//;
152  
153 # Strip feat/ft/featuring/with credits
154 0 $t =~ s/\s*[\(\[](feat|ft|featuring|with)\.?\s+[^\)\]]+[\)\]]//ig;
155 0 $t =~ s/\s+(feat|ft|featuring)\s+.+$//ig;
156  
157 # Strip common parenthetical junk (order matters: specific before generic)
158 0 my @strip = (
159 qr/\s*[\(\[]\s*(?:\d{4}\s+)?(?:digital\s+)?remaster(?:ed)?(?:\s+\d{4})?\s*[\)\]]/i,
160 qr/\s*[\(\[]\s*live(?:\s+at\s+[^\)\]]+)?\s*[\)\]]/i,
161 qr/\s*[\(\[]\s*(?:official\s+)?(?:audio|video|lyric\s+video|music\s+video)\s*[\)\]]/i,
162 qr/\s*[\(\[]\s*(?:radio|single|album|extended|original|instrumental|acoustic|demo|mono|stereo)\s+(?:edit|version|mix|take)?\s*[\)\]]/i,
163 qr/\s*[\(\[]\s*(?:explicit|clean|censored)\s*[\)\]]/i,
164 qr/\s*[\(\[]\s*(?:hd|hq|\d+hz|\d+\s*hz|4k)\s*[\)\]]/i,
165 qr/\s*-\s*(?:single|ep|soundtrack)\s*$/i,
166 qr/\s*[\(\[]\s*(?:19|20)\d{2}\s*[\)\]]/,
167 );
168 0 for my $re (@strip) { $t =~ s/$re//g }
169  
170 0 return _clean_field($t);
171 }
172  
173 # ------------------------------------------------------------------
174 # iTunes
175 # ------------------------------------------------------------------
176  
177 0 ▶sub _fetch_itunes {
Subroutine _fetch_itunes: not called CC=11 SCAR=48.8
178 0 my ($self, $title, $artist, $album) = @_;
179  
180 0 my $term = join(' ', grep { length } $artist, $title);
181 0 my $url = $ITUNES_BASE . '?term=' . uri_escape_utf8($term)
182 . '&entity=song&media=music&limit=5';
183  
184 0 ▶ my $data = $self->_get_plain($url) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $data = $self->_get_plain($url) or return 0 0 0
185 0 ▶ my $results = $data->{results} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $results = $data->{"results"} or return 0 0 0
186 0 ▶ return unless @$results;
Branch: 1 branch
BranchTrueFalseTotal
unless @$results 0 0 0
187  
188 0 my $best = _best_itunes_match($results, $title, $artist, $album);
189 0 ▶ return unless $best;
Branch: 1 branch
BranchTrueFalseTotal
unless $best 0 0 0
190  
191 0 my %meta;
192 0 ▶ $meta{title} = $best->{trackName} if $best->{trackName};
Branch: 1 branch
BranchTrueFalseTotal
if $best->{"trackName"} 0 0 0
193 0 ▶ $meta{artist} = $best->{artistName} if $best->{artistName};
Branch: 1 branch
BranchTrueFalseTotal
if $best->{"artistName"} 0 0 0
194 0 ▶ $meta{album} = $best->{collectionName} if $best->{collectionName};
Branch: 1 branch
BranchTrueFalseTotal
if $best->{"collectionName"} 0 0 0
195 0 ▶ $meta{genre} = $best->{primaryGenreName} if $best->{primaryGenreName};
Branch: 1 branch
BranchTrueFalseTotal
if $best->{"primaryGenreName"} 0 0 0
196 0 ▶ $meta{track_number} = $best->{trackNumber} if $best->{trackNumber};
Branch: 1 branch
BranchTrueFalseTotal
if $best->{"trackNumber"} 0 0 0
197 0 ▶ ($meta{year}) = ($best->{releaseDate} // '') =~ /^(\d{4})/;
Condition0%0/2
$best->{"releaseDate"} // ""
l!l
00
MC/DC0%0/1
$best->{"releaseDate"} // ""
$best->{"releaseDate"}
Truth table0%0/2
A
A= $best->{"releaseDate"}
Aresult
11
00
198 0 return \%meta;
199 }
200  
201 0 ▶sub _best_itunes_match {
Subroutine _best_itunes_match: not called CC=3 SCAR=24.8
202 0 my ($results, $want_title, $want_artist, $want_album) = @_;
203 0 ▶ my $score = sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
204 0 my ($r) = @_;
205 0 my $s = 0;
206 0 ▶ $s += 3 if $want_title && _fuzzy($r->{trackName}, $want_title);
Branch: 1 branch
BranchTrueFalseTotal
if $want_title and _fuzzy($r->{"trackName"}, $want_title) 0 0 0
Condition0%0/3
$want_title and _fuzzy($r->{"trackName"}, $want_title)
!ll&&!rl&&r
000
MC/DC0%0/2
$want_title and _fuzzy($r->{"trackName"}, $want_title)
$want_title _fuzzy($r->{"trackName"}, $want_title)
Truth table0%0/3
A and B
A= $want_titleB= _fuzzy($r->{"trackName"}, $want_title)
ABresult
0X0
100
111
207 0 ▶ $s += 2 if $want_artist && _fuzzy($r->{artistName}, $want_artist);
Branch: 1 branch
BranchTrueFalseTotal
if $want_artist and _fuzzy($r->{"artistName"}, $want_artist) 0 0 0
Condition0%0/3
$want_artist and _fuzzy($r->{"artistName"}, $want_artist)
!ll&&!rl&&r
000
MC/DC0%0/2
$want_artist and _fuzzy($r->{"artistName"}, $want_artist)
$want_artist _fuzzy($r->{"artistName"}, $want_artist)
Truth table0%0/3
A and B
A= $want_artistB= _fuzzy($r->{"artistName"}, $want_artist)
ABresult
0X0
100
111
208 0 ▶ $s += 1 if $want_album && _fuzzy($r->{collectionName}, $want_album);
Branch: 1 branch
BranchTrueFalseTotal
if $want_album and _fuzzy($r->{"collectionName"}, $want_album) 0 0 0
Condition0%0/3
$want_album and _fuzzy($r->{"collectionName"}, $want_album)
!ll&&!rl&&r
000
MC/DC0%0/2
$want_album and _fuzzy($r->{"collectionName"}, $want_album)
$want_album _fuzzy($r->{"collectionName"}, $want_album)
Truth table0%0/3
A and B
A= $want_albumB= _fuzzy($r->{"collectionName"}, $want_album)
ABresult
0X0
100
111
209 0 return $s;
210 0 };
211 0 my ($best) = sort { $score->($b) <=> $score->($a) } @$results;
212 0 ▶ return unless $want_title && _fuzzy($best->{trackName}, $want_title);
Branch: 1 branch
BranchTrueFalseTotal
unless $want_title and _fuzzy($best->{"trackName"}, $want_title) 0 0 0
Condition0%0/3
$want_title and _fuzzy($best->{"trackName"}, $want_title)
!ll&&!rl&&r
000
MC/DC0%0/2
$want_title and _fuzzy($best->{"trackName"}, $want_title)
$want_title _fuzzy($best->{"trackName"}, $want_title)
Truth table0%0/3
A and B
A= $want_titleB= _fuzzy($best->{"trackName"}, $want_title)
ABresult
0X0
100
111
213 0 return $best;
214 }
215  
216 0 ▶sub _fuzzy {
Subroutine _fuzzy: not called CC=5 SCAR=34.0
217 0 my ($hay, $needle) = @_;
218 0 ▶ return unless defined $hay && defined $needle && length $needle;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hay and defined $needle and length $needle 0 0 0
Condition0%0/6
defined $hay and defined $needle and length $needle
!ll&&!rl&&r
000
defined $hay and defined $needle
!ll&&!rl&&r
000
MC/DC0%0/3
defined $hay and defined $needle and length $needle
defined $hay defined $needle length $needle
Truth table0%0/4
A and B and C
A= defined $hayB= defined $needleC= length $needle
ABCresult
0XX0
10X0
1100
1111
219 0 ▶ return index(lc($hay), lc($needle)) >= 0
Condition0%0/3
index(lc $hay, lc $needle) != -1 || index(lc $needle, lc $hay) != -1
l!l&&r!l&&!r
000
MC/DC0%0/2
index(lc $hay, lc $needle) != -1 || index(lc $needle, lc $hay) != -1
index(lc $hay, lc $needle) != -1 index(lc $needle, lc $hay) != -1
Truth table0%0/3
A || B
A= index(lc $hay, lc $needle) != -1B= index(lc $needle, lc $hay) != -1
ABresult
1X1
011
000
220 || index(lc($needle), lc($hay)) >= 0;
221 }
222  
223 # ------------------------------------------------------------------
224 # MusicBrainz (text search, fuzzy, progressive relaxation)
225 # ------------------------------------------------------------------
226  
227 0 ▶sub _fetch_musicbrainz {
Subroutine _fetch_musicbrainz: not called CC=10 SCAR=47.0
228 0 my ($self, $title, $artist, $album) = @_;
229  
230 0 my @attempts;
231 0 ▶ push @attempts, 'recording:' . _mb_q($title) . '~ AND artist:' . _mb_q($artist)
Branch: 1 branch
BranchTrueFalseTotal
if $artist and $album 0 0 0
Condition0%0/3
$artist and $album
!ll&&!rl&&r
000
MC/DC0%0/2
$artist and $album
$artist $album
Truth table0%0/3
A and B
A= $artistB= $album
ABresult
0X0
100
111
232 . '~ AND release:' . _mb_q($album) . '~'
233 if $artist && $album;
234 0 ▶ push @attempts, 'recording:' . _mb_q($title) . '~ AND artist:' . _mb_q($artist) . '~'
Branch: 1 branch
BranchTrueFalseTotal
if $artist 0 0 0
235 if $artist;
236 0 push @attempts, 'recording:' . _mb_q($title) . '~';
237  
238 0 for my $query (@attempts) {
239 0 my $url = "$MB_BASE/recording?query=" . uri_escape_utf8($query)
240 . '&fmt=json&limit=5&inc=releases+artist-credits+tags+genres';
241 0 ▶ my $data = $self->_get_mb($url) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $data = $self->_get_mb($url) or next 0 0 0
242 0 ▶ my $recs = $data->{recordings} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $recs = $data->{"recordings"} or next 0 0 0
243 0 ▶ next unless @$recs;
Branch: 1 branch
BranchTrueFalseTotal
unless @$recs 0 0 0
244 0 my $meta = $self->_parse_mb_with_release($recs->[0]);
245 0 ▶ return $meta if $meta && %$meta;
Branch: 1 branch
BranchTrueFalseTotal
if $meta and %$meta 0 0 0
Condition0%0/3
$meta and %$meta
!ll&&!rl&&r
000
MC/DC0%0/2
$meta and %$meta
$meta %$meta
Truth table0%0/3
A and B
A= $metaB= %$meta
ABresult
0X0
100
111
246 }
247 0 return;
248 }
249  
250 0 ▶sub _fetch_musicbrainz_by_id {
Subroutine _fetch_musicbrainz_by_id: not called CC=2 SCAR=17.9
251 0 my ($self, $mb_id) = @_;
252 0 my $url = "$MB_BASE/recording/$mb_id?fmt=json&inc=releases+artist-credits+tags+genres";
253 0 ▶ my $rec = $self->_get_mb($url) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $rec = $self->_get_mb($url) or return 0 0 0
254 0 return $self->_parse_mb_with_release($rec);
255 }
256  
257 0 ▶sub _parse_mb_with_release {
Subroutine _parse_mb_with_release: not called CC=10 SCAR=47.0
258 0 my ($self, $rec) = @_;
259 0 my %meta = %{ _parse_mb($rec) };
260  
261 # If we didn't get a genre from the recording, try the release-group level
262 0 ▶ if (!$meta{genre} && (my $rel = _best_mb_release($rec->{releases} // []))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $meta{"genre"} and my $rel = _best_mb_release($rec->{"releases"} // [])) 0 0 0
Condition0%0/5
not $meta{"genre"} and my $rel = _best_mb_release($rec->{"releases"} // [])
!ll&&!rl&&r
000
$rec->{"releases"} // []
l!l
00
MC/DC0%0/2
not $meta{"genre"} and my $rel = _best_mb_release($rec->{"releases"} // [])
not $meta{"genre"} my $rel = _best_mb_release($rec->{"releases"} // [])
MC/DC0%0/1
$rec->{"releases"} // []
$rec->{"releases"}
Truth table0%0/3
not(A) and B
A= not $meta{"genre"}B= my $rel = _best_mb_release($rec->{"releases"} // [])
ABresult
0X0
100
111
Truth table0%0/2
A
A= $rec->{"releases"}
Aresult
11
00
263 0 my $rg_url = "$MB_BASE/release/$rel->{id}?fmt=json&inc=release-groups+genres+tags";
264 0 my $rd = $self->_get_mb($rg_url);
265 0 ▶ if ($rd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rd) 0 0 0
266 0 ▶ $meta{genre} //= _best_mb_genre($rd->{genres}, $rd->{tags});
Condition0%0/3
$meta{"genre"} //= _best_mb_genre($rd->{"genres"}, $rd->{"tags"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$meta{"genre"} //= _best_mb_genre($rd->{"genres"}, $rd->{"tags"})
$meta{"genre"} _best_mb_genre($rd->{"genres"}, $rd->{"tags"})
Truth table0%0/3
A //= B
A= $meta{"genre"}B= _best_mb_genre($rd->{"genres"}, $rd->{"tags"})
ABresult
1X1
011
000
267 0 ▶ if (!$meta{genre} && (my $rg = $rd->{'release-group'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $meta{"genre"} and my $rg = $rd->{"release-group"}) 0 0 0
Condition0%0/3
not $meta{"genre"} and my $rg = $rd->{"release-group"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $meta{"genre"} and my $rg = $rd->{"release-group"}
not $meta{"genre"} my $rg = $rd->{"release-group"}
Truth table0%0/3
not(A) and B
A= not $meta{"genre"}B= my $rg = $rd->{"release-group"}
ABresult
0X0
100
111
268 0 my $rg_full_url = "$MB_BASE/release-group/$rg->{id}?fmt=json&inc=genres+tags";
269 0 my $rgd = $self->_get_mb($rg_full_url);
270 0 ▶ $meta{genre} //= _best_mb_genre($rgd->{genres}, $rgd->{tags}) if $rgd;
Branch: 1 branch
BranchTrueFalseTotal
if $rgd 0 0 0
Condition0%0/3
$meta{"genre"} //= _best_mb_genre($rgd->{"genres"}, $rgd->{"tags"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$meta{"genre"} //= _best_mb_genre($rgd->{"genres"}, $rgd->{"tags"})
$meta{"genre"} _best_mb_genre($rgd->{"genres"}, $rgd->{"tags"})
Truth table0%0/3
A //= B
A= $meta{"genre"}B= _best_mb_genre($rgd->{"genres"}, $rgd->{"tags"})
ABresult
1X1
011
000
271 }
272 }
273 }
274 0 return \%meta;
275 }
276  
277 0 ▶sub _parse_mb {
Subroutine _parse_mb: not called CC=8 SCAR=42.8
278 0 my ($rec) = @_;
279 0 my %meta;
280 0 ▶ $meta{title} = $rec->{title} if $rec->{title};
Branch: 1 branch
BranchTrueFalseTotal
if $rec->{"title"} 0 0 0
281 0 ▶ if (my $credits = $rec->{'artist-credit'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $credits = $rec->{"artist-credit"}) 0 0 0
282 $meta{artist} = join(', ',
283 0 ▶ map { $_->{name} // $_->{artist}{name} // () }
Condition0%0/6
($_->{"name"} // $_->{"artist"}{"name"}) // ()
l!l&&r!l&&!r
000
$_->{"name"} // $_->{"artist"}{"name"}
l!l&&r!l&&!r
000
MC/DC0%0/3
($_->{"name"} // $_->{"artist"}{"name"}) // ()
$_->{"name"} $_->{"artist"}{"name"} ()
Truth table0%0/4
A // B // C
A= $_->{"name"}B= $_->{"artist"}{"name"}C= ()
ABCresult
1XX1
01X1
0011
0000
284 0 grep { ref $_ eq 'HASH' } @$credits
285 );
286 }
287 0 ▶ if (my $rel = _best_mb_release($rec->{releases} // [])) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rel = _best_mb_release($rec->{"releases"} // [])) 0 0 0
Condition0%0/2
$rec->{"releases"} // []
l!l
00
MC/DC0%0/1
$rec->{"releases"} // []
$rec->{"releases"}
Truth table0%0/2
A
A= $rec->{"releases"}
Aresult
11
00
288 0 $meta{album} = $rel->{title};
289 0 ▶ ($meta{year}) = ($rel->{date} // '') =~ /^(\d{4})/;
Condition0%0/2
$rel->{"date"} // ""
l!l
00
MC/DC0%0/1
$rel->{"date"} // ""
$rel->{"date"}
Truth table0%0/2
A
A= $rel->{"date"}
Aresult
11
00
290 }
291 0 $meta{genre} = _best_mb_genre($rec->{genres}, $rec->{tags});
292 0 return \%meta;
293 }
294  
295 # Prefer MB's curated genres over folksonomy tags; pick the highest-count entry.
296 0 ▶sub _best_mb_genre {
Subroutine _best_mb_genre: not called CC=7 SCAR=40.3
297 0 my ($genres, $tags) = @_;
298 0 ▶ if ($genres && @$genres) {
Branch: 1 branch
BranchTrueFalseTotal
if ($genres and @$genres) 0 0 0
Condition0%0/3
$genres and @$genres
!ll&&!rl&&r
000
MC/DC0%0/2
$genres and @$genres
$genres @$genres
Truth table0%0/3
A and B
A= $genresB= @$genres
ABresult
0X0
100
111
299 0 my ($top) = sort { $b->{count} <=> $a->{count} } @$genres;
300 0 ▶ return ucfirst($top->{name}) if $top;
Branch: 1 branch
BranchTrueFalseTotal
if $top 0 0 0
301 }
302 0 ▶ if ($tags && @$tags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tags and @$tags) 0 0 0
Condition0%0/3
$tags and @$tags
!ll&&!rl&&r
000
MC/DC0%0/2
$tags and @$tags
$tags @$tags
Truth table0%0/3
A and B
A= $tagsB= @$tags
ABresult
0X0
100
111
303 0 my ($top) = sort { $b->{count} <=> $a->{count} } @$tags;
304 0 ▶ return ucfirst($top->{name}) if $top;
Branch: 1 branch
BranchTrueFalseTotal
if $top 0 0 0
305 }
306 0 return;
307 }
308  
309 0 ▶sub _best_mb_release {
Subroutine _best_mb_release: not called CC=3 SCAR=24.8
310 0 my ($releases) = @_;
311 0 ▶ return unless @$releases;
Branch: 1 branch
BranchTrueFalseTotal
unless @$releases 0 0 0
312 0 my @dated = grep { $_->{date} } @$releases;
313 0 ▶ return @dated ? $dated[0] : $releases->[0];
Branch: 1 branch
BranchTrueFalseTotal
@dated ? : 0 0 0
314 }
315  
316 0 ▶sub _mb_q {
Subroutine _mb_q: not called CC=1 SCAR=6.9
317 0 my ($s) = @_;
318 0 $s =~ s/["\\+\-&|!(){}\[\]^~*?:\/]/\\$&/g;
319 0 return $s;
320 }
321  
322 # ------------------------------------------------------------------
323 # AcoustID
324 # ------------------------------------------------------------------
325  
326 0 ▶sub fpcalc_available {
Subroutine fpcalc_available: not called CC=2 SCAR=17.9
Pod undocumented
327 0 ▶ return -x '/usr/bin/fpcalc' || -x '/usr/local/bin/fpcalc';
Condition0%0/3
-x '/usr/bin/fpcalc' || -x '/usr/local/bin/fpcalc'
l!l&&r!l&&!r
000
MC/DC0%0/2
-x '/usr/bin/fpcalc' || -x '/usr/local/bin/fpcalc'
-x '/usr/bin/fpcalc' -x '/usr/local/bin/fpcalc'
Truth table0%0/3
A || B
A= -x '/usr/bin/fpcalc'B= -x '/usr/local/bin/fpcalc'
ABresult
1X1
011
000
328 }
329  
330 0 ▶sub ffprobe_available {
Subroutine ffprobe_available: not called CC=2 SCAR=17.9
Pod undocumented
331 0 ▶ return -x '/usr/bin/ffprobe' || -x '/usr/local/bin/ffprobe';
Condition0%0/3
-x '/usr/bin/ffprobe' || -x '/usr/local/bin/ffprobe'
l!l&&r!l&&!r
000
MC/DC0%0/2
-x '/usr/bin/ffprobe' || -x '/usr/local/bin/ffprobe'
-x '/usr/bin/ffprobe' -x '/usr/local/bin/ffprobe'
Truth table0%0/3
A || B
A= -x '/usr/bin/ffprobe'B= -x '/usr/local/bin/ffprobe'
ABresult
1X1
011
000
332 }
333  
334 0 ▶sub flac_available {
Subroutine flac_available: not called CC=2 SCAR=17.9
Pod undocumented
335 0 ▶ return eval { require Audio::FLAC::Header; 1 } // 0;
Condition0%0/2
eval { do { require Audio::FLAC::Header; 1 } } // 0
l!l
00
MC/DC0%0/1
eval { do { require Audio::FLAC::Header; 1 } } // 0
eval { do { require Audio::FLAC::Header; 1 } }
Truth table0%0/2
A
A= eval { do { require Audio::FLAC::Header; 1 } }
Aresult
11
00
336 }
337  
338 # Read embedded Vorbis Comment tags + duration from a FLAC file on Drive.
339 # Downloads only the first 512 KB (enough for any FLAC header).
340 # Returns a hashref of metadata fields, or undef on failure/no tags.
341 0 ▶sub read_embedded_tags {
Subroutine read_embedded_tags: not called CC=19 SCAR=59.4
Pod undocumented
342 0 my ($self, $drive_id) = @_;
343 0 ▶ return unless flac_available();
Branch: 1 branch
BranchTrueFalseTotal
unless flac_available() 0 0 0
344  
345 0 my $tmpfile = $self->_download_partial($drive_id, 512 * 1024);
346 0 ▶ return unless $tmpfile;
Branch: 1 branch
BranchTrueFalseTotal
unless $tmpfile 0 0 0
347  
348 0 my $flac = eval { Audio::FLAC::Header->new($tmpfile) };
349 0 unlink $tmpfile;
350 0 ▶ return unless $flac;
Branch: 1 branch
BranchTrueFalseTotal
unless $flac 0 0 0
351  
352 0 ▶ my $raw = $flac->tags() // {};
Condition0%0/2
$flac->tags // {}
l!l
00
MC/DC0%0/1
$flac->tags // {}
$flac->tags
Truth table0%0/2
A
A= $flac->tags
Aresult
11
00
353 0 my %tags = map { lc($_) => $raw->{$_} } keys %$raw;
354  
355 0 my %meta;
356 0 ▶ $meta{title} = $tags{title} if $tags{title};
Branch: 1 branch
BranchTrueFalseTotal
if $tags{"title"} 0 0 0
357 0 ▶ $meta{artist} = $tags{artist} if $tags{artist};
Branch: 1 branch
BranchTrueFalseTotal
if $tags{"artist"} 0 0 0
358 0 ▶ $meta{album} = $tags{album} if $tags{album};
Branch: 1 branch
BranchTrueFalseTotal
if $tags{"album"} 0 0 0
359 0 ▶ $meta{genre} = $tags{genre} if $tags{genre};
Branch: 1 branch
BranchTrueFalseTotal
if $tags{"genre"} 0 0 0
360 0 ▶ $meta{comment} = $tags{comment} if $tags{comment};
Branch: 1 branch
BranchTrueFalseTotal
if $tags{"comment"} 0 0 0
361 0 ▶ if ($tags{tracknumber} && $tags{tracknumber} =~ /^(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tags{"tracknumber"} and $tags{"tracknumber"} =~ /^(\d+)/) 0 0 0
Condition0%0/3
$tags{"tracknumber"} and $tags{"tracknumber"} =~ /^(\d+)/
!ll&&!rl&&r
000
MC/DC0%0/2
$tags{"tracknumber"} and $tags{"tracknumber"} =~ /^(\d+)/
$tags{"tracknumber"} $tags{"tracknumber"} =~ /^(\d+)/
Truth table0%0/3
A and B
A= $tags{"tracknumber"}B= $tags{"tracknumber"} =~ /^(\d+)/
ABresult
0X0
100
111
362 0 $meta{track_number} = $1 + 0;
363 }
364 0 ▶ if ($tags{date} && $tags{date} =~ /^(\d{4})/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tags{"date"} and $tags{"date"} =~ /^(\d{4})/) 0 0 0
Condition0%0/3
$tags{"date"} and $tags{"date"} =~ /^(\d{4})/
!ll&&!rl&&r
000
MC/DC0%0/2
$tags{"date"} and $tags{"date"} =~ /^(\d{4})/
$tags{"date"} $tags{"date"} =~ /^(\d{4})/
Truth table0%0/3
A and B
A= $tags{"date"}B= $tags{"date"} =~ /^(\d{4})/
ABresult
0X0
100
111
365 0 $meta{year} = $1 + 0;
366 }
367  
368 # Duration from FLAC stream info block
369 0 my $info = $flac->info();
370 0 ▶ if ($info && $info->{TOTALSAMPLES} && $info->{SAMPLERATE}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($info and $info->{'TOTALSAMPLES'} and $info->{'SAMPLERATE'}) { } 0 0 0
elsif ($flac->{'trackTotalLengthSeconds'}) { } 0 0 0
Condition0%0/6
$info and $info->{"TOTALSAMPLES"} and $info->{"SAMPLERATE"}
!ll&&!rl&&r
000
$info and $info->{"TOTALSAMPLES"}
!ll&&!rl&&r
000
MC/DC0%0/3
$info and $info->{"TOTALSAMPLES"} and $info->{"SAMPLERATE"}
$info $info->{"TOTALSAMPLES"} $info->{"SAMPLERATE"}
Truth table0%0/4
A and B and C
A= $infoB= $info->{"TOTALSAMPLES"}C= $info->{"SAMPLERATE"}
ABCresult
0XX0
10X0
1100
1111
371 0 $meta{duration_ms} = int($info->{TOTALSAMPLES} / $info->{SAMPLERATE} * 1000);
372 } elsif ($flac->{trackTotalLengthSeconds}) {
373 0 $meta{duration_ms} = int($flac->{trackTotalLengthSeconds} * 1000);
374 }
375  
376 0 ▶ return %meta ? \%meta : undef;
Branch: 1 branch
BranchTrueFalseTotal
%meta ? : 0 0 0
377 }
378  
379 # Probe a Drive file for duration (milliseconds) using ffprobe.
380 # Returns undef if ffprobe is unavailable or the probe fails.
381 0 ▶sub probe_duration_ms {
Subroutine probe_duration_ms: not called CC=5 SCAR=34.0
Pod undocumented
382 0 my ($class, $drive_id, $token) = @_;
383 0 ▶ return unless ffprobe_available();
Branch: 1 branch
BranchTrueFalseTotal
unless ffprobe_available() 0 0 0
384  
385 0 ▶ my $ffprobe = -x '/usr/bin/ffprobe' ? '/usr/bin/ffprobe' : 'ffprobe';
Branch: 1 branch
BranchTrueFalseTotal
-x '/usr/bin/ffprobe' ? : 0 0 0
386 0 my $url = sprintf($DRIVE_URL, $drive_id);
387 0 my $header = "Authorization: $token\r\n";
388  
389 0 my $out = q{};
390 0 my $pid = open(my $fh, '-|', $ffprobe,
391 '-v', 'error',
392 '-headers', $header,
393 '-show_entries', 'format=duration',
394 '-of', 'default=noprint_wrappers=1:nokey=1',
395 $url,
396 );
397 0 ▶ if ($pid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) 0 0 0
398 0 $out = do { local $/; <$fh> };
399 0 close $fh;
400 }
401 0 ▶ return unless $out =~ /^(\d+(?:\.\d+)?)/m;
Branch: 1 branch
BranchTrueFalseTotal
unless $out =~ /^(\d+(?:\.\d+)?)/m 0 0 0
402 0 return int($1 * 1000);
403 }
404  
405 0 ▶sub _download_partial {
Subroutine _download_partial: not called CC=8 SCAR=42.8
406 0 my ($self, $drive_id, $max_bytes) = @_;
407 0 my $token = $self->token_fn->();
408 0 ▶ unless ($token) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token) 0 0 0
409 0 ▶ $log->warn("Fingerprint: no bearer token available") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
410 0 return;
411 }
412  
413 0 my $url = sprintf $DRIVE_URL, uri_escape_utf8($drive_id);
414 0 ▶ my $max = ($max_bytes // ($DOWNLOAD_MB * 1024 * 1024)) - 1;
Condition0%0/2
$max_bytes // $DOWNLOAD_MB * 1024 * 1024
l!l
00
MC/DC0%0/1
$max_bytes // $DOWNLOAD_MB * 1024 * 1024
$max_bytes
Truth table0%0/2
A
A= $max_bytes
Aresult
11
00
415 0 my $ua = HTTP::Tiny->new(agent => $USER_AGENT, timeout => 30);
416 0 my ($fh, $tmpfile) = tempfile(SUFFIX => '.audio', UNLINK => 0);
417 0 binmode $fh;
418  
419 my $res = $ua->request('GET', $url, {
420 headers => {
421 Authorization => $token,
422 Range => "bytes=0-$max",
423 },
424 0 ▶ data_callback => sub { print {$fh} $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
425 0 });
426 0 close $fh;
427  
428 0 ▶ if ($res->{success} || $res->{status} == 206) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"success"} or $res->{"status"} == 206) 0 0 0
Condition0%0/3
$res->{"success"} or $res->{"status"} == 206
l!l&&r!l&&!r
000
MC/DC0%0/2
$res->{"success"} or $res->{"status"} == 206
$res->{"success"} $res->{"status"} == 206
Truth table0%0/3
A or B
A= $res->{"success"}B= $res->{"status"} == 206
ABresult
1X1
011
000
429 0 ▶ $log->debug("Fingerprint: downloaded " . (-s $tmpfile) . " bytes for drive_id=$drive_id") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
430 0 return $tmpfile;
431 }
432  
433 0 ▶ $log->warn("Fingerprint: HTTP $res->{status} downloading drive_id=$drive_id: $res->{reason}") if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
434 0 unlink $tmpfile;
435 0 return;
436 }
437  
438 0 ▶sub _fingerprint {
Subroutine _fingerprint: not called CC=6 SCAR=37.4
439 0 my ($tmpfile) = @_;
440 0 ▶ my $fpcalc = -x '/usr/bin/fpcalc' ? '/usr/bin/fpcalc' : 'fpcalc';
Branch: 1 branch
BranchTrueFalseTotal
-x '/usr/bin/fpcalc' ? : 0 0 0
441 0 my $json = qx($fpcalc -json -length 120 \Q$tmpfile\E 2>/dev/null);
442 0 ▶ return unless $json;
Branch: 1 branch
BranchTrueFalseTotal
unless $json 0 0 0
443 0 ▶ my $data = eval { decode_json($json) } or return;
Branch: 1 branch
BranchTrueFalseTotal
my $data = eval { do { decode_json($json) } } or return 0 0 0
444 0 ▶ return unless $data->{fingerprint} && $data->{duration};
Branch: 1 branch
BranchTrueFalseTotal
unless $data->{"fingerprint"} and $data->{"duration"} 0 0 0
Condition0%0/3
$data->{"fingerprint"} and $data->{"duration"}
!ll&&!rl&&r
000
MC/DC0%0/2
$data->{"fingerprint"} and $data->{"duration"}
$data->{"fingerprint"} $data->{"duration"}
Truth table0%0/3
A and B
A= $data->{"fingerprint"}B= $data->{"duration"}
ABresult
0X0
100
111
445 0 return { fingerprint => $data->{fingerprint}, duration => int($data->{duration}) };
446 }
447  
448 0 ▶sub _query_acoustid {
Subroutine _query_acoustid: not called CC=8 SCAR=42.8
449 0 my ($self, $fp) = @_;
450 my $url = $AID_BASE
451 . '?client=' . uri_escape_utf8($self->acoustid_key)
452 . '&meta=recordings+compress'
453 . '&duration=' . $fp->{duration}
454 0 . '&fingerprint=' . uri_escape_utf8($fp->{fingerprint});
455  
456 0 ▶ my $data = $self->_get_plain($url) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $data = $self->_get_plain($url) or return 0 0 0
457 0 ▶ my $results = $data->{results} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $results = $data->{"results"} or return 0 0 0
458 0 ▶ return unless @$results;
Branch: 1 branch
BranchTrueFalseTotal
unless @$results 0 0 0
459  
460 # Pick the result with the highest score
461 0 my ($best) = sort { $b->{score} <=> $a->{score} } @$results;
462 0 ▶ return unless $best->{score} && $best->{score} > 0.5;
Branch: 1 branch
BranchTrueFalseTotal
unless $best->{"score"} and $best->{"score"} > "0.5" 0 0 0
Condition0%0/3
$best->{"score"} and $best->{"score"} > "0.5"
!ll&&!rl&&r
000
MC/DC0%0/2
$best->{"score"} and $best->{"score"} > "0.5"
$best->{"score"} $best->{"score"} > "0.5"
Truth table0%0/3
A and B
A= $best->{"score"}B= $best->{"score"} > "0.5"
ABresult
0X0
100
111
463  
464 0 ▶ my $recordings = $best->{recordings} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $recordings = $best->{"recordings"} or return 0 0 0
465 0 ▶ return unless @$recordings;
Branch: 1 branch
BranchTrueFalseTotal
unless @$recordings 0 0 0
466 0 return $recordings->[0]{id};
467 }
468  
469 # ------------------------------------------------------------------
470 # HTTP helpers
471 # ------------------------------------------------------------------
472  
473 0 ▶sub _get_plain {
Subroutine _get_plain: not called CC=2 SCAR=17.9
474 0 my ($self, $url) = @_;
475 0 my $ua = HTTP::Tiny->new(agent => $USER_AGENT, timeout => 5);
476 0 my $res = $ua->get($url);
477 0 ▶ return unless $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 0 0
478 0 return eval { decode_json($res->{content}) };
479 }
480  
481 0 ▶sub _get_mb {
Subroutine _get_mb: not called CC=2 SCAR=17.9
482 0 my ($self, $url) = @_;
483 0 my $gap = $MB_MIN_GAP - (time() - $last_mb_req);
484 0 ▶ $self->_yield_sleep($gap) if $gap > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $gap > 0 0 0 0
485 0 $last_mb_req = time();
486 0 return $self->_get_plain($url);
487 }
488  
489 0 ▶sub _yield_sleep {
Subroutine _yield_sleep: not called CC=3 SCAR=24.8
490 0 my ($self, $secs) = @_;
491 0 my $yield = $self->yield;
492 0 ▶ if ($yield) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yield) { } 0 0 0
493 0 my $end = time() + $secs;
494 0 ▶ while (time() < $end) {
Branch: 1 branch
BranchTrueFalseTotal
if (&App::DrivePlayer::MetadataFetcher::time() < $end) 0 0 0
495 0 $yield->();
496 0 usleep(50_000);
497 }
498 } else {
499 0 sleep($secs);
500 }
501 }
502  
503 1 1;
504  
505 __END__
« lib/App/DrivePlayer/SheetDB.pm ↑ Summary blib/lib/App/DrivePlayer/GUI.pm »