[lastbash-cvs] lastbash lastbash,1.63,1.64
Status: Beta
Brought to you by:
cstroie
|
From: Costin S. <cs...@us...> - 2006-11-30 16:42:03
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv30641 Modified Files: lastbash Log Message: lastfm commands check error Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.63 retrieving revision 1.64 diff -u -d -r1.63 -r1.64 --- lastbash 30 Nov 2006 16:16:03 -0000 1.63 +++ lastbash 30 Nov 2006 16:41:56 -0000 1.64 @@ -369,20 +369,20 @@ KEY=${HTTP_RESPONSE[$N]%%=*} VALUE=${HTTP_RESPONSE[$N]#*=} case "${KEY}" in - "artist") META_ARTIST="${VALUE}" ;; - "artist_url") META_ARTIST_URL="${VALUE}" ;; - "track") META_TRACK="${VALUE}" ;; - "track_url") META_TRACK_URL="${VALUE}" ;; - "album") META_ALBUM="${VALUE}" ;; - "album_url") META_ALBUM_URL="${VALUE}" ;; - "albumcover_medium") META_COVER="${VALUE}" ;; - "trackduration") META_DURATION="${VALUE}" ;; - "station") META_STATION="${VALUE}" ;; - "streaming") META_STREAMING="${VALUE}" ;; - "discovery") META_DISCOVERY="${VALUE}" ;; - "radiomode") META_RADIOMODE="${VALUE}" ;; - "recordtoprofile") META_RTP="${VALUE}" ;; - "error") WS_ERROR="${VALUE}" ;; + "artist") META_ARTIST="${VALUE}" ;; + "artist_url") META_ARTIST_URL="${VALUE}" ;; + "track") META_TRACK="${VALUE}" ;; + "track_url") META_TRACK_URL="${VALUE}" ;; + "album") META_ALBUM="${VALUE}" ;; + "album_url") META_ALBUM_URL="${VALUE}" ;; + "albumcover_medium") META_COVER="${VALUE}" ;; + "trackduration") META_DURATION="${VALUE}" ;; + "station") META_STATION="${VALUE}" ;; + "streaming") META_STREAMING="${VALUE}" ;; + "discovery") META_DISCOVERY="${VALUE}" ;; + "radiomode") META_RADIOMODE="${VALUE}" ;; + "recordtoprofile") META_RTP="${VALUE}" ;; + "error") WS_ERROR="${VALUE}" ;; esac done RET="0" @@ -402,8 +402,38 @@ # $1 - session # $2 - command + local RET WS_RESPONSE WS_ERROR + # Do the http get - http_get "${LASTFM_BASEURL}" "${LASTFM_PORT}" "${LASTFM_BASEPATH}/control.php?session=$1&command=$2" + if http_get "${LASTFM_BASEURL}" "${LASTFM_PORT}" "${LASTFM_BASEPATH}/control.php?session=$1&command=$2" + then + # Parse the result + for ((N=0; N<=${#HTTP_RESPONSE[@]}; N++)) + do + KEY=${HTTP_RESPONSE[$N]%%=*} + VALUE=${HTTP_RESPONSE[$N]#*=} + case "${KEY}" in + "response") WS_RESPONSE="${VALUE}" ;; + "error") WS_ERROR="${VALUE}" ;; + esac + done + + # Check the returned data + if [ "${WS_RESPONSE}" != "OK" ] + then + RET="2" + debug "${FUNCNAME}: Command failed, unknown error" + else + RET="0" + debug "${FUNCNAME}: Command sent" + fi + else + RET="1" + debug "${FUNCNAME}: Command failed" + fi + + # Return the status code + return "${RET}" } # Function: Set a new Last.fm station {{{1 @@ -446,7 +476,7 @@ "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." ;; + *) RET="255"; ERRMSG="Changing station failed for unknown error" ;; esac debug "${FUNCNAME}: ${WS_ERROR}. ${ERRMSG}" else @@ -985,100 +1015,167 @@ { # $1 - command + local RET + # Set the status line tui_sbar "Sending command: $1" - lastfm_command "${LASTFM_SESSION}" "$1" + # Try sending the command + if lastfm_command "${LASTFM_SESSION}" "$1" + then + RET="0" + # Update the status line + tui_sbar "Command sent successfully" + else + RET="1" + # Update the status line + tui_sbar "Error sending command" + fi - # Update the status line - tui_sbar "Command sent" + # Return the status code + return "${RET}" } # Function: TUI for Last.fm love command {{{1 #----------------------------------------------------------------------------- function tui_lastfm_command_love() { + local RET + # One love per track - [ "${META_ACTION_LOVE}" ] && return - tui_lastfm_command "love" - META_ACTION_LOVE="y" + [ "${META_ACTION_LOVE}" ] && return 0 - # Refresh the display - tui_current + # Try sending the command + if tui_lastfm_command "love" + then + RET="0" + META_ACTION_LOVE="y" + + # Refresh the display + tui_current + else + RET="1" + fi # Sleep one moment and restore the status bar sleep 1 tui_sbar + + # Return the status code + return "${RET}" } # Function: TUI for Last.fm skip command {{{1 #----------------------------------------------------------------------------- function tui_lastfm_command_skip() { + local RET + # One skip per track - [ "${META_ACTION_SKIP}" ] && return - tui_lastfm_command "skip" - META_ACTION_SKIP="y" + [ "${META_ACTION_SKIP}" ] && return 0 - # Refresh the display - #tui_current + # Try sending the command + if tui_lastfm_command "skip" + then + RET="0" + META_ACTION_SKIP="y" + else + RET="1" + fi # Sleep one moment and refresh the metadata sleep 1 tui_metadata + + # Return the status code + return "${RET}" } # Function: TUI for Last.fm ban command {{{1 #----------------------------------------------------------------------------- function tui_lastfm_command_ban() { + local RET + # One ban per track [ "${META_ACTION_BAN}" ] && return - tui_lastfm_command "ban" - META_ACTION_BAN="y" - # Refresh the display - tui_current + # Try sending the command + if tui_lastfm_command "ban" + then + RET="0" + META_ACTION_BAN="y" + + # Refresh the display + tui_current + else + RET="1" + fi # Sleep one moment and refresh the metadata sleep 1 tui_metadata + + # Return the status code + return "${RET}" } # Function: TUI for toggling Record to Profile {{{1 #----------------------------------------------------------------------------- function tui_lastfm_rtp() { + local RET="0" + if [ "${META_RTP}" == "1" ] then tui_sbar "Disabling RTP..." - lastfm_command "${LASTFM_SESSION}" "nortp" + lastfm_command "${LASTFM_SESSION}" "nortp" || RET="1" else tui_sbar "Enabling RTP..." - lastfm_command "${LASTFM_SESSION}" "rtp" + lastfm_command "${LASTFM_SESSION}" "rtp" || RET="2" + fi + + # Say something if action failed + if [ "${RET}" != "0" ] + then + tui_sbar "Action failed" fi # Sleep one moment and refresh the metadata sleep 1 tui_metadata + + # Return the status code + return "${RET}" } # Function: TUI for toggling Discovery mode {{{1 #----------------------------------------------------------------------------- function tui_lastfm_discovery() { + local RET="0" + if [ "${META_DISCOVERY}" == "1" ] then tui_sbar "Disable discovery mode..." - lastfm_station "${LASTFM_SESSION}" "lastfm://settings/discovery/off" + lastfm_station "${LASTFM_SESSION}" "lastfm://settings/discovery/off" || RET="1" else tui_sbar "Enable discovery mode..." - lastfm_station "${LASTFM_SESSION}" "lastfm://settings/discovery/on" + lastfm_station "${LASTFM_SESSION}" "lastfm://settings/discovery/on" || RET="2" + fi + + # Say something if action failed + if [ "${RET}" != "0" ] + then + tui_sbar "Action failed" fi # Sleep one moment and refresh the metadata sleep 1 tui_metadata + + # Return the status code + return "${RET}" } # Function: Send commands to the player {{{1 |