Add playlist functions

This commit is contained in:
mschuepbach
2024-03-24 23:34:26 +01:00
parent fe4a7dc49e
commit e3a184aa63
7 changed files with 784 additions and 28 deletions

View File

@@ -41,8 +41,9 @@ sub initialize_context {
}
sub get_visitor_id {
my ($content) = @_;
my @matches = $content =~ /ytcfg\.set\s*\(\s*({.+?})\s*\)\s*;/g;
my ($response) = @_;
my @matches =
$response->decoded_content =~ /ytcfg\.set\s*\(\s*({.+?})\s*\)\s*;/g;
my $visitor_id = "";
if (@matches) {
@@ -89,11 +90,15 @@ sub to_int {
sub sum_total_duration {
my ($item) = @_;
return 0 unless exists $item->{tracks};
return 0 unless exists $item->{"tracks"};
my $total_duration =
sum( map { exists $_->{duration_seconds} ? $_->{duration_seconds} : 0 }
@{ $item->{tracks} } );
my $total_duration = 0;
foreach my $track ( @{ $item->{"tracks"} } ) {
$total_duration +=
exists $track->{"duration_seconds"}
? $track->{"duration_seconds"}
: 0;
}
return $total_duration;
}