50 lines
1.2 KiB
Perl
50 lines
1.2 KiB
Perl
package Plugins::YouTubeMusic::OAuth2;
|
|
|
|
use strict;
|
|
|
|
use Slim::Utils::Log;
|
|
use Slim::Utils::Cache;
|
|
use Slim::Utils::Strings qw(string cstring);
|
|
use JSON::XS::VersionOneAndTwo;
|
|
use Data::Dumper;
|
|
|
|
my $log = logger('plugin.youtubemusic');
|
|
my $cache = Slim::Utils::Cache->new();
|
|
|
|
sub getDeviceCode {
|
|
my $post = "client_id=861556708454-d6dlm3lh05idd8npek18k6be8ba3oc68.apps.googleusercontent.com" .
|
|
"&scope=https://www.googleapis.com/auth/youtube";
|
|
|
|
my $http = Slim::Networking::SimpleAsyncHTTP->new(
|
|
sub {
|
|
my $response = shift;
|
|
my $result = eval { from_json($response->content) };
|
|
|
|
if ($@) {
|
|
$log->error(Data::Dump::dump($response)) unless main::DEBUGLOG && $log->is_debug;
|
|
$log->error($@);
|
|
} else {
|
|
$cache->set("yt:device_code", $result->{device_code}, $result->{expires_in});
|
|
$cache->set("yt:verification_url", $result->{verification_url}, $result->{expires_in});
|
|
$cache->set("yt:user_code", $result->{user_code}, $result->{expires_in});
|
|
|
|
$log->debug("content:", $response->content);
|
|
}
|
|
},
|
|
sub {
|
|
$log->error($_[1]);
|
|
},
|
|
{
|
|
timeout => 15,
|
|
}
|
|
);
|
|
|
|
$http->post(
|
|
"https://www.youtube.com/o/oauth2/device/code",
|
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
|
$post,
|
|
);
|
|
}
|
|
|
|
1;
|