[lastbash-cvs] lastbash lastbash,1.62,1.63
Status: Beta
Brought to you by:
cstroie
|
From: Costin S. <cs...@us...> - 2006-11-30 16:16:12
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv20689 Modified Files: lastbash Log Message: tui_metadata and lastfm_metadata check error Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.62 retrieving revision 1.63 diff -u -d -r1.62 -r1.63 --- lastbash 30 Nov 2006 16:03:00 -0000 1.62 +++ lastbash 30 Nov 2006 16:16:03 -0000 1.63 @@ -313,12 +313,12 @@ KEY=${HTTP_RESPONSE[$N]%%=*} VALUE=${HTTP_RESPONSE[$N]#*=} case "${KEY}" in - "session") LASTFM_SESSION="${VALUE}" ;; - "stream_url") LASTFM_STREAM="${VALUE}" ;; - "base_url") LASTFM_BASEURL="${VALUE}" ;; - "base_path") LASTFM_BASEPATH="${VALUE}" ;; - "subscriber") LASTFM_SUBSCRIBER="${VALUE}" ;; - "banned") LASTFM_BANNED="${VALUE}" ;; + "session") LASTFM_SESSION="${VALUE}" ;; + "stream_url") LASTFM_STREAM="${VALUE}" ;; + "base_url") LASTFM_BASEURL="${VALUE}" ;; + "base_path") LASTFM_BASEPATH="${VALUE}" ;; + "subscriber") LASTFM_SUBSCRIBER="${VALUE}" ;; + "banned") LASTFM_BANNED="${VALUE}" ;; "info_message") LASTFM_INFO_MESSAGE="${VALUE}" ;; esac done @@ -354,36 +354,45 @@ # $1 - session local N KEY VALUE + local RET WS_ERROR # Do the http get - http_get "${LASTFM_BASEURL}" "${LASTFM_PORT}" "${LASTFM_BASEPATH}/np.php?session=$1" + if http_get "${LASTFM_BASEURL}" "${LASTFM_PORT}" "${LASTFM_BASEPATH}/np.php?session=$1" + then + # Do this only if ok + unset META_ARTIST META_ARTIST_URL META_TRACK META_TRACK_URL META_ALBUM META_ALBUM_URL META_COVER + unset META_DURATION META_STATION META_STREAMING META_DISCOVERY META_RADIOMODE META_RTP - # TODO Do this only if ok - unset META_ARTIST META_ARTIST_URL META_TRACK META_TRACK_URL META_ALBUM META_ALBUM_URL META_COVER - unset META_DURATION META_STATION META_STREAMING META_DISCOVERY META_RADIOMODE META_RTP - #unset META_ACTION_LOVE META_ACTION_SKIP META_ACTION_BAN + # Parse the result + for ((N=0; N<=${#HTTP_RESPONSE[@]}; N++)) + do + 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}" ;; + esac + done + RET="0" + else + RET="1" + debug "${FUNCNAME}: Metadata retrieving failed" + fi - # Parse the result - for ((N=0; N<=${#HTTP_RESPONSE[@]}; N++)) - do - 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}" ;; - esac - done + # Return the status code + return "${RET}" } # Function: Send a Last.fm command {{{1 @@ -405,7 +414,8 @@ # $2 - url local URL=$(url_encode "$2") - local LASTFM_RESPONSE LASTFM_ERROR LASTFM_URL LASTFM_STATIONNAME + local WS_RESPONSE WS_ERROR + local LASTFM_URL LASTFM_STATIONNAME local RET ERRMSG # Do the http get @@ -417,18 +427,18 @@ KEY=${HTTP_RESPONSE[$N]%%=*} VALUE=${HTTP_RESPONSE[$N]#*=} case "${KEY}" in - "response") LASTFM_RESPONSE="${VALUE}" ;; - "error") LASTFM_ERROR="${VALUE}" ;; + "response") WS_RESPONSE="${VALUE}" ;; + "error") WS_ERROR="${VALUE}" ;; "url") LASTFM_URL="${VALUE}" ;; "stationname") LASTFM_STATIONNAME="${VALUE}" ;; esac done # Check the returned data - if [ "${LASTFM_RESPONSE}" != "OK" ] + if [ "${WS_RESPONSE}" != "OK" ] then # FIXME Are these the error codes? - case "${LASTFM_ERROR}" in + case "${WS_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" ;; @@ -438,7 +448,7 @@ "7") RET="8"; ERRMSG="Streaming system is offline for maintenance" ;; *) RET="255"; ERRMSG="Changing station failed. Unknown error." ;; esac - debug "${FUNCNAME}: ${LASTFM_ERROR}. ${ERRMSG}" + debug "${FUNCNAME}: ${WS_ERROR}. ${ERRMSG}" else RET="0" debug "${FUNCNAME}: Station changed" @@ -837,6 +847,8 @@ #----------------------------------------------------------------------------- function tui_metadata() { + local RET + # Save the current metadata local PREV_ARTIST="${META_ARTIST}" local PREV_ALBUM="${META_ALBUM}" @@ -851,36 +863,45 @@ tui_sbar "Retrieving metadata..." # Fetch the metadata - lastfm_metadata "${LASTFM_SESSION}" - - # And only if any metadata has changed - if [ "${META_ARTIST}" != "${PREV_ARTIST}" ] || \ - [ "${META_ALBUM}" != "${PREV_ALBUM}" ] || \ - [ "${META_TRACK}" != "${PREV_TRACK}" ] || \ - [ "${META_DURATION}" != "${PREV_DURATION}" ] + if lastfm_metadata "${LASTFM_SESSION}" then - # Clear the action - unset META_ACTION_LOVE META_ACTION_SKIP META_ACTION_BAN - # Compute the minutes and seconds only if streaming - if [ "${META_STREAMING}" == "true" ] - then - META_MIN=$(( META_DURATION / 60 )) - META_SEC=$(( META_DURATION % 60 )) - else - META_MIN="00" - META_SEC="00" - fi - # Refresh the display - tui_current - # Add to history if there is anything to add - if [ "${PREV_ARTIST}" ] || [ "${PREV_ALBUM}" ] || [ "${PREV_TRACK}" ] + # And only if any metadata has changed + if [ "${META_ARTIST}" != "${PREV_ARTIST}" ] || \ + [ "${META_ALBUM}" != "${PREV_ALBUM}" ] || \ + [ "${META_TRACK}" != "${PREV_TRACK}" ] || \ + [ "${META_DURATION}" != "${PREV_DURATION}" ] then - tui_history + # Clear the action + unset META_ACTION_LOVE META_ACTION_SKIP META_ACTION_BAN + # Compute the minutes and seconds only if streaming + if [ "${META_STREAMING}" == "true" ] + then + META_MIN=$(( META_DURATION / 60 )) + META_SEC=$(( META_DURATION % 60 )) + else + META_MIN="00" + META_SEC="00" + fi + # Refresh the display + tui_current + # Add to history if there is anything to add + if [ "${PREV_ARTIST}" ] || [ "${PREV_ALBUM}" ] || [ "${PREV_TRACK}" ] + then + tui_history + fi fi + RET="0" + else + RET="1" + tui_sbar "Metadata retrieving failed" + sleep 1 fi # Set the new status bar tui_sbar + + # Return the status code + return "${RET}" } # Function: TUI for connecting {{{1 |