Initial commit
This commit is contained in:
78
YTMusicAPI/Parsers/Parser.pm
Normal file
78
YTMusicAPI/Parsers/Parser.pm
Normal file
@@ -0,0 +1,78 @@
|
||||
package YTMusicAPI::Parsers::Parser;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use YTMusicAPI::Navigation;
|
||||
|
||||
sub new {
|
||||
my ( $class, $language ) = @_;
|
||||
|
||||
my $self = { lang => $language };
|
||||
|
||||
bless $self, $class;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub _ {
|
||||
my ($input) = @_;
|
||||
return $input;
|
||||
}
|
||||
|
||||
sub get_search_result_types {
|
||||
my ($self) = @_;
|
||||
|
||||
return [
|
||||
_("artist"), _("playlist"), _("song"), _("video"),
|
||||
_("station"), _("profile"), _("podcast"), _("episode"),
|
||||
];
|
||||
}
|
||||
|
||||
sub parse_channel_contents {
|
||||
my ( $self, $results ) = @_;
|
||||
|
||||
my @categories = (
|
||||
[ "albums", _("albums"), \&parse_album, $MTRIR ],
|
||||
[ "singles", _("singles"), \&parse_single, $MTRIR ],
|
||||
[ "shows", _("shows"), \&parse_album, $MTRIR ],
|
||||
[ "videos", _("videos"), \&parse_video, $MTRIR ],
|
||||
[ "playlists", _("playlists"), \&parse_playlist, $MTRIR ],
|
||||
[ "related", _("related"), \&parse_related_artist, $MTRIR ],
|
||||
[ "episodes", _("episodes"), \&parse_episode, $MMRIR ],
|
||||
[ "podcasts", _("podcasts"), \&parse_podcast, $MTRIR ],
|
||||
);
|
||||
|
||||
my %artist = {};
|
||||
foreach my $category_tuple (@categories) {
|
||||
my ( $category, $category_local, $category_parser, $category_key ) =
|
||||
@$category_tuple;
|
||||
my @data = map { $_->{"musicCarouselShelfRenderer"} }
|
||||
grep {
|
||||
exists $_->{"musicCarouselShelfRenderer"}
|
||||
&& nav( $_, $CAROUSEL . $CAROUSEL_TITLE )->{"text"} =~
|
||||
/^$category_local$/i
|
||||
} $results;
|
||||
|
||||
if ( scalar @data > 0 ) {
|
||||
$artist{$category} = { "browseId" => undef, "results" => [] };
|
||||
|
||||
if (
|
||||
exists nav( $data[0], $CAROUSEL_TITLE )->{"navigationEndpoint"}
|
||||
)
|
||||
{
|
||||
$artist{$category}->{"browseId"} =
|
||||
nav( $data[0], $CAROUSEL_TITLE . $NAVIGATION_BROWSE_ID );
|
||||
$artist{$category}->{"params"} = nav( $data[0],
|
||||
$CAROUSEL_TITLE . $NAVIGATION_BROWSE . ["params"], 1 );
|
||||
}
|
||||
$artist{$category}->{"results"} =
|
||||
parse_content_list( $data[0]->{"contents"},
|
||||
$category_parser, "key" => $category_key );
|
||||
}
|
||||
}
|
||||
|
||||
return %artist;
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user