Skip to content

List of presets #50

@EastEriq

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

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