This commit is contained in:
@@ -11,34 +11,38 @@ use Slim::Utils::Cache;
|
||||
|
||||
use Plugins::YouTubeMusic::OAuth2;
|
||||
|
||||
my $log = Slim::Utils::Log->addLogCategory({
|
||||
'category' => 'plugin.youtubemusic',
|
||||
'defaultLevel' => 'WARN',
|
||||
'description' => 'PLUGIN_YOUTUBEMUSIC',
|
||||
});
|
||||
my $log = Slim::Utils::Log->addLogCategory(
|
||||
{
|
||||
'category' => 'plugin.youtubemusic',
|
||||
'defaultLevel' => 'WARN',
|
||||
'description' => 'PLUGIN_YOUTUBEMUSIC',
|
||||
}
|
||||
);
|
||||
|
||||
my $prefs = preferences('plugin.youtubemusic');
|
||||
my $cache = Slim::Utils::Cache->new();
|
||||
|
||||
$prefs->init({
|
||||
testPref => 'test'
|
||||
});
|
||||
$prefs->init(
|
||||
{
|
||||
testPref => 'test'
|
||||
}
|
||||
);
|
||||
|
||||
sub initPlugin {
|
||||
my $class = shift;
|
||||
my $class = shift;
|
||||
|
||||
$class->SUPER::initPlugin(
|
||||
feed => \&mainMenu,
|
||||
tag => 'youtubemusic',
|
||||
menu => 'radios',
|
||||
is_app => 1,
|
||||
weight => 1,
|
||||
);
|
||||
$class->SUPER::initPlugin(
|
||||
feed => \&mainMenu,
|
||||
tag => 'youtubemusic',
|
||||
menu => 'radios',
|
||||
is_app => 1,
|
||||
weight => 1,
|
||||
);
|
||||
|
||||
if (main::WEBUI) {
|
||||
require Plugins::YouTubeMusic::Settings;
|
||||
Plugins::YouTubeMusic::Settings->new();
|
||||
}
|
||||
if (main::WEBUI) {
|
||||
require Plugins::YouTubeMusic::Settings;
|
||||
Plugins::YouTubeMusic::Settings->new();
|
||||
}
|
||||
}
|
||||
|
||||
sub shutdownPlugin {
|
||||
@@ -48,59 +52,68 @@ sub shutdownPlugin {
|
||||
sub getDisplayName { 'PLUGIN_YOUTUBEMUSIC' }
|
||||
|
||||
sub mainMenu {
|
||||
my ($client, $callback, $args) = @_;
|
||||
my ( $client, $callback, $args ) = @_;
|
||||
|
||||
$callback->([
|
||||
{ name => cstring($client, 'PLUGIN_YOUTUBEMUSIC_MYPLAYLISTS'), type => 'url', url => \&myPlaylistHandler, passthrough => [ { count => 2 } ] },
|
||||
]);
|
||||
$callback->(
|
||||
[
|
||||
{
|
||||
name => cstring( $client, 'PLUGIN_YOUTUBEMUSIC_MYPLAYLISTS' ),
|
||||
type => 'url',
|
||||
url => \&myPlaylistHandler,
|
||||
passthrough => [ { count => 2 } ]
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
sub myPlaylistHandler {
|
||||
my ($client, $cb, $args, $params) = @_;
|
||||
my ( $client, $cb, $args, $params ) = @_;
|
||||
|
||||
if (!$cache->get('yt:access_token')) {
|
||||
Plugins::YouTubeMusic::OAuth2::getToken(\&myPlaylistHandler, @_);
|
||||
return;
|
||||
}
|
||||
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'),
|
||||
};
|
||||
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},
|
||||
});
|
||||
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;
|
||||
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;
|
||||
for my $entry (@$sortedList) {
|
||||
my $snippet = $entry->{snippet} || next;
|
||||
my $title = $snippet->{title} || next;
|
||||
|
||||
my $item = {
|
||||
name => $title,
|
||||
type => 'playlist',
|
||||
};
|
||||
my $item = {
|
||||
name => $title,
|
||||
type => 'playlist',
|
||||
};
|
||||
|
||||
push @items, $item;
|
||||
}
|
||||
push @items, $item;
|
||||
}
|
||||
|
||||
$list->{items} = \@items;
|
||||
$list->{items} = \@items;
|
||||
|
||||
return $list;
|
||||
return $list;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user