x-out spotify username and password

This commit is contained in:
badaix 2017-10-07 10:33:10 +02:00
parent baf5a7af3b
commit a490402721
3 changed files with 42 additions and 2 deletions

View file

@ -51,6 +51,11 @@ SpotifyStream::SpotifyStream(PcmListener* pcmListener, const StreamUri& uri) : P
params_ += " --onstart \"" + onstart + "\""; params_ += " --onstart \"" + onstart + "\"";
if (!onstop.empty()) if (!onstop.empty())
params_ += " --onstop \"" + onstop + "\""; params_ += " --onstop \"" + onstop + "\"";
if (uri_.query.find("username") != uri_.query.end())
uri_.query["username"] = "xxx";
if (uri_.query.find("password") != uri_.query.end())
uri_.query["password"] = "xxx";
// LOG(INFO) << "params: " << params << "\n"; // LOG(INFO) << "params: " << params << "\n";
} }

View file

@ -26,7 +26,14 @@ using namespace std;
namespace strutils = utils::string; namespace strutils = utils::string;
StreamUri::StreamUri(const std::string& streamUri) StreamUri::StreamUri(const std::string& uri)
{
parse(uri);
}
void StreamUri::parse(const std::string& streamUri)
{ {
// https://en.wikipedia.org/wiki/Uniform_Resource_Identifier // https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
// scheme:[//[user:password@]host[:port]][/]path[?query][#fragment] // scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
@ -92,13 +99,38 @@ StreamUri::StreamUri(const std::string& streamUri)
query[key] = value; query[key] = value;
} }
} }
LOG(DEBUG) << "StreamUri.toString: " << toString() << "\n";
}
std::string StreamUri::toString() const
{
// scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
stringstream ss;
ss << scheme << "://" << host << "/" + path;
if (!query.empty())
{
ss << "?";
auto iter = query.begin();
while (true)
{
ss << iter->first << "=" << iter->second;
if (++iter == query.end())
break;
ss << "&";
}
}
if (!fragment.empty())
ss << "#" << fragment;
return ss.str();
} }
json StreamUri::toJson() const json StreamUri::toJson() const
{ {
json j = { json j = {
{"raw", uri}, {"raw", toString()},
{"scheme", scheme}, {"scheme", scheme},
{"host", host}, {"host", host},
{"path", path}, {"path", path},

View file

@ -49,6 +49,9 @@ struct StreamUri
std::string id() const; std::string id() const;
json toJson() const; json toJson() const;
std::string getQuery(const std::string& key, const std::string& def = "") const; std::string getQuery(const std::string& key, const std::string& def = "") const;
void parse(const std::string& streamUri);
std::string toString() const;
}; };