Skip to content

List of presets #50

Open
Open

Description

@EastEriq

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>"

Activity

  1. EastEriq commented on Jan 22, 2017

    @EastEriq
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions