[lastbash-cvs] lastbash lastbash,1.61,1.62
Status: Beta
Brought to you by:
cstroie
|
From: Costin S. <cs...@us...> - 2006-11-30 16:03:10
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv16925 Modified Files: lastbash Log Message: tui_lastfm_station and lastfm_station check error Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.61 retrieving revision 1.62 diff -u -d -r1.61 -r1.62 --- lastbash 30 Nov 2006 15:02:25 -0000 1.61 +++ lastbash 30 Nov 2006 16:03:00 -0000 1.62 @@ -405,8 +405,51 @@ # $2 - url local URL=$(url_encode "$2") + local LASTFM_RESPONSE LASTFM_ERROR LASTFM_URL LASTFM_STATIONNAME + local RET ERRMSG - http_get "${LASTFM_BASEURL}" "${LASTFM_PORT}" "${LASTFM_BASEPATH}/adjust.php?session=$1&url=${URL}" + # Do the http get + if http_get "${LASTFM_BASEURL}" "${LASTFM_PORT}" "${LASTFM_BASEPATH}/adjust.php?session=$1&url=${URL}" + then + # Parse the result + for ((N=0; N<=${#HTTP_RESPONSE[@]}; N++)) + do + KEY=${HTTP_RESPONSE[$N]%%=*} + VALUE=${HTTP_RESPONSE[$N]#*=} + case "${KEY}" in + "response") LASTFM_RESPONSE="${VALUE}" ;; + "error") LASTFM_ERROR="${VALUE}" ;; + "url") LASTFM_URL="${VALUE}" ;; + "stationname") LASTFM_STATIONNAME="${VALUE}" ;; + esac + done + + # Check the returned data + if [ "${LASTFM_RESPONSE}" != "OK" ] + then + # FIXME Are these the error codes? + case "${LASTFM_ERROR}" in + "1") RET="2"; ERRMSG="Not enough content to play this station" ;; + "2") RET="3"; ERRMSG="Not enough members for radio" ;; + "3") RET="4"; ERRMSG="Not enough fans for radio" ;; + "4") RET="5"; ERRMSG="Not available for streaming" ;; + "5") RET="6"; ERRMSG="Feature only available to subscribers" ;; + "6") RET="7"; ERRMSG="Not enough neighbours for this radio" ;; + "7") RET="8"; ERRMSG="Streaming system is offline for maintenance" ;; + *) RET="255"; ERRMSG="Changing station failed. Unknown error." ;; + esac + debug "${FUNCNAME}: ${LASTFM_ERROR}. ${ERRMSG}" + else + RET="0" + debug "${FUNCNAME}: Station changed" + fi + else + RET="1" + debug "${FUNCNAME}: Changing station failed" + fi + + # Return the status code + return "${RET}" } # Function: Ask username and password {{{1 @@ -886,17 +929,33 @@ { # $1 - station + local ERRCODE RET + # Set the status line tui_sbar "Setting new Last.fm station..." + # Try changing the station lastfm_station "${LASTFM_SESSION}" "$1" + ERRCODE="$?" - # Update the status line - tui_sbar "Station changed" + # Check the error code + if [ "${ERRCODE}" == "0" ] + then + RET="0" + # Update the status line + tui_sbar "Station changed" + else + # TODO Display the detailed error messages + RET="1" + tui_sbar "Changing station failed" + fi # Sleep one moment and refresh the metadata sleep 1 tui_metadata + + # Return the status code + return "${RET}" } # Function: TUI for Last.fm command {{{1 |