philsmd / sharpfin

Sharpfin: update, patch, modify the firmware of your internet radio
GNU General Public License v3.0
18 stars 11 forks source link

List of presets #50

Open EastEriq opened 8 years ago

EastEriq commented 8 years ago

The attached script works on my radio; if saved as /mnt/debug/webserver/cgi-bin/radio_List_presets.cgi it naturally appears in the left frame of the welcome screen. Cosmetics may be improved, if you like it as a contribution, take.

Ref: http://iradioforum.net/forum/index.php?topic=2127.msg18979#msg18979

#!/bin/ash

cd /root/config

cat <<- HEADER
    Content-Type text/html

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Presets list</title>

    <style type="text/css">
      table {border-collapse: collapse;}
      td {border-top: 1px solid black; padding-right: 1.5em}
      td.num {text-align: right; border-right: 1px solid black;}
      td.station {font-weight: bold; padding-left: 1em}
      td.freq {font-weight: bold; text-align: right; padding-left: 1em}
      a {text-decoration: none; border-bottom: 1px dotted #BBBBBB;}
      a:hover {border-bottom: 1px solid;background-color: #CBCBBB;}
    </style>
    </head>

    <body>
    <h1>Presets:</h1>

    <h2>Internet Radio</h2>

    <table>
    <tr><th>Preset</th>
        <th style="text-align: left; padding-left: 1em;">Name</th>
        <th style="text-align: left;">URL</th></tr>
HEADER

IRPRESETS=`ls preset[0-9]*.xml| grep -o "[0-9]\+" |sort -n`
BOOKMARKS=`ls bookmark[0-9]*.xml | grep -o "[0-9]\+" |sort -n`
FMPRESETS=`ls fm_preset[0-9]*.txt| grep -o "[0-9]\+" |sort -n`

for i in $IRPRESETS
do
    STATION=`grep -o -m 1 "<title>[^<]*</title>" preset$i.xml |\
             sed -e "s/<[^>]*>//g"`
    STREAMURL=`grep -o -m 1 "<url>[^<]*</url>" preset$i.xml |\
             sed -e "s/<[^>]*>//g"`
    echo -e "<tr><td class=\"num\">$i</td>\n" \
            "<td class=\"station\">$STATION</td>\n" \
            "<td><a href=\"$STREAMURL\">$STREAMURL</a></td></tr>"
done

cat <<-MID1
    </table>

    <h2>Bookmarks</h2>

    <table>
MID1

for i in $BOOKMARKS
do
    STATION=`grep -o -m 1 "<title>[^<]*</title>" bookmark$i.xml |\
             sed -e "s/<[^>]*>//g"`
    STREAMURL=`grep -o -m 1 "<url>[^<]*</url>" bookmark$i.xml |\
             sed -e "s/<[^>]*>//g"`
    echo -e "<tr><td class=\"num\">$i</td>\n" \
            "<td class=\"station\">$STATION</td>\n" \
            "<td><a href=\"$STREAMURL\">$STREAMURL</a></td></tr>"
done

cat <<-MID2
    </table>

    <h2>FM</h2>

    <table>
    <tr><th>Preset</th><th>kHz</th></tr>
MID2

for i in $FMPRESETS
do
      FREQ=`tail +1 fm_preset$i.txt`
      echo "<tr><td class=\"num\">$i</td><td class=\"freq\">$FREQ</td></tr>"
done
echo -e "</table>\n\n</body>\n</html>"
EastEriq commented 7 years ago

Update: this is how far I've got for a tentative page handling presets. It interacts with the radio (one way) giving lirc commands. Nothing great, but being some 5 years late in the game... A more clever implementation could avoid refreshing the whole page (recalling the same cgi), which takes some seconds and kB of traffic, when buttons are pressed.

handle_presets.ZIP

Uses the script preset, included in the zip, which I dropped in /usr/sbin/.

Also included is an aborted attempt to command the spinner automatically entering a given string. Absolutely vane, only for future memory.