commit 3bf31903f61730be8e80789173eaa9b9e807119f (patch) parent 84efc614a8d3243c04cf4bc7fb83d55cefb4e55a Author: Alex Karle <alex@alexkarle.com> Date: Tue, 4 Feb 2025 22:07:48 -0500 Fix broken track pagination Here I was being a good citizen and using their field filters and who would have thought it'd change the whole api shape?? Diffstat:
M | cli.pl | | | 13 | +++++++++---- |
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/cli.pl b/cli.pl @@ -68,8 +68,12 @@ EOM my $err = $res->decoded_content; die "Failed to fetch playlist: $err"; } + # NOTE: after paging, the shape changes.. my $j = decode_json($res->decoded_content); - foreach my $t (@{$j->{tracks}->{items}}) { + my $tracks = $url =~ /offset/ ? $j : $j->{tracks}; + my $n = scalar @{$tracks->{items}}; + print("$n Tracks\n"); + foreach my $t (@{$tracks->{items}}) { (my $d = $t->{added_at}) =~ s/T.*Z$//; my $fart = @{$t->{track}->{artists}}[0]->{name}; $s .= sprintf( @@ -78,11 +82,12 @@ EOM ); $i += 1; } - if (!$j->{tracks}->{next}) { + if (!$tracks->{next}) { last; } - print("Paging Tracks: $url\n"); - $url = $j->{tracks}->{next}; + # HACK: the fields filter breaks in the next URL, + # so we have to strip the tracks. prefix + ($url = $tracks->{next}) =~ s/tracks\.//g; } return $s; }