diff --git a/YouTubeMusic/HTML/EN/plugins/YouTubeMusic/settings/basic.html b/YouTubeMusic/HTML/EN/plugins/YouTubeMusic/settings/basic.html
index 602ca46..e94d96e 100644
--- a/YouTubeMusic/HTML/EN/plugins/YouTubeMusic/settings/basic.html
+++ b/YouTubeMusic/HTML/EN/plugins/YouTubeMusic/settings/basic.html
@@ -6,4 +6,12 @@
[% END %]
+ [% WRAPPER setting title="PLUGIN_YOUTUBEMUSIC_AUTH" desc="PLUGIN_YOUTUBEMUSIC_AUTH_DESC" %]
+ [% "PLUGIN_YOUTUBEMUSIC_VERIFICATIONURL" | string %]
+
[% user_code %]
+ [% END %]
+ [% END %]
+
[% PROCESS settings/footer.html %]
diff --git a/YouTubeMusic/OAuth2.pm b/YouTubeMusic/OAuth2.pm
new file mode 100644
index 0000000..9cf1eb0
--- /dev/null
+++ b/YouTubeMusic/OAuth2.pm
@@ -0,0 +1,49 @@
+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;
diff --git a/YouTubeMusic/Settings.pm b/YouTubeMusic/Settings.pm
index 2ad6f6f..95f59f5 100644
--- a/YouTubeMusic/Settings.pm
+++ b/YouTubeMusic/Settings.pm
@@ -7,6 +7,7 @@ use Slim::Utils::Log;
use Slim::Utils::Prefs;
my $log = logger('plugin.youtubemusic');
+my $cache = Slim::Utils::Cache->new();
sub name {
return 'PLUGIN_YOUTUBEMUSIC';
@@ -27,6 +28,11 @@ sub handler {
preferences('plugin.youtubemusic')->set('testPref', $params->{'pref_testPref'});
}
+ Plugins::YouTubeMusic::OAuth2::getDeviceCode if $params->{get_device_code};
+
+ $params->{user_code} = $cache->get('yt:user_code');
+ $params->{verification_url} = $cache->get('yt:verification_url');
+
return $class->SUPER::handler($client, $params);
}
diff --git a/YouTubeMusic/strings.txt b/YouTubeMusic/strings.txt
index 0961717..79db065 100644
--- a/YouTubeMusic/strings.txt
+++ b/YouTubeMusic/strings.txt
@@ -10,3 +10,15 @@ PLUGIN_YOUTUBEMUSIC_TESTPREF
PLUGIN_YOUTUBEMUSIC_TESTPREF_DESC
EN This is a test.
+PLUGIN_YOUTUBEMUSIC_AUTH
+ EN Login with Google
+
+PLUGIN_YOUTUBEMUSIC_AUTH_DESC
+ EN You need to login with your Google account to use this plugin.
+
+PLUGIN_YOUTUBEMUSIC_START_AUTH
+ EN Start
+
+PLUGIN_YOUTUBEMUSIC_VERIFICATIONURL
+ EN Login
+