philippe44 / LMS-YouTube

Play YouTube videos on LMS
38 stars 15 forks source link

strip whitespaces at the beginning/end of "YouTube API Access Key." #15

Closed freddyb closed 4 years ago

freddyb commented 4 years ago

First of all, thank you for working on this plugin. It's super useful :-)

I see connection failures in my server log and it seems as if the API key contains whitespaces that would ideally be stripped by the plugin. Looking back at the plugin settings it actually looks as though I did not even enter whitespace in the first place - which is slightly odd.

Anyhow, I am wondering if it would make sense to strip the api either when receiving it from the input form or in line 153 where the error shows up (see below).

[17-09-02 14:01:03.0733] Slim::Utils::Misc::msg (1244) Warning: [14:01:03.0726] (
  bless([
    sub { "???" },
    sub { "???" },
    { params => {}, timeout => 15 },
    "GET",
    "https://www.googleapis.com/youtube/v3/videos?key= XY-REPLACING-THE-ACTUAL-KEY84 &id=xd-replaced-id-as-well--foo&maxResults=50&part=snippet%2CcontentDetails&regionCode=DE",
    "Connect timed out: ",
    undef,
    undef,
    undef,
    undef,
    undef,
    undef,
  ], "Slim::Networking::SimpleAsyncHTTP"),
  "Connect timed out: ",
) at /var/lib/squeezeboxserver/cache/InstalledPlugins/Plugins/YouTube/API.pm line 153.
[17-09-02 14:01:03.0741] Plugins::YouTube::API::__ANON__ (154) Connect timed out: 
philippe44 commented 4 years ago

The spaces are normally already stripped

freddyb commented 4 years ago

Do you think this could be a problem with the logging then? The warning comes from Slim::Utils::Misc::msg, not from the Plugin directly, right? Would be odd that it gets an incorrect URL though.

Anything I could do to help figure this out? Any ideas?

balamakka commented 4 years ago

I looked at the youtube.prefs file. It did indeed have a space character in front of the key. I edited the file, removed the space, restarted the server, and the problem was gone.

philippe44 commented 4 years ago

You're correct. I was trimming the spaces of the APIKey, but I forgot to add the prefix to the pre-defined prefs variables in the Settings framework, so I was trimming nothing