From c77a0022310c47270c9c262616ededbeca592ee8 Mon Sep 17 00:00:00 2001 From: raduburla Date: Fri, 10 Dec 2021 07:32:46 +0000 Subject: [PATCH 1/2] Update plexWatch.pl fix Unescaped left brace in regex is illegal here in regex error and update plex auth url --- plexWatch.pl | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/plexWatch.pl b/plexWatch.pl index 5dbfd78..7c9beb9 100755 --- a/plexWatch.pl +++ b/plexWatch.pl @@ -753,16 +753,16 @@ () } } - $format =~ s/{{($regex)}}/$info->{$1}/g; ## regex replace variables + $format =~ s/\{\{($regex)\}\}/$info->{$1}/g; ## regex replace variables $format =~ s/\[\]//g; ## trim any empty variable encapsulated in [] $format =~ s/\s+/ /g; ## remove double spaces $format =~ s/\\n/\n/g; ## allow \n to be an actual new line - $format =~ s/{{newline}}/\n/g; ## allow \n to be an actual new line + $format =~ s/\{\{newline\}\}/\n/g; ## allow \n to be an actual new line ## special for now.. might make this more useful -- just thrown together since email can include a ton of info - if ($format =~ /{{all_details}}/i) { - $format =~ s/\s*{{all_details}}\s*//i; + if ($format =~ /\{\{all_details\}\}/i) { + $format =~ s/\s*\{\{all_details\}\}\s*//i; $format .= sprintf("\n\n%10s %s\n","","-----All Details-----"); my $f_extra; foreach my $key (keys %{$info} ) { @@ -3790,7 +3790,7 @@ () $ua->default_header('X-Plex-Client-Identifier' => $appname); $ua->default_header('Content-Length' => 0); - my $url = 'https://my.plexapp.com/users/sign_in.xml'; + my $url = 'https://plex.tv/users/sign_in.json'; my $req = HTTP::Request->new(POST => $url); $req->authorization_basic($myPlex_user, $myPlex_pass); @@ -3800,15 +3800,21 @@ () if ($response->is_success) { my $content = $response->decoded_content(); + #print $content; if ($debug_xml) { print "URL: $url\n"; print "===================================XML CUT=================================================\n"; print $content; print "===================================XML END=================================================\n"; } - my $data = XMLin(encode('utf8',$content)); - return $data->{'authenticationToken'} if $data->{'authenticationToken'}; - return $data->{'authentication-token'} if $data->{'authentication-token'}; + + my $json = JSON->new->allow_nonref + ->utf8->relaxed; + my $data = $json->decode( $content ); + + return $data->{user}->{authToken} if $data->{user}->{authToken}; + return $data->{user}->{'authentication-token'} if $data->{user}->{'authentication-token'}; + } else { print $response->as_string; die; From dc30a97b9a020020a7dd59d6b77b3507ab6b9dc1 Mon Sep 17 00:00:00 2001 From: raduburla Date: Fri, 10 Dec 2021 07:41:49 +0000 Subject: [PATCH 2/2] cleanup --- plexWatch.pl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plexWatch.pl b/plexWatch.pl index 7c9beb9..0423d73 100755 --- a/plexWatch.pl +++ b/plexWatch.pl @@ -3800,7 +3800,7 @@ () if ($response->is_success) { my $content = $response->decoded_content(); - #print $content; + if ($debug_xml) { print "URL: $url\n"; print "===================================XML CUT=================================================\n"; @@ -3808,13 +3808,12 @@ () print "===================================XML END=================================================\n"; } - my $json = JSON->new->allow_nonref - ->utf8->relaxed; - my $data = $json->decode( $content ); - - return $data->{user}->{authToken} if $data->{user}->{authToken}; - return $data->{user}->{'authentication-token'} if $data->{user}->{'authentication-token'}; + my $json = JSON->new->allow_nonref + ->utf8->relaxed; + my $data = $json->decode( $content ); + return $data->{user}->{authToken} if $data->{user}->{authToken}; + return $data->{user}->{'authentication-token'} if $data->{user}->{'authentication-token'}; } else { print $response->as_string; die;