[lastbash-cvs] lastbash lastbash,1.59,1.60
Status: Beta
Brought to you by:
cstroie
|
From: Costin S. <cs...@us...> - 2006-11-30 14:43:28
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv18073 Modified Files: lastbash Log Message: lastfm_connect check error Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.59 retrieving revision 1.60 diff -u -d -r1.59 -r1.60 --- lastbash 30 Nov 2006 14:20:32 -0000 1.59 +++ lastbash 30 Nov 2006 14:43:20 -0000 1.60 @@ -65,6 +65,9 @@ CR=$'\x0d' LF=$'\x0a' +# Set some shell options +shopt -s nocasematch + # Labels LBL_ARTIST="Artist" LBL_ALBUM="Album" @@ -226,7 +229,7 @@ # $2 - port # $3 - path - local REQUEST LINE RSP="n" N=0 + local REQUEST LINE RSP="n" N=0 RET local TMP_FILE="${HOME_DIR}/http.tmp" REQUEST="GET $3 HTTP/1.0\r\nHost: $1\r\n\r\n" @@ -275,6 +278,17 @@ # Remove the temporary file rm -f "${TMP_FILE}" + + # Check the status + if [[ "${HTTP_HEADERS[0]}" =~ "200" ]] + then + RET="0" + else + RET="1" + fi + + # Return the status code + return "${RET}" } # Function: Connect to Last.fm and save a playlist {{{1 @@ -284,29 +298,53 @@ # $1 - user # $2 - pass - local N KEY VALUE + local N KEY VALUE RET # Do the http get - http_get "${LASTFM_HOST}" "${LASTFM_PORT}" "/radio/handshake.php?version=${CLIENT_VERSION}&platform=${CLIENT_PLATFORM}&username=$1&passwordmd5=$2" + if http_get "${LASTFM_HOST}" "${LASTFM_PORT}" "/radio/handshake.php?version=${CLIENT_VERSION}&platform=${CLIENT_PLATFORM}&username=$1&passwordmd5=$2" + then + # Do this only if ok + unset LASTFM_SESSION LASTFM_STREAM LASTFM_BASEURL LASTFM_BASEPATH + unset LASTFM_SUBSCRIBER LASTFM_BANNED LASTFM_INFO_MESSAGE - # TODO Do this only if ok - unset LASTFM_SESSION LASTFM_STREAM LASTFM_BASEURL LASTFM_BASEPATH + # Parse the result + for ((N=0; N<=${#HTTP_RESPONSE[@]}; N++)) + do + 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}" ;; + "info_message") LASTFM_INFO_MESSAGE="${VALUE}" ;; + esac + done - # Parse the result - for ((N=0; N<=${#HTTP_RESPONSE[@]}; N++)) - do - 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}" ;; - esac - done + # Check the returned data + if [[ "${LASTFM_SESSION}" =~ "failed" ]] + then + RET="2" + debug "${FUNCNAME}: Session failed" + elif [ "${LASTFM_BANNED}" == "1" ] + then + RET="3" + debug "${FUNCNAME}: Player banned" + else + RET="0" + debug "${FUNCNAME}: Handshake successful" + # Save the playlist + save_m3u "${PLAYLIST_FILE}" "-1" "Last.fm stream" "${LASTFM_STREAM}" + fi + else + RET="1" + debug "${FUNCNAME}: Handshake failed" + fi - # Save the playlist - save_m3u "${PLAYLIST_FILE}" "-1" "Last.fm stream" "${LASTFM_STREAM}" + # Return the status code + return "${RET}" } # Function: Retrieve Last.fm stream metadata {{{1 |