From fce061b5447a9c2c4b5e5ac1dad4284beee66560 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 26 Jan 2018 16:59:09 +0100 Subject: [PATCH] input/tidal: move code to ExtractTidalTrackId() --- src/input/plugins/TidalInputPlugin.cxx | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/input/plugins/TidalInputPlugin.cxx b/src/input/plugins/TidalInputPlugin.cxx index 547b501c6..3079288e5 100644 --- a/src/input/plugins/TidalInputPlugin.cxx +++ b/src/input/plugins/TidalInputPlugin.cxx @@ -190,18 +190,30 @@ FinishTidalInput() delete tidal_session; } +gcc_pure +static const char * +ExtractTidalTrackId(const char *uri) +{ + const char *track_id = StringAfterPrefix(uri, "tidal://track/"); + if (track_id == nullptr) { + track_id = StringAfterPrefix(uri, "https://listen.tidal.com/track/"); + if (track_id == nullptr) + return nullptr; + } + + if (*track_id == 0) + return nullptr; + + return track_id; +} + static InputStreamPtr OpenTidalInput(const char *uri, Mutex &mutex, Cond &cond) { assert(tidal_session != nullptr); - const char *track_id; - - track_id = StringAfterPrefix(uri, "tidal://track/"); + const char *track_id = ExtractTidalTrackId(uri); if (track_id == nullptr) - track_id = StringAfterPrefix(uri, "https://listen.tidal.com/track/"); - - if (track_id == nullptr || *track_id == 0) return nullptr; // TODO: validate track_id