lastbash-cvs Mailing List for Last.fm console player (Page 7)
Status: Beta
Brought to you by:
cstroie
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(27) |
Dec
(77) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(14) |
Feb
(8) |
Mar
(41) |
Apr
(5) |
May
(2) |
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2008 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
|
From: Costin S. <cs...@us...> - 2006-12-05 15:39:29
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9583 Modified Files: lastbash Log Message: Keep the history in memory and redisplay it when resize. Added support for toggling the scrolling direction. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.75 retrieving revision 1.76 diff -u -d -r1.75 -r1.76 --- lastbash 5 Dec 2006 12:53:49 -0000 1.75 +++ lastbash 5 Dec 2006 15:39:26 -0000 1.76 @@ -950,6 +950,14 @@ #----------------------------------------------------------------------------- function tui_history() { + # $1 - index of HISTORY array to display + + # Return if the index is invalid + if [ "$1" -ge "${#HISTORY_ARTIST[*]}" ] || [ "$1" -lt 0 ] + then + return + fi + # Define the scroll area tput csr ${TSCROLL_FIRST} ${TSCROLL_LAST} @@ -973,7 +981,7 @@ fi # Display the history line - tui_history_line + tui_history_line "$1" # Increment the current line number (( TSCROLL_CURRENT++ )) @@ -982,16 +990,62 @@ tput csr 0 ${T_LINES} } +# Function: Re-display the whole history area {{{1 +#----------------------------------------------------------------------------- +function tui_history_redisplay() +{ + local SCROLL_LINES="$(( TSCROLL_LAST - TSCROLL_FIRST + 1 ))" + [ "${SCROLL_LINES}" -lt 0 ] && SCROLL_LINES="0" + local HLAST="${#HISTORY_ARTIST[*]}" + local HFIRST="$(( HLAST - SCROLL_LINES ))" + [ "${HFIRST}" -lt 0 ] && HFIRST="0" + local INDEX HINDEX SLINE + + # Define the scroll area + tput csr ${TSCROLL_FIRST} ${TSCROLL_LAST} + + for (( INDEX=0; INDEX < SCROLL_LINES; INDEX++ )) + do + # Compute the index to display + if [ "${HISTORY_SCROLL_DOWN}" == "y" ] + then + HINDEX="$(( HLAST - INDEX - 1 ))" + else + HINDEX="$(( HFIRST + INDEX ))" + fi + + # Compute the scroll line number + SLINE="$(( TSCROLL_FIRST + INDEX ))" + + # Check the index, move the cursor and print the line + if [ "${HINDEX}" -lt "${HLAST}" ] && [ "${HINDEX}" -ge 0 ] + then + # Move the cursor on the determined line + tput cup ${SLINE} 0 + # Display the history line + tui_history_line "${HINDEX}" + fi + done + + # Compute the scroll line number + TSCROLL_CURRENT="$(( TSCROLL_FIRST + HLAST ))" + + # Restore the whole screen as scrolling area + tput csr 0 ${T_LINES} +} + # Function: Display the line in history area {{{1 #----------------------------------------------------------------------------- function tui_history_line() { + # $1 - index in HISTORY array + local FIELD LINE S # Start with the love/ban indicator - if [ "${PREV_ACTION}" ] + if [ "${HISTORY_ACTION[$1]}" ] then - LINE=" ${PREV_ACTION:0:1}" + LINE=" ${HISTORY_ACTION[$1]:0:1}" else LINE=" " fi @@ -1000,7 +1054,7 @@ if [ "${HISTORY_FIELD_UNITS[0]}" != "0" ] then S="${HISTORY_FIELD_SIZE[0]}" - printf -v FIELD " %-${S}s" "${PREV_ARTIST:0:$S}" + printf -v FIELD " %-${S}s" "${HISTORY_ARTIST[$1]:0:$S}" LINE="${LINE}${FIELD}" fi @@ -1008,17 +1062,17 @@ if [ "${HISTORY_FIELD_UNITS[1]}" != "0" ] then S="${HISTORY_FIELD_SIZE[1]}" - printf -v FIELD " %-${S}s" "${PREV_ALBUM:0:$S}" + printf -v FIELD " %-${S}s" "${HISTORY_ALBUM[$1]:0:$S}" LINE="${LINE}${FIELD}" fi # Add the track title S="${HISTORY_FIELD_SIZE[2]}" - printf -v FIELD " %-${S}s" "${PREV_TRACK:0:$S}" + printf -v FIELD " %-${S}s" "${HISTORY_TRACK[$1]:0:$S}" LINE="${LINE}${FIELD}" # Add the track duration - printf -v FIELD " %6s " "${PREV_MIN_SEC}" + printf -v FIELD " %6s " "${HISTORY_MIN_SEC[$1]}" LINE="${LINE}${FIELD}" # Output the line @@ -1029,7 +1083,7 @@ #----------------------------------------------------------------------------- function tui_metadata() { - local RET + local RET HINDEX # Save the current metadata local PREV_ARTIST="${META_ARTIST}" @@ -1051,15 +1105,6 @@ [ "${META_TRACK}" != "${PREV_TRACK}" ] || \ [ "${META_DURATION}" != "${PREV_DURATION}" ] then - # Save in history - HINDEX="${#HISTORY_ARTIST[*]}" - HISTORY_ARTIST[$HINDEX]="${PREV_ARTIST}" - HISTORY_ALBUM[$HINDEX]="${PREV_ALBUM}" - HISTORY_TRACK[$HINDEX]="${PREV_TRACK}" - HISTORY_DURATION[$HINDEX]="${PREV_DURATION}" - HISTORY_MIN_SEC[$HINDEX]="${PREV_MIN_SEC}" - HISTORY_ACTION[$HINDEX]="${META_ACTION}" - # Clear the action unset META_ACTION META_ACTION_LOVE META_ACTION_SKIP META_ACTION_BAN @@ -1070,12 +1115,23 @@ else unset META_MIN_SEC 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 + # Save in history + HINDEX="${#HISTORY_ARTIST[*]}" + HISTORY_ARTIST[$HINDEX]="${PREV_ARTIST}" + HISTORY_ALBUM[$HINDEX]="${PREV_ALBUM}" + HISTORY_TRACK[$HINDEX]="${PREV_TRACK}" + HISTORY_DURATION[$HINDEX]="${PREV_DURATION}" + HISTORY_MIN_SEC[$HINDEX]="${PREV_MIN_SEC}" + HISTORY_ACTION[$HINDEX]="${META_ACTION}" + + tui_history "${HINDEX}" fi fi RET="0" @@ -1338,6 +1394,27 @@ return "${RET}" } +# Function: TUI for toggling history scrolling direction {{{1 +#----------------------------------------------------------------------------- +function tui_scroll_toggle() +{ + if [ "${HISTORY_SCROLL_DOWN}" == "y" ] + then + tui_sbar "History scroll upward" + HISTORY_SCROLL_DOWN="n" + else + tui_sbar "History scroll downward" + HISTORY_SCROLL_DOWN="y" + fi + + # Redisplay the scrolling area + tui_history_redisplay + + # Sleep one moment and restore the status bar + sleep 1 + tui_sbar +} + # Function: Send commands to the player {{{1 #----------------------------------------------------------------------------- function player_command() @@ -1593,7 +1670,7 @@ # Redisplay the TUI tui_start tui_current - tui_history + tui_history_redisplay } @@ -1612,6 +1689,7 @@ "k") tui_lastfm_command_skip ;; "p") tui_lastfm_rtp ;; "d") tui_lastfm_discovery ;; + "s") tui_scroll_toggle ;; # Redisplay the TUI "${CTRL_L}") sigwinch ;; # Player commands |
|
From: Costin S. <cs...@us...> - 2006-12-05 12:53:53
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6801 Modified Files: lastbash Log Message: Initial support for history storing and better duration treatment. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.74 retrieving revision 1.75 diff -u -d -r1.74 -r1.75 --- lastbash 4 Dec 2006 16:57:36 -0000 1.74 +++ lastbash 5 Dec 2006 12:53:49 -0000 1.75 @@ -65,6 +65,7 @@ HTTP_CLIENTS="wget curl" REQ_PROGRAMS="rm date sleep tput md5sum dd chmod" declare -a HTTP_HEADERS HTTP_RESPONSE +declare -a HISTORY_ARTIST HISTORY_ALBUM HISTORY_TRACK HISTORY_DURATION HISTORY_MIN_SEC HISTORY_ACTION CR=$'\x0d' LF=$'\x0a' CTRL_L=$'\x0c' @@ -914,7 +915,7 @@ #----------------------------------------------------------------------------- function tui_current() { - local LINE ACTION + local LINE printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_ARTIST}" "${META_ARTIST:0:$TCURRENT_MAX}" tput cup 2 2 @@ -928,24 +929,11 @@ tput cup 4 2 echo -ne "${LINE}${T_EL}" - printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %d:%02d" "${LBL_LENGTH}" "${META_MIN}" "${META_SEC}" + printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_LENGTH}" "${META_MIN_SEC}" tput cup 5 2 echo -ne "${LINE}${T_EL}" - if [ "${META_ACTION_LOVE}" ] - then - ACTION="Loved" - elif [ "${META_ACTION_SKIP}" ] - then - ACTION="Skipped" - elif [ "${META_ACTION_BAN}" ] - then - ACTION="Banned" - else - ACTION="" - fi - - printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_ACTION}" "${ACTION}" + printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_ACTION}" "${META_ACTION}" tput cup 6 2 echo -ne "${LINE}${T_EL}" @@ -1001,12 +989,9 @@ local FIELD LINE S # Start with the love/ban indicator - if [ "${PREV_ACTION_LOVE}" ] - then - LINE=" L" - elif [ "${PREV_ACTION_BAN}" ] + if [ "${PREV_ACTION}" ] then - LINE=" B" + LINE=" ${PREV_ACTION:0:1}" else LINE=" " fi @@ -1033,7 +1018,7 @@ LINE="${LINE}${FIELD}" # Add the track duration - printf -v FIELD " %3d:%02d " "${PREV_MIN}" "${PREV_SEC}" + printf -v FIELD " %6s " "${PREV_MIN_SEC}" LINE="${LINE}${FIELD}" # Output the line @@ -1051,10 +1036,8 @@ local PREV_ALBUM="${META_ALBUM}" local PREV_TRACK="${META_TRACK}" local PREV_DURATION="${META_DURATION}" - local PREV_MIN="${META_MIN}" - local PREV_SEC="${META_SEC}" - local PREV_ACTION_LOVE="${META_ACTION_LOVE}" - local PREV_ACTION_BAN="${META_ACTION_BAN}" + local PREV_MIN_SEC="${META_MIN_SEC}" + local PREV_ACTION="${META_ACTION}" # Set the status line tui_sbar "Retrieving metadata..." @@ -1068,16 +1051,24 @@ [ "${META_TRACK}" != "${PREV_TRACK}" ] || \ [ "${META_DURATION}" != "${PREV_DURATION}" ] then + # Save in history + HINDEX="${#HISTORY_ARTIST[*]}" + HISTORY_ARTIST[$HINDEX]="${PREV_ARTIST}" + HISTORY_ALBUM[$HINDEX]="${PREV_ALBUM}" + HISTORY_TRACK[$HINDEX]="${PREV_TRACK}" + HISTORY_DURATION[$HINDEX]="${PREV_DURATION}" + HISTORY_MIN_SEC[$HINDEX]="${PREV_MIN_SEC}" + HISTORY_ACTION[$HINDEX]="${META_ACTION}" + # Clear the action - unset META_ACTION_LOVE META_ACTION_SKIP META_ACTION_BAN + unset META_ACTION 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 )) + printf -v META_MIN_SEC "%d:%02d" "$(( META_DURATION / 60 ))" "$(( META_DURATION % 60 ))" else - META_MIN="00" - META_SEC="00" + unset META_MIN_SEC fi # Refresh the display tui_current @@ -1217,6 +1208,7 @@ then RET="0" META_ACTION_LOVE="y" + META_ACTION="Loved" # Refresh the display tui_current @@ -1272,6 +1264,7 @@ then RET="0" META_ACTION_BAN="y" + META_ACTION="Banned" # Refresh the display tui_current |
|
From: Costin S. <cs...@us...> - 2006-12-04 16:57:40
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19850 Modified Files: lastbash Log Message: Added support for curl as external http client. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.73 retrieving revision 1.74 diff -u -d -r1.73 -r1.74 --- lastbash 4 Dec 2006 16:32:33 -0000 1.73 +++ lastbash 4 Dec 2006 16:57:36 -0000 1.74 @@ -62,7 +62,7 @@ # Internal stuff PLAYERS="mplayer" -HTTP_CLIENTS="wget" +HTTP_CLIENTS="wget curl" REQ_PROGRAMS="rm date sleep tput md5sum dd chmod" declare -a HTTP_HEADERS HTTP_RESPONSE CR=$'\x0d' @@ -287,6 +287,7 @@ # Select the HTTP client function case "${HTTP_CLIENT}" in "wget") HTTP_CLIENT_FUNCTION="http_get_wget" ;; + "curl") HTTP_CLIENT_FUNCTION="http_get_curl" ;; *) HTTP_CLIENT_FUNCTION="http_get_builtin" ;; esac @@ -359,10 +360,10 @@ # $3 - port # $4 - path - local RET ERRCODE + local RET # Send the request - wget --quiet \ + if wget --quiet \ --tries="3" \ --timeout="5" \ --save-headers \ @@ -371,12 +372,39 @@ --output-file="/dev/null" \ --output-document="${1}" \ "http://${2}:${3}${4}" + then + RET="0" + else + RET="1" + fi - # Keep the error code - ERRCODE="$?" + # Return the status code + return "${RET}" +} - # Check error code - if [ "${ERRCODE}" == "0" ] +# Function: HTTP GET method: curl implementation {{{1 +#----------------------------------------------------------------------------- +function http_get_curl() +{ + # $1 - output file + # $2 - host + # $3 - port + # $4 - path + + local RET + + # Send the request + if curl --silent \ + --connect-timeout "5" \ + --max-time "8" \ + --retry "3" \ + --http1.0 \ + --user-agent "${PROG_TITLE}/${PROG_VER}" \ + --header "Connection: Close" \ + --dump-header - \ + --output - \ + --stderr "/dev/null" \ + "http://${2}:${3}${4}" > "${1}" then RET="0" else |
|
From: Costin S. <cs...@us...> - 2006-12-04 16:32:36
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9762 Modified Files: lastbash Log Message: Improved the error detection in builtin http client. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.72 retrieving revision 1.73 diff -u -d -r1.72 -r1.73 --- lastbash 4 Dec 2006 16:28:39 -0000 1.72 +++ lastbash 4 Dec 2006 16:32:33 -0000 1.73 @@ -402,20 +402,30 @@ REQUEST="GET $4 HTTP/1.0\r\nHost: $2:$3\r\nUser-Agent: ${PROG_TITLE}/${PROG_VER}\r\nConnection: Close\r\n\r\n" # Map the FD no.5 to tcp connection - exec 5<>/dev/tcp/$2/$3 - [ "$?" != "0" ] && RET="1" - - # Send the request - echo -ne "${REQUEST}" >&5 2>/dev/null - [ "$?" != "0" ] && RET="2" - - # Save the response to the temporary file - dd <&5 >"${1}" 2>/dev/null - [ "$?" != "0" ] && RET="3" - - # Close the connection - exec 5>&- - [ "$?" != "0" ] && RET="4" + if exec 5<>/dev/tcp/$2/$3 + then + # Send the request + if echo -ne "${REQUEST}" >&5 2>/dev/null + then + # Save the response to the temporary file + if dd <&5 >"${1}" 2>/dev/null + then + # Close the connection + if exec 5>&- + then + RET="0" + else + RET="4" + fi + else + RET="3" + fi + else + RET="2" + fi + else + RET="1" + fi # Return the status code return "${RET}" |
|
From: Costin S. <cs...@us...> - 2006-12-04 16:28:46
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv8089 Modified Files: lastbash Log Message: Added support for external http clients (see the ubuntu bug). Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.71 retrieving revision 1.72 diff -u -d -r1.71 -r1.72 --- lastbash 30 Nov 2006 21:49:05 -0000 1.71 +++ lastbash 4 Dec 2006 16:28:39 -0000 1.72 @@ -24,12 +24,13 @@ # User settings DEBUG="n" -USE_PLAYER="y" HISTORY_SCROLL_DOWN="y" HISTORY_FIELD_UNITS=(2 2 3) REFRESH_INTERVAL="30" PLAYER="auto" # $PLAYERS, auto +USE_PLAYER="y" AUTO_PLAY="y" +HTTP_CLIENT="auto" # $HTTP_CLIENTS, builtin, auto # Program identification PROG_NAME="lastbash" @@ -61,6 +62,7 @@ # Internal stuff PLAYERS="mplayer" +HTTP_CLIENTS="wget" REQ_PROGRAMS="rm date sleep tput md5sum dd chmod" declare -a HTTP_HEADERS HTTP_RESPONSE CR=$'\x0d' @@ -183,7 +185,7 @@ break fi done - # No player is not present + # No player is present [ ! "${PLAYER}" ] && debug "No supported player found." else if type -t "${PLAYER}" >/dev/null 2>&1 @@ -195,6 +197,42 @@ PLAYER="" fi fi + + # Check for http client + if [ "${HTTP_CLIENT}" == "builtin" ] + then + debug "Using the builtin HTTP client." + elif [ "${HTTP_CLIENT}" == "auto" ] + then + HTTP_CLIENT="" + debug "Searching for available and supported HTTP clients..." + # Search for the first supported http client + for P in ${HTTP_CLIENTS} + do + debug "Trying ${P}..." + if type -t "${P}" >/dev/null 2>&1 + then + debug "HTTP client found: ${P}" + HTTP_CLIENT="${P}" + break + fi + done + # No HTTP client is present + if [ ! "${HTTP_CLIENT}" ] + then + debug "No supported HTTP client found, using the builtin one." + HTTP_CLIENT="builtin" + fi + else + if type -t "${HTTP_CLIENT}" >/dev/null 2>&1 + then + debug "HTTP client found: ${HTTP_CLIENT}" + else + # The HTTP client is not present, switching to builtin + debug "HTTP client ${HTTP_CLIENT} not found." + HTTP_CLIENT="builtin" + fi + fi } # Function: Save the settings {{{1 @@ -233,7 +271,7 @@ done } -# Function: HTTP GET method implementation {{{1 +# Function: HTTP GET method {{{1 #----------------------------------------------------------------------------- function http_get() { @@ -241,58 +279,104 @@ # $2 - port # $3 - path - local REQUEST LINE RSP="n" N=0 RET + local HTTP_CLIENT_FUNCTION RET + local GET_PATH + local LINE RSP="n" N=0 local TMP_FILE="${HOME_DIR}/http.tmp" - REQUEST="GET $3 HTTP/1.0\r\nHost: $1\r\n\r\n" - # Map the FD no.5 to tcp connection - exec 5<>/dev/tcp/$1/$2 + # Select the HTTP client function + case "${HTTP_CLIENT}" in + "wget") HTTP_CLIENT_FUNCTION="http_get_wget" ;; + *) HTTP_CLIENT_FUNCTION="http_get_builtin" ;; + esac - # Send the request - debug "${FUNCNAME}: Q> ${REQUEST}" - # FIXME add error processing - echo -ne "${REQUEST}" >&5 2>/dev/null + # Make sure the GET path starts with "/" + GET_PATH="$3" + [ "${GET_PATH:0:1}" != "/" ] && GET_PATH="/${GET_PATH}" - # Save the response to a temporary file - dd <&5 >"${TMP_FILE}" 2>/dev/null - # Append one (missing) EOL - echo >> "${TMP_FILE}" + # Log the request + debug "${FUNCNAME}: Q> http://${1}:${2}${GET_PATH}" - # Close the connection - exec 5>&- + # Do the HTTP request + if "${HTTP_CLIENT_FUNCTION}" "${TMP_FILE}" "$1" "$2" "${GET_PATH}" + then + # Append one (missing) EOL (and make sure the file exits) + echo >> "${TMP_FILE}" - # Clear the HTTP_* arrays - HTTP_HEADERS=() - HTTP_RESPONSE=() + # Clear the HTTP_* arrays + HTTP_HEADERS=() + HTTP_RESPONSE=() - # Parse the result - while read LINE - do - LINE="${LINE//$CR/}" - if [ "${LINE}" == "" ] - then - N=0 - RSP="y" - else - if [ "${RSP}" == "n" ] + # Parse the result + while read LINE + do + LINE="${LINE//$CR/}" + if [ "${LINE}" == "" ] then - HTTP_HEADERS[$N]="${LINE}" - debug "${FUNCNAME}: H> ${LINE}" + N=0 + RSP="y" else - HTTP_RESPONSE[$N]="${LINE}" - debug "${FUNCNAME}: R> ${LINE}" + if [ "${RSP}" == "n" ] + then + HTTP_HEADERS[$N]="${LINE}" + debug "${FUNCNAME}: H> ${LINE}" + else + HTTP_RESPONSE[$N]="${LINE}" + debug "${FUNCNAME}: R> ${LINE}" + fi fi - fi - # Increment the index - (( N++ )) - done < "${TMP_FILE}" + # Increment the index + (( N++ )) + done < "${TMP_FILE}" + + # Check the status + if [[ "${HTTP_HEADERS[0]}" =~ "200" ]] + then + RET="0" + else + debug "${FUNCNAME}: HTTP GET status is not OK" + RET="1" + fi + else + debug "${FUNCNAME}: HTTP GET error" + RET="2" + fi # Remove the temporary file rm -f "${TMP_FILE}" - # Check the status - if [[ "${HTTP_HEADERS[0]}" =~ "200" ]] + # Return the status code + return "${RET}" +} + +# Function: HTTP GET method: wget implementation {{{1 +#----------------------------------------------------------------------------- +function http_get_wget() +{ + # $1 - output file + # $2 - host + # $3 - port + # $4 - path + + local RET ERRCODE + + # Send the request + wget --quiet \ + --tries="3" \ + --timeout="5" \ + --save-headers \ + --header="Connection: Close" \ + --user-agent="${PROG_TITLE}/${PROG_VER}" \ + --output-file="/dev/null" \ + --output-document="${1}" \ + "http://${2}:${3}${4}" + + # Keep the error code + ERRCODE="$?" + + # Check error code + if [ "${ERRCODE}" == "0" ] then RET="0" else @@ -303,6 +387,40 @@ return "${RET}" } +# Function: HTTP GET method: builtin implementation {{{1 +#----------------------------------------------------------------------------- +function http_get_builtin() +{ + # $1 - output file + # $2 - host + # $3 - port + # $4 - path + + local REQUEST RET="0" + + # Construct the request + REQUEST="GET $4 HTTP/1.0\r\nHost: $2:$3\r\nUser-Agent: ${PROG_TITLE}/${PROG_VER}\r\nConnection: Close\r\n\r\n" + + # Map the FD no.5 to tcp connection + exec 5<>/dev/tcp/$2/$3 + [ "$?" != "0" ] && RET="1" + + # Send the request + echo -ne "${REQUEST}" >&5 2>/dev/null + [ "$?" != "0" ] && RET="2" + + # Save the response to the temporary file + dd <&5 >"${1}" 2>/dev/null + [ "$?" != "0" ] && RET="3" + + # Close the connection + exec 5>&- + [ "$?" != "0" ] && RET="4" + + # Return the status code + return "${RET}" +} + # Function: Connect to Last.fm and save a playlist {{{1 #----------------------------------------------------------------------------- function lastfm_connect() |
|
From: Costin S. <cs...@us...> - 2006-11-30 21:49:27
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv22013 Modified Files: TODO Log Message: Some more added. Index: TODO =================================================================== RCS file: /cvsroot/lastbash/lastbash/TODO,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- TODO 30 Nov 2006 20:51:01 -0000 1.11 +++ TODO 30 Nov 2006 21:49:24 -0000 1.12 @@ -2,14 +2,19 @@ # $Id$ TODO +- add more led monitored stuff +- improve player support +- add more players +- do something with the unicode chars in history +- better interface (themeable) - save a html file with album cover, links, etc. - maybe save a csv history file -- implement the leds - add support for changing stations in interface - improve support for interface refresh (keep history) - add support for color and bw interface DONE +- implement the leds - maybe mark the loved/banned/skipped tracks - more commands per remote call - use 'tput' instead of plain ansi escape codes |
|
From: Costin S. <cs...@us...> - 2006-11-30 21:49:08
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21891 Modified Files: lastbash Log Message: User CTRL-L for redraw. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.70 retrieving revision 1.71 diff -u -d -r1.70 -r1.71 --- lastbash 30 Nov 2006 21:29:29 -0000 1.70 +++ lastbash 30 Nov 2006 21:49:05 -0000 1.71 @@ -65,6 +65,7 @@ declare -a HTTP_HEADERS HTTP_RESPONSE CR=$'\x0d' LF=$'\x0a' +CTRL_L=$'\x0c' # Set some shell options shopt -s nocasematch @@ -1463,7 +1464,7 @@ "p") tui_lastfm_rtp ;; "d") tui_lastfm_discovery ;; # Redisplay the TUI - "R") sigwinch ;; + "${CTRL_L}") sigwinch ;; # Player commands "x") player_load ;; "X") player_start ;; @@ -1476,7 +1477,7 @@ *) if [ "${KEY}" ] then - # FIXME this is executed after a remote call, too + # FIXME this gets executed after a remote call, too tui_keys sleep 3 tui_sbar @@ -1554,7 +1555,7 @@ # Let's initialize init -# Login +# Ask user name and password, if needed login # Now, let's save the PID |
|
From: Costin S. <cs...@us...> - 2006-11-30 21:29:32
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14047 Modified Files: lastbash Log Message: Improved the leds string formatting. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.69 retrieving revision 1.70 diff -u -d -r1.69 -r1.70 --- lastbash 30 Nov 2006 21:19:32 -0000 1.69 +++ lastbash 30 Nov 2006 21:29:29 -0000 1.70 @@ -713,7 +713,7 @@ { # $1 - the text to print - local LINE LEDS L1 L2 L3 L4 S + local LINE L1 L2 L3 L4 S # Set the leds # - R: the player is running # - P: record to profile is on @@ -722,7 +722,6 @@ [ "${META_RTP}" == "1" ] && L2="P" || L2="-" [ "${META_DISCOVERY}" == "1" ] && L3="D" || L3="-" L4="-" - LEDS="${L1}${L2}${L3}${L4}" # Compute the main field size S=$(( T_COLUMNS - 27 )) @@ -730,12 +729,12 @@ # Format the status line if [ "$1" ] then - printf -v LINE " %-${S}s %-15s [%s] " "$1" "$LASTFM_USER" "$LEDS" + printf -v LINE " %-${S}s %-15s [%c%c%c%c] " "${1:0:$S}" "${LASTFM_USER}" "${L1}" "${L2}" "${L3}" "${L4}" elif [ "${META_STREAMING}" == "true" ] then - printf -v LINE " %-${S}s %-15s [%s] " "$META_STATION" "$LASTFM_USER" "$LEDS" + printf -v LINE " %-${S}s %-15s [%c%c%c%c] " "${META_STATION:0:$S}" "${LASTFM_USER}" "${L1}" "${L2}" "${L3}" "${L4}" else - printf -v LINE " %-${S}s %-15s [%s] " "Not streaming" "$LASTFM_USER" "$LEDS" + printf -v LINE " %-${S}s %-15s [%c%c%c%c] " "Not streaming, please launch the player" "${LASTFM_USER}" "${L1}" "${L2}" "${L3}" "${L4}" fi # Move the cursor on lower-left corner and print tput cup ${T_LINES} 0 |
|
From: Costin S. <cs...@us...> - 2006-11-30 21:19:35
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv10126 Modified Files: lastbash Log Message: Checjing for a minimum terminal size. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.68 retrieving revision 1.69 diff -u -d -r1.68 -r1.69 --- lastbash 30 Nov 2006 21:12:30 -0000 1.68 +++ lastbash 30 Nov 2006 21:19:32 -0000 1.69 @@ -146,6 +146,16 @@ debug "No missing programs." fi + # Check a minimum terminal size + T_LINES=$(tput lines) + T_COLUMNS=$(tput cols) + if [ "${T_LINES}" -lt 15 ] || [ "${T_COLUMNS}" -lt 60 ] + then + echo "Minimum terminal size is 60x15, your is ${T_COLUMNS}x${T_LINES}" + debug "Terminal size insufficient: ${T_COLUMNS}x${T_LINES}" + exit 1 + fi + # Check the history fields proportions are right if [ "${HISTORY_FIELD_UNITS[0]}" == "0" ] || [ "${HISTORY_FIELD_UNITS[2]}" == "0" ] then @@ -596,7 +606,7 @@ # Find the screen size T_LINES=$(tput lines) T_COLUMNS=$(tput cols) - # FIXME Request a minimal size or exit + # Find the maximum line and column T_LASTLINE=$(( T_LINES - 1 )) T_LASTCOLUMN=$(( T_COLUMNS - 1 )) |
|
From: Costin S. <cs...@us...> - 2006-11-30 21:12:35
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv7405 Modified Files: lastbash Log Message: Renamed the INFO_* variables to HISTORY_* Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.67 retrieving revision 1.68 diff -u -d -r1.67 -r1.68 --- lastbash 30 Nov 2006 21:08:25 -0000 1.67 +++ lastbash 30 Nov 2006 21:12:30 -0000 1.68 @@ -26,7 +26,7 @@ DEBUG="n" USE_PLAYER="y" HISTORY_SCROLL_DOWN="y" -INFO_FIELD_UNITS=(2 2 3) +HISTORY_FIELD_UNITS=(2 2 3) REFRESH_INTERVAL="30" PLAYER="auto" # $PLAYERS, auto AUTO_PLAY="y" @@ -146,11 +146,11 @@ debug "No missing programs." fi - # Check the info line proportions are right - if [ "${INFO_FIELD_UNITS[0]}" == "0" ] || [ "${INFO_FIELD_UNITS[2]}" == "0" ] + # Check the history fields proportions are right + if [ "${HISTORY_FIELD_UNITS[0]}" == "0" ] || [ "${HISTORY_FIELD_UNITS[2]}" == "0" ] then # Restore the defaults - INFO_FIELD_UNITS=(2 2 3) + HISTORY_FIELD_UNITS=(2 2 3) fi # Check and fix the refresh interval @@ -605,25 +605,25 @@ TSCROLL_LAST=$(( T_LASTLINE - 2 )) TSCROLL_CURRENT=${TSCROLL_FIRST} - # Set the info line field sizes + # Set the history line field sizes # The fixed-size fields are the following # - the love/ban indicator: 1 char # - the track duration: 6 chars # Plus: 1 char at start and end of line # Plus: 2 chars between fields (this is computed) # Find the total relative units - local UNITS_TOTAL=$(( ${INFO_FIELD_UNITS[0]} + ${INFO_FIELD_UNITS[1]} + ${INFO_FIELD_UNITS[2]} )) + local UNITS_TOTAL=$(( ${HISTORY_FIELD_UNITS[0]} + ${HISTORY_FIELD_UNITS[1]} + ${HISTORY_FIELD_UNITS[2]} )) # Find the variable line length local VAR_LINE=$(( ${T_COLUMNS} - 13 )) - [ "${INFO_FIELD_UNITS[0]}" != "0" ] && VAR_LINE=$(( ${VAR_LINE} - 2 )) - [ "${INFO_FIELD_UNITS[1]}" != "0" ] && VAR_LINE=$(( ${VAR_LINE} - 2 )) + [ "${HISTORY_FIELD_UNITS[0]}" != "0" ] && VAR_LINE=$(( ${VAR_LINE} - 2 )) + [ "${HISTORY_FIELD_UNITS[1]}" != "0" ] && VAR_LINE=$(( ${VAR_LINE} - 2 )) # Find the unit length local UNIT=$(( ${VAR_LINE} / ${UNITS_TOTAL} )) # Compute the sizes - INFO_FIELD_SIZE[0]=$(( ${UNIT} * ${INFO_FIELD_UNITS[0]} )) - INFO_FIELD_SIZE[1]=$(( ${UNIT} * ${INFO_FIELD_UNITS[1]} )) - INFO_FIELD_SIZE[2]=$(( ${VAR_LINE} - ${INFO_FIELD_SIZE[0]} - ${INFO_FIELD_SIZE[1]} )) - INFO_FIELD_SIZE[3]="6" + HISTORY_FIELD_SIZE[0]=$(( ${UNIT} * ${HISTORY_FIELD_UNITS[0]} )) + HISTORY_FIELD_SIZE[1]=$(( ${UNIT} * ${HISTORY_FIELD_UNITS[1]} )) + HISTORY_FIELD_SIZE[2]=$(( ${VAR_LINE} - ${HISTORY_FIELD_SIZE[0]} - ${HISTORY_FIELD_SIZE[1]} )) + HISTORY_FIELD_SIZE[3]="6" # Compute the current max line length TCURRENT_MAX=$(( ${T_COLUMNS} - 13 )) @@ -666,28 +666,28 @@ LINE=" ${LBL_ARTIST:0:1}" # Add the artist, if the field units are not null - if [ "${INFO_FIELD_UNITS[0]}" != "0" ] + if [ "${HISTORY_FIELD_UNITS[0]}" != "0" ] then - S="${INFO_FIELD_SIZE[0]}" + S="${HISTORY_FIELD_SIZE[0]}" printf -v FIELD " %-${S}s" "${LBL_ARTIST:0:$S}" LINE="${LINE}${FIELD}" fi # Add the album, if the field units are not null - if [ "${INFO_FIELD_UNITS[1]}" != "0" ] + if [ "${HISTORY_FIELD_UNITS[1]}" != "0" ] then - S="${INFO_FIELD_SIZE[1]}" + S="${HISTORY_FIELD_SIZE[1]}" printf -v FIELD " %-${S}s" "${LBL_ALBUM:0:$S}" LINE="${LINE}${FIELD}" fi # Add the track title - S="${INFO_FIELD_SIZE[2]}" + S="${HISTORY_FIELD_SIZE[2]}" printf -v FIELD " %-${S}s" "${LBL_TRACK:0:$S}" LINE="${LINE}${FIELD}" # Add the track duration - S="${INFO_FIELD_SIZE[3]}" + S="${HISTORY_FIELD_SIZE[3]}" printf -v FIELD " %${S}s " "${LBL_LENGTH:0:$S}" LINE="${LINE}${FIELD}" @@ -818,7 +818,7 @@ fi fi - # Display the info line + # Display the history line tui_history_line # Increment the current line number @@ -846,23 +846,23 @@ fi # Add the artist, if the field units are not null - if [ "${INFO_FIELD_UNITS[0]}" != "0" ] + if [ "${HISTORY_FIELD_UNITS[0]}" != "0" ] then - S="${INFO_FIELD_SIZE[0]}" + S="${HISTORY_FIELD_SIZE[0]}" printf -v FIELD " %-${S}s" "${PREV_ARTIST:0:$S}" LINE="${LINE}${FIELD}" fi # Add the album, if the field units are not null - if [ "${INFO_FIELD_UNITS[1]}" != "0" ] + if [ "${HISTORY_FIELD_UNITS[1]}" != "0" ] then - S="${INFO_FIELD_SIZE[1]}" + S="${HISTORY_FIELD_SIZE[1]}" printf -v FIELD " %-${S}s" "${PREV_ALBUM:0:$S}" LINE="${LINE}${FIELD}" fi # Add the track title - S="${INFO_FIELD_SIZE[2]}" + S="${HISTORY_FIELD_SIZE[2]}" printf -v FIELD " %-${S}s" "${PREV_TRACK:0:$S}" LINE="${LINE}${FIELD}" |
|
From: Costin S. <cs...@us...> - 2006-11-30 21:08:32
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv5744 Modified Files: lastbash Log Message: Some more required programs. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.66 retrieving revision 1.67 diff -u -d -r1.66 -r1.67 --- lastbash 30 Nov 2006 20:50:21 -0000 1.66 +++ lastbash 30 Nov 2006 21:08:25 -0000 1.67 @@ -61,7 +61,7 @@ # Internal stuff PLAYERS="mplayer" -REQ_PROGRAMS="rm tput md5sum dd" +REQ_PROGRAMS="rm date sleep tput md5sum dd chmod" declare -a HTTP_HEADERS HTTP_RESPONSE CR=$'\x0d' LF=$'\x0a' @@ -608,7 +608,7 @@ # Set the info line field sizes # The fixed-size fields are the following # - the love/ban indicator: 1 char - # - the track duration: 5 chars + # - the track duration: 6 chars # Plus: 1 char at start and end of line # Plus: 2 chars between fields (this is computed) # Find the total relative units @@ -1200,6 +1200,12 @@ # Return if no player is to be used [ "${USE_PLAYER}" == "y" ] || return + if type -t mkfifo >/dev/null 2>&1 + then + debug "No way to control the player, mkfifo is absent" + return + fi + # Set the status line tui_sbar "Starting the backend player..." @@ -1320,7 +1326,7 @@ then PID="$(< $PID_FILE)" # Check if we can send a signal to that process - if kill -0 $PID >/dev/null 2>&1 + if kill -0 "${PID}" >/dev/null 2>&1 then RET="1" else @@ -1461,6 +1467,7 @@ *) if [ "${KEY}" ] then + # FIXME this is executed after a remote call, too tui_keys sleep 3 tui_sbar @@ -1484,7 +1491,7 @@ case "$1" in "-a") AUTO_PLAY="y" ;; "-A") AUTO_PLAY="n" ;; - "-c") LASTFM_COMMAND="$1"; shift 1 ;; + "-c") LASTFM_COMMAND="$2"; shift 1 ;; "-d") DEBUG="y" ;; "-p") PLAYER="$2"; shift 1 ;; "-r") REFRESH_INTERVAL="$2"; shift 1 ;; @@ -1504,8 +1511,6 @@ if [[ "$1" =~ "^lastfm://" ]] then # This is the new station to tune into - # FIXME %escape the url - if first_instance then # Store the station to load after the init @@ -1528,7 +1533,7 @@ # Check if there is a command to execute if [ "${LASTFM_COMMAND}" ] then - remote_call "$1" + remote_call "${LASTFM_COMMAND}" exit 0 else # Nothing to do @@ -1570,7 +1575,7 @@ player_stop else # Wait for the user read the status and exit - read -n 1 -s -t ${REFRESH_INTERVAL} KEY + read -n 1 -s -t ${REFRESH_INTERVAL} JUNK fi # Restore the terminal |
|
From: Costin S. <cs...@us...> - 2006-11-30 20:51:04
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv30934 Modified Files: TODO Log Message: Some more done. Index: TODO =================================================================== RCS file: /cvsroot/lastbash/lastbash/TODO,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- TODO 30 Nov 2006 20:17:05 -0000 1.10 +++ TODO 30 Nov 2006 20:51:01 -0000 1.11 @@ -4,14 +4,14 @@ TODO - save a html file with album cover, links, etc. - maybe save a csv history file -- maybe mark the loved/banned/skipped tracks - implement the leds - add support for changing stations in interface - improve support for interface refresh (keep history) - add support for color and bw interface -- more commands per remote call DONE +- maybe mark the loved/banned/skipped tracks +- more commands per remote call - use 'tput' instead of plain ansi escape codes - add support for lastfm errors - when not streaming, clear the current data |
|
From: Costin S. <cs...@us...> - 2006-11-30 20:50:25
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv30882 Modified Files: lastbash Log Message: Multiple commands per call and locks during remote calls. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.65 retrieving revision 1.66 diff -u -d -r1.65 -r1.66 --- lastbash 30 Nov 2006 17:06:21 -0000 1.65 +++ lastbash 30 Nov 2006 20:50:21 -0000 1.66 @@ -57,10 +57,11 @@ DEBUG_FILE="${HOME_DIR}/lastbash.debug" PID_FILE="${HOME_DIR}/pid" COMMAND_FILE="${HOME_DIR}/command" +COMMAND_FILE_LOCK="${HOME_DIR}/command.lock" # Internal stuff PLAYERS="mplayer" -REQ_PROGRAMS="tput md5sum dd" +REQ_PROGRAMS="rm tput md5sum dd" declare -a HTTP_HEADERS HTTP_RESPONSE CR=$'\x0d' LF=$'\x0a' @@ -1333,18 +1334,25 @@ return "${RET}" } -# Function: Send a command to the running instance {{{1 +# Function: Send commands to the running instance {{{1 #----------------------------------------------------------------------------- function remote_call() { - # $1 - the command - - local PID + # $@ - the commands - # FIXME add locks - echo "$1" >> "${COMMAND_FILE}" - PID="$(< $PID_FILE)" - kill -HUP ${PID} + if [ -f "${COMMAND_FILE_LOCK}" ] + then + echo "Lockfile present, commands not sent" + else + # Create the lock + echo "$$" > "${COMMAND_FILE_LOCK}" + # Send the commands + echo "$@" >> "${COMMAND_FILE}" + # Remove the lock + rm -f "${COMMAND_FILE_LOCK}" + # Signal the first instance + kill -HUP "$(< $PID_FILE)" + fi } # Function: Execute arbitrary commands {{{1 @@ -1378,15 +1386,32 @@ { local CMD ARGS - # Set the status line - tui_sbar "Remote command received" + if [ -f "${COMMAND_FILE_LOCK}" ] + then + tui_sbar "Lockfile present, remote call ignored" + else + # Create the lock + echo "$$" > "${COMMAND_FILE_LOCK}" - # FIXME enable the read lock - read CMD ARGS < "${COMMAND_FILE}" - execute_command "${CMD}" "${ARGS}" + # Check the command file exists + if [ -f "${COMMAND_FILE}" ] + then + # Read the commands, one per line, and execute them + while read CMD ARGS + do + [ "${CMD}" ] && execute_command "${CMD}" "${ARGS}" + done < "${COMMAND_FILE}" - rm -f "${COMMAND_FILE}" - # FIXME disable the read lock + # Remove the command file + rm -f "${COMMAND_FILE}" + else + # There is no command file + tui_sbar "No commands to execute" + fi + + # Remove the lock + rm -f "${COMMAND_FILE_LOCK}" + fi # Restore the status bar sleep 1 @@ -1445,7 +1470,7 @@ ;; esac # Reset the key - KEY="" + unset KEY done } # }}}1 |
|
From: Costin S. <cs...@us...> - 2006-11-30 20:17:09
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv17645 Modified Files: TODO Log Message: Some more done. Index: TODO =================================================================== RCS file: /cvsroot/lastbash/lastbash/TODO,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- TODO 28 Nov 2006 17:33:16 -0000 1.9 +++ TODO 30 Nov 2006 20:17:05 -0000 1.10 @@ -7,13 +7,13 @@ - maybe mark the loved/banned/skipped tracks - implement the leds - add support for changing stations in interface -- add support for lastfm errors - improve support for interface refresh (keep history) - add support for color and bw interface -- use 'tput' instead of plain ansi escape codes - more commands per remote call DONE +- use 'tput' instead of plain ansi escape codes +- add support for lastfm errors - when not streaming, clear the current data - add support for interface refresh and resize - discovery on/off |
|
From: Costin S. <cs...@us...> - 2006-11-30 17:06:28
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv8008 Modified Files: lastbash Log Message: Reported version is 1.0 Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.64 retrieving revision 1.65 diff -u -d -r1.64 -r1.65 --- lastbash 30 Nov 2006 16:41:56 -0000 1.64 +++ lastbash 30 Nov 2006 17:06:21 -0000 1.65 @@ -45,7 +45,7 @@ # Some client settings CLIENT_PLATFORM="linux" -CLIENT_VERSION="0.1" +CLIENT_VERSION="1.0" # Files and directories HOME_DIR="${HOME}/.lastbash" |
|
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 |
|
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 |
|
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 |
|
From: Costin S. <cs...@us...> - 2006-11-30 15:02:28
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv25739 Modified Files: lastbash Log Message: tui_lastfm_connect check error Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.60 retrieving revision 1.61 diff -u -d -r1.60 -r1.61 --- lastbash 30 Nov 2006 14:43:20 -0000 1.60 +++ lastbash 30 Nov 2006 15:02:25 -0000 1.61 @@ -844,15 +844,40 @@ #----------------------------------------------------------------------------- function tui_lastfm_connect() { + local ERRCODE RET + # Set the status line tui_sbar "Connecting to Last.fm..." - # Connect + + # Try connecting lastfm_connect "${LASTFM_USER}" "${LASTFM_PASS}" - # Update the status line - tui_sbar "Connected" - sleep 1 - # Change the station, if required - [ "${LASTFM_STATION}" ] && tui_lastfm_station "${LASTFM_STATION}" + ERRCODE="$?" + + # Check the error code + if [ "${ERRCODE}" == "0" ] + then + # TODO Display the LASTFM_INFO_MESSAGE + RET="0" + # Update the status line + tui_sbar "Connected" + sleep 1 + # Change the station, if required + [ "${LASTFM_STATION}" ] && tui_lastfm_station "${LASTFM_STATION}" + elif [ "${ERRCODE}" == "2" ] + then + RET="2" + tui_sbar "Last.fm session failed, check credentials" + elif [ "${ERRCODE}" == "3" ] + then + RET="3" + tui_sbar "Player banned, contact the author" + else + RET="1" + tui_sbar "Last.fm handshake failed" + fi + + # Return the status code + return "${RET}" } # Function: TUI for changing station {{{1 @@ -1331,15 +1356,20 @@ tui_start # Next, connect to the Last.fm station -tui_lastfm_connect -# Start the player -player_start -# Get the initial metadata -tui_metadata -# Enter the readkey loop -read_key_loop -# Stop the player -player_stop +if tui_lastfm_connect +then + # Start the player + player_start + # Get the initial metadata + tui_metadata + # Enter the readkey loop + read_key_loop + # Stop the player + player_stop +else + # Wait for the user read the status and exit + read -n 1 -s -t ${REFRESH_INTERVAL} KEY +fi # Restore the terminal term_exit |
|
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 |
|
From: Costin S. <cs...@us...> - 2006-11-30 14:20:37
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv8885 Modified Files: lastbash Log Message: Fixed the debug header location. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.58 retrieving revision 1.59 diff -u -d -r1.58 -r1.59 --- lastbash 29 Nov 2006 15:01:32 -0000 1.58 +++ lastbash 30 Nov 2006 14:20:32 -0000 1.59 @@ -1212,14 +1212,8 @@ # The main part #----------------------------------------------------------------------------- -# Write the debug header -debug "------------------------------------------------" -debug " Debug started on `date`" -debug "------------------------------------------------" # Check commandline options -debug "Parsing the command line..." - while [ "${1:0:1}" = "-" ] do case "$1" in @@ -1236,6 +1230,11 @@ shift 1 done +# Write the debug header +debug "------------------------------------------------" +debug " Debug started on `date`" +debug "------------------------------------------------" + # This should be the Last.fm station if [[ "$1" =~ "^lastfm://" ]] then |
|
From: Costin S. <cs...@us...> - 2006-11-29 15:01:39
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31327 Modified Files: lastbash Log Message: The m3u playlist can contain more than 1 entry. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.57 retrieving revision 1.58 diff -u -d -r1.57 -r1.58 --- lastbash 29 Nov 2006 14:55:38 -0000 1.57 +++ lastbash 29 Nov 2006 15:01:32 -0000 1.58 @@ -202,11 +202,20 @@ # $3 - extinf name # $4 - file location / url - echo "#EXTM3U" > "$1" + # Keep the filename + local FILE="$1" + shift 1 - # TODO Add support for multiple items in playlist - echo "#EXTINF:$2,$3" >> "$1" - echo "$4" >> "$1" + # Output the header + echo "#EXTM3U" > "${FILE}" + + # Output the sets of 3 data: duration, name, location + while [ "$1" ] + do + echo "#EXTINF:$1,$2" >> "${FILE}" + echo "$3" >> "${FILE}" + shift 3 + done } # Function: HTTP GET method implementation {{{1 |
|
From: Costin S. <cs...@us...> - 2006-11-29 14:55:42
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv28756 Modified Files: lastbash Log Message: Use ncurses for colors and text attributes. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.56 retrieving revision 1.57 diff -u -d -r1.56 -r1.57 --- lastbash 29 Nov 2006 14:37:52 -0000 1.56 +++ lastbash 29 Nov 2006 14:55:38 -0000 1.57 @@ -423,14 +423,15 @@ T_BGCOLOR_MAGENTA="$(tput setab 5)" T_BGCOLOR_CYAN="$(tput setab 6)" T_BGCOLOR_WHITE="$(tput setab 7)" + T_COLOR_NORMAL="$(tput op)" # Define attributes - T_BOLD="$(tput bold)" - T_REV="$(tput rev)" - T_BLINK="$(tput blink)" - T_INVIS="$(tput invis)" - T_ULINE="$(tput smul)" - T_NORMAL="\e[0m" + T_ATTR_BOLD="$(tput bold)" + T_ATTR_REV="$(tput rev)" + T_ATTR_BLINK="$(tput blink)" + T_ATTR_INVIS="$(tput invis)" + T_ATTR_ULINE="$(tput smul)" + T_ATTR_NORMAL="\e[0m" # Some more escape sequences T_EL="$(tput el)" @@ -521,7 +522,7 @@ printf -v H_LINE " %${S}s " "${PROG_TITLE} v${PROG_VER}" # Move the cursor on upper-left corner and print tput home - echo -ne "\e[0;37;44m${H_LINE}\e[0;39m\e[0;49m" + echo -ne "${T_COLOR_WHITE}${T_BGCOLOR_BLUE}${H_LINE}${T_COLOR_NORMAL}" } # Function: Display the history header {{{1 @@ -561,7 +562,7 @@ # Move the cursor and print tput cup 8 0 - echo -ne "\e[0;37;44m${LINE}\e[0;39m\e[0;49m" + echo -ne "${T_COLOR_WHITE}${T_BGCOLOR_BLUE}${LINE}${T_COLOR_NORMAL}" } @@ -597,7 +598,7 @@ fi # Move the cursor on lower-left corner and print tput cup ${T_LINES} 0 - echo -ne "\e[0;37;44m${LINE}\e[0;39m\e[0;49m" + echo -ne "${T_COLOR_WHITE}${T_BGCOLOR_BLUE}${LINE}${T_COLOR_NORMAL}" } # Function: Display the keys {{{1 @@ -609,7 +610,7 @@ # Move the cursor on lower-left corner and print tput cup ${T_LINES} 0 - echo -ne "\e[0;37;44m Keys: ${LINE}${T_EL}\e[0;39m\e[0;49m" + echo -ne "${T_COLOR_WHITE}${T_BGCOLOR_BLUE} Keys: ${LINE}${T_EL}${T_COLOR_NORMAL}" } # Function: Display the current metadata {{{1 @@ -618,19 +619,19 @@ { local LINE ACTION - printf -v LINE "\e[1m%7s\e[0m : %s" "${LBL_ARTIST}" "${META_ARTIST:0:$TCURRENT_MAX}" + printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_ARTIST}" "${META_ARTIST:0:$TCURRENT_MAX}" tput cup 2 2 echo -ne "${LINE}${T_EL}" - printf -v LINE "\e[1m%7s\e[0m : %s" "${LBL_TRACK}" "${META_TRACK:0:$TCURRENT_MAX}" + printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_TRACK}" "${META_TRACK:0:$TCURRENT_MAX}" tput cup 3 2 echo -ne "${LINE}${T_EL}" - printf -v LINE "\e[1m%7s\e[0m : %s" "${LBL_ALBUM}" "${META_ALBUM:0:$TCURRENT_MAX}" + printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_ALBUM}" "${META_ALBUM:0:$TCURRENT_MAX}" tput cup 4 2 echo -ne "${LINE}${T_EL}" - printf -v LINE "\e[1m%7s\e[0m : %d:%02d" "${LBL_LENGTH}" "${META_MIN}" "${META_SEC}" + printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %d:%02d" "${LBL_LENGTH}" "${META_MIN}" "${META_SEC}" tput cup 5 2 echo -ne "${LINE}${T_EL}" @@ -647,7 +648,7 @@ ACTION="" fi - printf -v LINE "\e[1m%7s\e[0m : %s" "${LBL_ACTION}" "${ACTION}" + printf -v LINE "${T_ATTR_BOLD}%7s${T_ATTR_NORMAL} : %s" "${LBL_ACTION}" "${ACTION}" tput cup 6 2 echo -ne "${LINE}${T_EL}" |
|
From: Costin S. <cs...@us...> - 2006-11-29 14:37:57
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21272 Modified Files: lastbash Log Message: First use of ncurses. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.55 retrieving revision 1.56 diff -u -d -r1.55 -r1.56 --- lastbash 29 Nov 2006 12:53:38 -0000 1.55 +++ lastbash 29 Nov 2006 14:37:52 -0000 1.56 @@ -60,7 +60,7 @@ # Internal stuff PLAYERS="mplayer" -REQ_PROGRAMS="md5sum dd" +REQ_PROGRAMS="tput md5sum dd" declare -a HTTP_HEADERS HTTP_RESPONSE CR=$'\x0d' LF=$'\x0a' @@ -402,13 +402,43 @@ function term_init() { # Enter special mode - echo -ne '\e[?1049h' + tput smcup # Set a welcome xterm title set_xterm "Welcome to ${PROG_TITLE}!" + + # Define colors + T_COLOR_BLACK="$(tput setaf 0)" + T_COLOR_RED="$(tput setaf 1)" + T_COLOR_GREEN="$(tput setaf 2)" + T_COLOR_YELLOW="$(tput setaf 3)" + T_COLOR_BLUE="$(tput setaf 4)" + T_COLOR_MAGENTA="$(tput setaf 5)" + T_COLOR_CYAN="$(tput setaf 6)" + T_COLOR_WHITE="$(tput setaf 7)" + T_BGCOLOR_BLACK="$(tput setab 0)" + T_BGCOLOR_RED="$(tput setab 1)" + T_BGCOLOR_GREEN="$(tput setab 2)" + T_BGCOLOR_YELLOW="$(tput setab 3)" + T_BGCOLOR_BLUE="$(tput setab 4)" + T_BGCOLOR_MAGENTA="$(tput setab 5)" + T_BGCOLOR_CYAN="$(tput setab 6)" + T_BGCOLOR_WHITE="$(tput setab 7)" + + # Define attributes + T_BOLD="$(tput bold)" + T_REV="$(tput rev)" + T_BLINK="$(tput blink)" + T_INVIS="$(tput invis)" + T_ULINE="$(tput smul)" + T_NORMAL="\e[0m" + + # Some more escape sequences + T_EL="$(tput el)" + # Set the initial terminal size related settings term_resize # Make cursor invisible - echo -ne '\e[?25l' # tput civis + tput civis } # Function: Exit the terminal {{{1 @@ -418,13 +448,13 @@ # Set a goodbye xterm title set_xterm "Thank you for flying ${PROG_TITLE}!" # Make sure to reset the scrolling area - echo -ne "\e[0;${T_LINES}r" + tput csr 0 ${T_LINES} # Move the cursor on upper-left corner and clear the entire screen - echo -ne "\e[H\e[2J" - # Make cursor visible - echo -ne '\e[?12;25h' # tput cvvis + tput clear + # Make cursor normal visible + tput cnorm # Exit special mode - echo -ne '\e[?1049l' + tput rmcup } # Function: Compute some lengths when the terminal has been resized {{{1 @@ -432,16 +462,15 @@ function term_resize() { # Find the screen size - STTY_SIZE=$(stty size) - T_LINES=${STTY_SIZE% *} - T_COLUMNS=${STTY_SIZE#* } + T_LINES=$(tput lines) + T_COLUMNS=$(tput cols) # FIXME Request a minimal size or exit T_LASTLINE=$(( T_LINES - 1 )) T_LASTCOLUMN=$(( T_COLUMNS - 1 )) # Scroll area related settings - TSCROLL_FIRST=11 - TSCROLL_LAST=$(( T_LINES - 2 )) + TSCROLL_FIRST=10 + TSCROLL_LAST=$(( T_LASTLINE - 2 )) TSCROLL_CURRENT=${TSCROLL_FIRST} # Set the info line field sizes @@ -473,7 +502,7 @@ function tui_start() { # Move the cursor on upper-left corner and clear the entire screen - echo -ne "\e[H\e[2J" + tput clear # Display the main parts tui_header @@ -491,7 +520,8 @@ # Format the header line printf -v H_LINE " %${S}s " "${PROG_TITLE} v${PROG_VER}" # Move the cursor on upper-left corner and print - echo -ne "\e[H\e[0;37;44m${H_LINE}\e[0;39m\e[0;49m" + tput home + echo -ne "\e[0;37;44m${H_LINE}\e[0;39m\e[0;49m" } # Function: Display the history header {{{1 @@ -530,7 +560,8 @@ LINE="${LINE}${FIELD}" # Move the cursor and print - echo -ne "\e[9;0H\e[0;37;44m${LINE}\e[0;39m\e[0;49m" + tput cup 8 0 + echo -ne "\e[0;37;44m${LINE}\e[0;39m\e[0;49m" } @@ -565,7 +596,8 @@ printf -v LINE " %-${S}s %-15s [%s] " "Not streaming" "$LASTFM_USER" "$LEDS" fi # Move the cursor on lower-left corner and print - echo -ne "\e[${T_LINES};0H\e[0;37;44m${LINE}\e[0;39m\e[0;49m" + tput cup ${T_LINES} 0 + echo -ne "\e[0;37;44m${LINE}\e[0;39m\e[0;49m" } # Function: Display the keys {{{1 @@ -576,7 +608,8 @@ printf -v LINE " \e[1;44m%1s\e[0;44m %s " "R" "Refresh" "L" "Love" "B" "Ban" "K" "Skip" "P" "RTP" "D" "Discovery" "Q" "Quit" # Move the cursor on lower-left corner and print - echo -ne "\e[${T_LINES};0H\e[0;37;44m Keys: ${LINE}\e[K\e[0;39m\e[0;49m" + tput cup ${T_LINES} 0 + echo -ne "\e[0;37;44m Keys: ${LINE}${T_EL}\e[0;39m\e[0;49m" } # Function: Display the current metadata {{{1 @@ -586,16 +619,20 @@ local LINE ACTION printf -v LINE "\e[1m%7s\e[0m : %s" "${LBL_ARTIST}" "${META_ARTIST:0:$TCURRENT_MAX}" - echo -ne "\e[3;2H${LINE}\e[K" + tput cup 2 2 + echo -ne "${LINE}${T_EL}" printf -v LINE "\e[1m%7s\e[0m : %s" "${LBL_TRACK}" "${META_TRACK:0:$TCURRENT_MAX}" - echo -ne "\e[4;2H${LINE}\e[K" + tput cup 3 2 + echo -ne "${LINE}${T_EL}" printf -v LINE "\e[1m%7s\e[0m : %s" "${LBL_ALBUM}" "${META_ALBUM:0:$TCURRENT_MAX}" - echo -ne "\e[5;2H${LINE}\e[K" + tput cup 4 2 + echo -ne "${LINE}${T_EL}" printf -v LINE "\e[1m%7s\e[0m : %d:%02d" "${LBL_LENGTH}" "${META_MIN}" "${META_SEC}" - echo -ne "\e[6;2H${LINE}\e[K" + tput cup 5 2 + echo -ne "${LINE}${T_EL}" if [ "${META_ACTION_LOVE}" ] then @@ -611,7 +648,8 @@ fi printf -v LINE "\e[1m%7s\e[0m : %s" "${LBL_ACTION}" "${ACTION}" - echo -ne "\e[7;2H${LINE}\e[K" + tput cup 6 2 + echo -ne "${LINE}${T_EL}" # Set the xterm title if [ "${META_STREAMING}" == "true" ] @@ -627,24 +665,24 @@ function tui_history() { # Define the scroll area - echo -ne "\e[${TSCROLL_FIRST};${TSCROLL_LAST}r" + tput csr ${TSCROLL_FIRST} ${TSCROLL_LAST} if [ "${HISTORY_SCROLL_DOWN}" == "y" ] then # Move the cursor on the first line of the scrolling area - echo -ne "\e[${TSCROLL_FIRST};0H" + tput cup ${TSCROLL_FIRST} 0 # Scroll down one line - echo -ne "\eM" + tput il1 else if [ ${TSCROLL_CURRENT} -gt ${TSCROLL_LAST} ] then # Move the cursor on the last line of the scrolling area - echo -ne "\e[${TSCROLL_LAST};0H" + tput cup ${TSCROLL_LAST} 0 # Scroll up one line - echo -ne "\x0A" + tput ind else # Move the cursor on the current line - echo -ne "\e[${TSCROLL_CURRENT};0H" + tput cup ${TSCROLL_CURRENT} 0 fi fi @@ -655,7 +693,7 @@ (( TSCROLL_CURRENT++ )) # Restore the whole screen as scrolling area - echo -ne "\e[0;${T_LINES}r" + tput csr 0 ${T_LINES} } # Function: Display the line in history area {{{1 |
|
From: Costin S. <cs...@us...> - 2006-11-29 12:53:50
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11520 Modified Files: lastbash Log Message: Enter and leave terminal special mode. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.54 retrieving revision 1.55 diff -u -d -r1.54 -r1.55 --- lastbash 29 Nov 2006 12:32:41 -0000 1.54 +++ lastbash 29 Nov 2006 12:53:38 -0000 1.55 @@ -401,12 +401,14 @@ #----------------------------------------------------------------------------- function term_init() { + # Enter special mode + echo -ne '\e[?1049h' # Set a welcome xterm title set_xterm "Welcome to ${PROG_TITLE}!" # Set the initial terminal size related settings term_resize # Make cursor invisible - echo -en '\e[?25l' # tput civis + echo -ne '\e[?25l' # tput civis } # Function: Exit the terminal {{{1 @@ -420,7 +422,9 @@ # Move the cursor on upper-left corner and clear the entire screen echo -ne "\e[H\e[2J" # Make cursor visible - echo -en '\e[?12;25h' # tput cvvis + echo -ne '\e[?12;25h' # tput cvvis + # Exit special mode + echo -ne '\e[?1049l' } # Function: Compute some lengths when the terminal has been resized {{{1 |