diff options
| -rw-r--r-- | libpiano/src/main.c | 32 | ||||
| -rw-r--r-- | libpiano/src/piano.h | 2 | ||||
| -rw-r--r-- | libpiano/src/xml.c | 22 | ||||
| -rw-r--r-- | libpiano/src/xml.h | 1 | ||||
| -rw-r--r-- | src/ui.c | 20 | ||||
| -rw-r--r-- | src/ui.h | 2 | ||||
| -rw-r--r-- | src/ui_act.c | 4 | 
7 files changed, 75 insertions, 8 deletions
| diff --git a/libpiano/src/main.c b/libpiano/src/main.c index b3bcab8..844d757 100644 --- a/libpiano/src/main.c +++ b/libpiano/src/main.c @@ -763,6 +763,38 @@ PianoReturn_t PianoExplain (PianoHandle_t *ph, const PianoSong_t *song,  	return ret;  } +/*	Get seed suggestions by music id + *	@param piano handle + *	@param music id + *	@param max results + *	@param result buffer + */ +PianoReturn_t PianoSeedSuggestions (PianoHandle_t *ph, const char *musicId, +		unsigned int max, PianoSearchResult_t *searchResult) { +	char xmlSendBuf[PIANO_SEND_BUFFER_SIZE], retStr[PIANO_RECV_BUFFER]; +	PianoReturn_t ret; + +	snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>" +			"<methodCall><methodName>music.getSeedSuggestions</methodName>" +			"<params><param><value><int>%li</int></value></param>" +			"<param><value><string>%s</string></value></param>" +			"<param><value><string>%s</string></value></param>" +			"<param><value><int>%u</int></value></param>" +			"</params></methodCall>", time (NULL), ph->user.authToken, +			musicId, max); +	 +	snprintf (ph->waith.path, sizeof (ph->waith.path), PIANO_RPC_PATH +			"rid=%s&lid=%s&method=method=getSeedSuggestions&arg1=%s&arg2=%u", +			ph->routeId, ph->user.listenerId, musicId, max); +	 +	if ((ret = PianoHttpPost (&ph->waith, xmlSendBuf, retStr, +			sizeof (retStr))) == PIANO_RET_OK) { +		ret = PianoXmlParseSeedSuggestions (retStr, searchResult); +	} + +	return ret; +} +  /*	convert return value to human-readable string   *	@param enum   *	@return error string diff --git a/libpiano/src/piano.h b/libpiano/src/piano.h index 2910e99..7d7554a 100644 --- a/libpiano/src/piano.h +++ b/libpiano/src/piano.h @@ -136,5 +136,7 @@ PianoReturn_t PianoGetGenreStations (PianoHandle_t *);  PianoReturn_t PianoTransformShared (PianoHandle_t *, PianoStation_t *);  PianoReturn_t PianoExplain (PianoHandle_t *, const PianoSong_t *, char **);  const char *PianoErrorToStr (PianoReturn_t); +PianoReturn_t PianoSeedSuggestions (PianoHandle_t *, const char *, +		unsigned int, PianoSearchResult_t *);  #endif /* _PIANO_H */ diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c index 2cc519f..b02df5d 100644 --- a/libpiano/src/xml.c +++ b/libpiano/src/xml.c @@ -647,6 +647,28 @@ PianoReturn_t PianoXmlParseSearch (char *xml,  	return PIANO_RET_OK;  } +/*	FIXME: copy&waste (PianoXmlParseSearch) + */ +PianoReturn_t PianoXmlParseSeedSuggestions (char *xml, +		PianoSearchResult_t *searchResult) { +	ezxml_t xmlDoc, dataNode; +	PianoReturn_t ret; + +	if ((ret = PianoXmlInitDoc (xml, &xmlDoc)) != PIANO_RET_OK) { +		return ret; +	} +	 +	dataNode = ezxml_get (xmlDoc, "params", 0, "param", 0, "value", -1); +	/* we need a "clean" search result (with null pointers) */ +	memset (searchResult, 0, sizeof (*searchResult)); +	/* reuse seach result parser; structure is nearly the same */ +	PianoXmlParseSearchCb ("artists", dataNode, searchResult); + +	ezxml_free (xmlDoc); + +	return PIANO_RET_OK; +} +  /*	encode reserved xml chars   *	TODO: remove and use ezxml_ampencode   *	@param encode this diff --git a/libpiano/src/xml.h b/libpiano/src/xml.h index 525c8f3..5c0e5c2 100644 --- a/libpiano/src/xml.h +++ b/libpiano/src/xml.h @@ -40,6 +40,7 @@ PianoReturn_t PianoXmlParseGenreExplorer (PianoHandle_t *ph,  		const char *xmlContent);  PianoReturn_t PianoXmlParseTranformStation (const char *searchXml);  PianoReturn_t PianoXmlParseNarrative (const char *xml, char **retNarrative); +PianoReturn_t PianoXmlParseSeedSuggestions (char *, PianoSearchResult_t *);  char *PianoXmlEncodeString (const char *s); @@ -239,9 +239,11 @@ PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist, FILE *curFd) {  /*	search music: query, search request, return music id   *	@param piano handle + *	@param read data from fd + *	@param allow seed suggestions if != NULL   *	@return musicId or NULL on abort/error   */ -char *BarUiSelectMusicId (PianoHandle_t *ph, FILE *curFd) { +char *BarUiSelectMusicId (PianoHandle_t *ph, FILE *curFd, char *similarToId) {  	char *musicId = NULL;  	char lineBuf[100], selectBuf[2];  	PianoSearchResult_t searchResult; @@ -250,10 +252,18 @@ char *BarUiSelectMusicId (PianoHandle_t *ph, FILE *curFd) {  	BarUiMsg (MSG_QUESTION, "Search for artist/title: ");  	if (BarReadlineStr (lineBuf, sizeof (lineBuf), 0, curFd) > 0) { -		BarUiMsg (MSG_INFO, "Searching... "); -		if (BarUiPrintPianoStatus (PianoSearchMusic (ph, lineBuf, -				&searchResult)) != PIANO_RET_OK) { -			return NULL; +		if (strcmp ("?", lineBuf) == 0 && similarToId != NULL) { +			BarUiMsg (MSG_INFO, "Receiving suggestions... "); +			if (BarUiPrintPianoStatus (PianoSeedSuggestions (ph, similarToId, +					20, &searchResult)) != PIANO_RET_OK) { +				return NULL; +			} +		} else { +			BarUiMsg (MSG_INFO, "Searching... "); +			if (BarUiPrintPianoStatus (PianoSearchMusic (ph, lineBuf, +					&searchResult)) != PIANO_RET_OK) { +				return NULL; +			}  		}  		BarUiMsg (MSG_NONE, "\r");  		if (searchResult.songs != NULL && searchResult.artists != NULL) { @@ -37,7 +37,7 @@ PianoStation_t *BarUiSelectStation (PianoHandle_t *ph, const char *prompt,  		FILE *curFd);  PianoSong_t *BarUiSelectSong (PianoSong_t *startSong, FILE *curFd);  PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist, FILE *curFd); -char *BarUiSelectMusicId (PianoHandle_t *ph, FILE *curFd); +char *BarUiSelectMusicId (PianoHandle_t *ph, FILE *curFd, char *);  void BarStationFromGenre (PianoHandle_t *ph, FILE *curFd);  inline void BarUiPrintStation (PianoStation_t *);  inline void BarUiPrintSong (PianoSong_t *, PianoStation_t *); diff --git a/src/ui_act.c b/src/ui_act.c index ea7a235..a3d33ed 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -87,7 +87,7 @@ void BarUiActAddMusic (BAR_KS_ARGS) {  	RETURN_IF_NO_STATION; -	musicId = BarUiSelectMusicId (ph, curFd); +	musicId = BarUiSelectMusicId (ph, curFd, (*curSong)->musicId);  	if (musicId != NULL) {  		if (!BarTransformIfShared (ph, *curStation)) {  			return; @@ -124,7 +124,7 @@ void BarUiActCreateStation (BAR_KS_ARGS) {  	char *musicId;  	PianoReturn_t pRet = PIANO_RET_ERR; -	musicId = BarUiSelectMusicId (ph, curFd); +	musicId = BarUiSelectMusicId (ph, curFd, NULL);  	if (musicId != NULL) {  		BarUiMsg (MSG_INFO, "Creating station... ");  		pRet = BarUiPrintPianoStatus (PianoCreateStation (ph, "mi", musicId)); | 
