Skip to content

Commit

Permalink
fallback on invalid presentation map
Browse files Browse the repository at this point in the history
do not load default categories for tuneIn service
  • Loading branch information
janbar committed Jun 28, 2020
1 parent 7036ca9 commit 44ffb7d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion noson/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# set lib version here
set (noson_VERSION_MAJOR 2)
set (noson_VERSION_MINOR 3)
set (noson_VERSION_PATCH 1)
set (noson_VERSION_PATCH 2)

set (noson_VERSION ${noson_VERSION_MAJOR}.${noson_VERSION_MINOR}.${noson_VERSION_PATCH})
set (NOSON_LIB_VERSION ${noson_VERSION})
Expand Down
47 changes: 28 additions & 19 deletions noson/src/smapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,29 @@ bool SMAPI::Init(const SMServicePtr& smsvc, const std::string& locale)
default:
break;
}
if (!response->IsSuccessful())
if (response->IsSuccessful())
{
DBG(DBG_ERROR, "%s: invalid response\n", __FUNCTION__);
// receive content data
size_t len = 0, l = 0;
std::string data;
char buffer[4096];
while ((l = response->ReadContent(buffer, sizeof(buffer))))
{
data.append(buffer, l);
len += l;
}
delete response;
return false;
response = nullptr;
if (!parsePresentationMap(data))
return false;
}
// receive content data
size_t len = 0, l = 0;
std::string data;
char buffer[4096];
while ((l = response->ReadContent(buffer, sizeof(buffer))))
else
{
data.append(buffer, l);
len += l;
DBG(DBG_ERROR, "%s: the presentation map is invalid\n", __FUNCTION__);
delete response;
m_presentation.clear();
m_searchCategories.clear();
}
delete response;
response = nullptr;
if (!parsePresentationMap(data))
return false;
}

// see https://musicpartners.sonos.com/node/530
Expand All @@ -147,11 +151,15 @@ bool SMAPI::Init(const SMServicePtr& smsvc, const std::string& locale)
{
if (m_searchCategories.empty())
{
// add default search categories
m_searchCategories.push_back(ElementPtr(new Element("tracks", "track")));
m_searchCategories.push_back(ElementPtr(new Element("albums", "album")));
m_searchCategories.push_back(ElementPtr(new Element("artists", "artist")));
m_searchCategories.push_back(ElementPtr(new Element("playlists", "playlist")));
// don't load default categories for TuneIn because it won't work as expected
if (m_service->GetServiceType() != "65031") /* TuneIn */
{
// add default search categories
m_searchCategories.push_back(ElementPtr(new Element("tracks", "track")));
m_searchCategories.push_back(ElementPtr(new Element("albums", "album")));
m_searchCategories.push_back(ElementPtr(new Element("artists", "artist")));
m_searchCategories.push_back(ElementPtr(new Element("playlists", "playlist")));
}
}
}
else
Expand Down Expand Up @@ -621,6 +629,7 @@ ElementList SMAPI::DoCall(const std::string& action, const ElementList& args)

WSRequest request(*m_uri, HRM_POST);
request.SetUserAgent(m_service->GetAgent());
request.SetHeader("X-Sonos-SWGen", "1");
request.SetHeader("Accept-Language", m_language);
request.SetHeader("SOAPAction", soapaction);
request.SetContentCustom(CT_XML, content.c_str());
Expand Down

0 comments on commit 44ffb7d

Please sign in to comment.