This commit is contained in:
@@ -2,7 +2,7 @@ package Plugins::YouTubeMusic::Plugin;
|
||||
|
||||
use strict;
|
||||
|
||||
use base qw(Slim::Plugin::Base);
|
||||
use base qw(Slim::Plugin::OPMLBased);
|
||||
|
||||
use Slim::Utils::Strings qw(string);
|
||||
use Slim::Utils::Prefs;
|
||||
@@ -25,9 +25,10 @@ $prefs->init({
|
||||
sub initPlugin {
|
||||
my $class = shift;
|
||||
|
||||
$class->SUPER::initPlugin;
|
||||
|
||||
$log->info("Hello, World!");
|
||||
$class->SUPER::initPlugin(
|
||||
feed => \&mainMenu,
|
||||
is_app => 1
|
||||
);
|
||||
|
||||
if (main::WEBUI) {
|
||||
require Plugins::YouTubeMusic::Settings;
|
||||
@@ -41,5 +42,60 @@ sub shutdownPlugin {
|
||||
|
||||
sub getDisplayName { 'PLUGIN_YOUTUBEMUSIC' }
|
||||
|
||||
sub mainMenu {
|
||||
my ($client, $callback, $args) = @_;
|
||||
|
||||
$callback->([
|
||||
{ name => cstring($client, 'PLUGIN_YOUTUBEMUSIC_MYPLAYLISTS'), type => 'url', url => \&myPlaylistHandler, passthrough => [ { count => 2 } ] },
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
sub myPlaylistHandler {
|
||||
my ($client, $cb, $args, $params) = @_;
|
||||
|
||||
if (!$cache->get('yt:access_token')) {
|
||||
Plugins::YouTubeMusic::OAuth2::getToken(\&myPlaylistHandler, @_);
|
||||
return;
|
||||
}
|
||||
|
||||
my $account = {
|
||||
_cache_ttl => 60,
|
||||
_noKey => 1,
|
||||
mine => 'true',
|
||||
access_token => $cache->get('yt:access_token'),
|
||||
};
|
||||
|
||||
Plugins::YouTubeMusic::API->searchDirect('playlists', sub {
|
||||
$cb->(_renderList($_[0], 'title', $account));
|
||||
}, {
|
||||
%$account,
|
||||
_index => $args->{index},
|
||||
_quantity => $args->{quantity},
|
||||
});
|
||||
}
|
||||
|
||||
sub _renderList {
|
||||
my ($list, $sort, $passthrough, $tags) = @_;
|
||||
my $sortedList = $list->{items};
|
||||
my @items;
|
||||
|
||||
for my $entry (@$sortedList) {
|
||||
my $snippet = $entry->{snippet} || next;
|
||||
my $title = $snippet->{title} || next;
|
||||
|
||||
my $item = {
|
||||
name => $title,
|
||||
type => 'playlist',
|
||||
};
|
||||
|
||||
push @items, $item;
|
||||
}
|
||||
|
||||
$list->{items} = \@items;
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user