SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-12-10 17:21:15

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 3,265
Website

BBC radio programmes pipe menu

This uses the excellent beebotron site which serves up all the available BBC "listen again" radio programmes in html files with links that most media players can use. This means you don't have to use the heavy flashbound iplayer. The full list is here: http://beebotron.org/index3lite.php but this script uses the music genre selection. Even that list is huge and would give you an enormous menu, so there's some filtering you should tweak to get the selections you want. Anyway, usage is like any pipe menu, dependencies - nothing special, though radiotray's nice. If you've got a slow internet connection downloading the 200KB file will slow the menu down quite a bit, so add '/path/to/beebotron.sh --refresh &' to your autostart file to get it out of the way. Anyway here it is:

#!/bin/bash
# beebotron.sh - a script to download a list of
# recent bbc radio programmes from beebotron.org
# and generate an openbox pipe menu
# version 12/04/11 added optional top menu items

# Usage: add
# <menu id="beebotron" label="BBC Music Programmes" execute="/path/to/beebotron.sh" />
# to your .config/openbox/menu.xml
# The first time it is run that day the cache file will be downloaded,
# which will make the menu slow to pop out. You can avoid that by adding:
# /path/to/beebotron.sh --refresh &
# to your openbox autostart(.sh) file.

# choose player for radio (see lines 45-47 below)
player=radiotray

# choose url to download
url=http://beebotron.org/public3/genremusic.html
# Other genres are: genrechildrens, genrecomedy, genredrama, genrefactual,
# genrelearning, genrenews, genrereligethics, genresport, genreweather
#  - substitute for genremusic above.
# If you live in the UK you can use the high quality links, which end with "hq"
# url=http://beebotron.org/public3/genremusichq.html

CACHE_FILE=$HOME/.cache/beebotron_music # where to keep the cache file
# (change name to match genre)

#######################################
## FILTERS using regular expressions ##
# If you don't filter the list the menu will be very long.
# Entry descriptions are in the html file, but not displayed in the menu.

# Any entries (including descriptions) matching the expression will be put at the top of the menu
# and further filters will be ignored.
#top='(^My Favourite Prog Title|^This Too)'
top='(^World on 3|^World Routes)'

# Any entries (including descriptions) matching the expression will be skipped.
#skip='([Bb]ach|[Bb]eethoven)'
#skip='a^' # nothing matches this
skip='(^1Xtra|^Breakfast|^C2|^The Early Show |^The Evening Show)'

# Any entries (including descriptions) NOT matching the expression will be skipped.
only='([Jj]azz|[Ww]orld|[Aa]sia|[Rr]eggae|[Bb]hangra|[Bb]lues|India|Pakistan|^Don Letts)'

#######################################

[[ $1 = "--refresh" || ! -f $CACHE_FILE || $(( $(date +%s) - $(stat -c %Z "$CACHE_FILE") )) -gt 86400 ]] && {
wget -q -O "$CACHE_FILE" "$url"
}
[[ $1 = "--refresh" ]] && exit

# start up radiotray in background if it's not already running
# Comment out this line if you don't use radiotray:
pgrep radiotray >/dev/null || { ( radiotray >/dev/null 2>&1 & ); sleep 1;}

awk -v TOP="$top" -v SKIP="$skip" -v ONLY="$only" -v PLAYER="$player" 'BEGIN {
    MENU=TOPMENU=""
    PRE="    <item label=\""
    MID="\">\n        <action name=\"Execute\"><command>" PLAYER " \""
    POST="\"</command></action>\n    </item>"
    RS="<a href=\""
    FS="\">"
}
/DOCTYPE/ {next}
/http:\/\/beebotron.org/ {exit}
# $1 is the url, $2 the name
$2 ~ TOP {
    sub(/<\/a>.*$/,"",$2)
    TOPMENU = TOPMENU "\n" PRE $2 MID $1 POST
    next
}
$2 ~ SKIP {next}
$2 !~ ONLY {next}
{
    sub(/<\/a>.*$/,"",$2)
    MENU = MENU "\n" PRE $2 MID $1 POST
}
END {print ("<openbox_pipe_menu>" TOPMENU "\n    <separator/>" MENU "\n</openbox_pipe_menu>")}
' "$CACHE_FILE"

exit

Hope you like it. smile

edit 2012/4/5 The BBC's urls seem to have changed, (temporarily?) breaking the script (and the beebotron) for international users. See post below.
edit 2012/4/12 The url issue seems to be OK now. Either the BBC got their act together or Kronalias at the Beebotron fixed it. The script has also been updated - now you can add a top menu section for favourites.

Don't forget to edit the filters to suit your own tastes!

EDIT 121015 See new version below for recording option.

Last edited by johnraff (2013-10-15 13:38:51)


John     Please help us keep your forums manageable.
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

Be excellent to each other!

#2 2011-12-10 17:27:50

kowloonboy
#! Junkie
Registered: 2011-10-13
Posts: 443

Re: BBC radio programmes pipe menu

This is so cool. Thanks smile


"To me, the extraordinary aspect of martial arts lies in its simplicity. The easy way is also the right way, and martial arts is nothing at all special; the closer to the true way of martial arts, the less wastage of expression there is." - Bruce Lee

Offline

#3 2011-12-10 17:31:32

machinebacon
#! unstable
From: China
Registered: 2009-07-02
Posts: 6,825
Website

Re: BBC radio programmes pipe menu

John,

thank you, thank you, it works and it's great! I love your scripts smile


Sweaty lads picking up the soap | I love the new "Ignore user" button

Offline

#4 2011-12-11 14:46:04

saturn9
Member
From: Lancashire, UK
Registered: 2008-12-02
Posts: 47

Re: BBC radio programmes pipe menu

Great script (as ever).

Many thanks.

Offline

#5 2011-12-12 17:06:53

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 3,265
Website

Re: BBC radio programmes pipe menu

At least half the credit to the guy that runs that beebotron site.
(but thanks anyway smile )


John     Please help us keep your forums manageable.
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#6 2011-12-16 13:38:05

Kronalias
New Member
Registered: 2011-12-16
Posts: 1

Re: BBC radio programmes pipe menu

Nice work, Johnraff!

And thanks for the thanks wink

All the best, Kronalias (author of the Beebotron)

Offline

#7 2011-12-16 17:51:14

saturn9
Member
From: Lancashire, UK
Registered: 2008-12-02
Posts: 47

Re: BBC radio programmes pipe menu

Thanks for your work as well Kronalias!

Top stuff.

Offline

#8 2011-12-17 17:05:10

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 3,265
Website

Re: BBC radio programmes pipe menu

Hi Kronalias! A great service you're providing there. I've been using it a while now - since the days of realplayer links.

...and welcome to Crunchbang smile


John     Please help us keep your forums manageable.
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#9 2012-04-04 16:36:16

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 3,265
Website

Re: BBC radio programmes pipe menu

The BBC seem to have changed something, and the urls that the Beebotron fetches no longer work for international listeners. See here. A couple of workarounds came up in that thread, but lets see if things stabilize a bit and then I'll try and rehack the script if necessary.


John     Please help us keep your forums manageable.
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#10 2012-04-12 12:06:01

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 3,265
Website

Re: BBC radio programmes pipe menu

^That issue seems to be fixed now, needing no hacks at this end. I celebrated by updating the script a little. Got fed up with having to scroll down to the bottom of the menu to get to my favourite programmes "World Routes" and "World on 3" so added the option of putting some selected items at the top. smile

(Also moved some of the code from bashzone to awkzone and got a 30% speedup. Awk is fast.)


John     Please help us keep your forums manageable.
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#11 2012-04-15 12:20:19

UkDkDe
Member
Registered: 2009-05-08
Posts: 47

Re: BBC radio programmes pipe menu

@Johnraff

Has the cache structure changed since beebotron service stopped and restarted?
How does the filter work? I used to have the filter expression:

# Any entries not matching the expression will be skipped.
only='([Hh]istory|[Ss]cience|[Nn]ature)'

I am sure I get different results now; and looking at the cache I cant work out what this expression would act
on, since the cache entries appear to be short synopsis of the programme rather than the genre (sub-)categories
The above filter was designed on the categories which get-iplayer delivers; and I am sure, used to deliver a correct menu list. To be honest, I cant actually rember the whether I studied the cache structure before.

Is the only filter now available the actual programme name, as in the script example
top='(^World on 3|^World Routes)' because only='([Jj]azz|[Ww]orld|[Aa]sia|[Rr]eggae|) type filtering only seems to be effective if the synopsis contains the Key words

Offline

#12 2012-04-17 11:01:00

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 3,265
Website

Re: BBC radio programmes pipe menu

Hi UkDkDe, no nothing's changed with the beebotron service afaik, and in the script, a little code was moved from bash to awk, and an extra option for "top" menu items added. My menu seems to be working fine.

The cache file is just the html as downloaded. Apart from the stuff at the top and bottom, each entry looks like this:

<a href="http://www.bbc.co.uk/mediaselector/4/asx/b01g4mxg/iplayer_intl_stream_wma_lo_concrete">100% HomeGrown with DJ Target, DJ Cameo&#39;s Lyrical Master and Nicky Blackmarket D&amp;B mix</a> - Cameo is in to chat about Lyrical Master - get online fast if you&#39;re the next big thing! [5 days 12 hours]<br>

So the part between <a href="blahblahblah"> and </a> is used as the menu title, and the description after that is thrown away, though both the title and desription are checked against the regular expression filters.

Three filters are available as before:
top - matching entries go in the top menu section even if they match the 'skip' filter, and regardless of whether they're included in the 'only' filter.
skip - matching entries are skipped, even if they match the 'only' filter.
only - entries which don't match are skipped.

I'm not sure if the 'skip' filter is any use really - I thought skipping certain entries like '^1Xtra' at the beginning of the string would speed things up by avoiding checking for possible 'only' matches the full length of the string, but it didn't seem to make much difference to the execution time. But it does no harm.

Don't forget, the caret ^ anchors the expression to the beginning, so '^1Xtra' matches '1Xtra music' but not 'Music on 1Xtra'.

The only other thing I wonder is if you set the download url to the genre you want. The default is genremusic.html, which is unlikely to have many results for a filter of only='([Hh]istory|[Ss]cience|[Nn]ature)' wink


John     Please help us keep your forums manageable.
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#13 2012-04-17 20:18:32

UkDkDe
Member
Registered: 2009-05-08
Posts: 47

Re: BBC radio programmes pipe menu

Hi Johnraff, been working through this and I understand where I am going wrong now
My original use of this script was just for comedy. I tried to extend it to factual.
My comedy genre version is unfiltered - produces an unfiltered pipemenu of circa 100 items
The factual version produces an enormous pipe menu (presumably almost the full cache) since the filter
only='([Hh]istory|[Ss]cience|[Nn]ature)' has no/little impact.

Reading through the cache of genrefactual, it looks like filtering down to sub-genres like Nature
or Science will not work.Sorry, my mistake; I thought beebotron was picking up the same sub-categories
as get-iplayer does eg.  (using your example above, the get_iplayer categorisation is)
"HomeGrown with DJ Target - WORLD EXCLUSIVE: BRAND NEW WILEY, BBC 1Xtra, Dance & Electronica,Drum & Bass,Experimental & New,Garage,Hip Hop R'n'B & Dancehall,Music,Radio"
which would allow a very targeted filter - in this case a "skip" filter smile
Nevertheleess, a super pipemenu for comedy , thank you!

Offline

#14 2013-10-15 13:36:58

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 3,265
Website

Re: BBC radio programmes pipe menu

New Version, with recording option

Now you can record a programme as well as listen to it. Uses ffmpeg. (See comments in script.)

#!/bin/bash
# beebotron.sh - a script to download a list of
# recent bbc radio programmes from beebotron.org
# and generate an openbox pipe menu
# version 12/04/11 added optional top menu items
# version 13/08/31 added recording option
# version 13/09/05 added some error checks
# requires curl, awk and ffmpeg (for recording)

# Usage: add this entry:
# <menu id="beebotron" label="BBC Music Programmes" execute="/path/to/beebotron.sh" />
# to your .config/openbox/menu.xml
# The first time it is run that day the cache file will be downloaded,
# which will make the menu slow to pop out. You can avoid that by adding:
# /path/to/beebotron.sh --refresh &
# to your openbox autostart(.sh) file.

# choose player for radio (radiotray will load new urls via dbus)
player=radiotray

# choose beebotron url to use
url=http://beebotron.org/public3/genremusic.html
# Other genres are: genrechildrens, genrecomedy, genredrama, genrefactual,
# genrelearning, genrenews, genrereligethics, genresport, genreweather
#  - substitute for genremusic above.
# If you live in the UK you can use the high quality links,
# which end with "hq" eg:
# url=http://beebotron.org/public3/genremusichq.html

cache_file=$HOME/.cache/beebotron_music # path to cache file
# (change name to match genre)

# RECORDING (needs ffmpeg to be installed)
recording='true' # 'true' to enable, any other value to disable recording
download_folder="$HOME/downloads/bbc" # store downloaded files here
# optional terminal to run ffmpeg in (see line 100)
terminal=urxvt # should support the -e option

#######################################

## FILTERS using regular expressions ##
# If you don't filter the list the menu will be very long.
# Entry descriptions are in the html file, but not displayed in the menu.

# Any entries (including descriptions) matching the expression
# will be put at the top of the menu and further filters will be ignored.
#top='(^My Favourite Prog Title|^This Too)'
top='(^World on 3|^World Routes|^Cerys on 6|^Don Letts|womad|WOMAD)'

# Any entries (including descriptions) matching the expression
# will be skipped.
#skip='([Bb]ach|[Bb]eethoven)'
#skip='a^' # nothing matches this
skip='(^Ace|^Beverley.*s World of Music|^Breakfast|^C2|^Chatback|^Chris Hawkins|^Composer of the Week|^Damien St|^Dress Circle|^Drivetime|^Graham Torrington|^Mornings |^Phil White|^Pipeline|^Rob da Bank|^Scott Mills |^Shaun Keaveny|^Simon Mayo |^Sue Davies|^The Early Show |^The Evening Show|^Through the Night|^Toddla T|^Tommy Sandhu)'

# Any entries (including descriptions) NOT matching the expression
# will be skipped.
keep='([Jj]azz|[Ww]orld|[Gg]lobal|[Aa]sia|[Aa]frica|[Rr]eggae|[Bb]hangra|[Bb]lues|r&b|R&B|[Rr]oots|[Ll]atin|India|Pakistan|Thai|Lao|Indonesia|Nathan Fake|Late Junction)'

##########################################################################
error_exit() {
    echo "$0 error: $1" >&2
    exit 1
}

[[ -t 0 ]] && {
    [[ $1 = '--debug' ]] && shift || {
        echo "This script is not intended to be called from a terminal.
Use the --debug option to overrule this behaviour.
Otherwise, see the comments in $0 for usage information"
        exit
    }
}

if [[ $recording = true ]]
then
    needed_apps='curl awk ffmpeg'
else
    needed_apps='curl awk'
fi
missing_apps=
for i in $needed_apps
do
    hash $i || missing_apps+=" $i"
done
[[ $missing_apps ]] && error_exit "Some necessary packages missing: $missing_apps"

[[ $1 = "--refresh" || ! -f $cache_file || $(( $(date +%s) - $(stat -c %Z "$cache_file") )) -gt 86400 ]] && {
curl -so "$cache_file" "$url" || error_exit "failed to download list from beebotron"
}
[[ $1 = "--refresh" ]] && exit

[[ $1 = "--record" ]] && {
    [[ $2 && $3 ]] || error_exit "not enough arguments for --record option"
    [[ $2 =~ ^http://(www|open\.live)\.bbc\.co\.uk(/[[:alnum:]_]+)+$ ]] || error_exit "url is not valid"
    prog_name="$3-$( date +%y%m%d )"
    mkdir -p "$download_folder" || error_exit "unable to make $download_folder"
    dl_file="$download_folder/$prog_name".wma
    stream_url=$( tr [[:upper:]] [[:lower:]] < <( curl -s $2 || error_exit "curl failed to fetch $2" ) | awk 'BEGIN{RS="<ref href=\"";FS="\"";}NR!=2{next}{sub(/^mms/,"mmsh",$1);print $1;}' )
    # remove '$terminal -e' from next line to run ffmpeg in background
    $terminal -e ffmpeg -i "$stream_url" -vn -acodec copy "$dl_file"
    exit
}

awk -v TOP="$top" -v SKIP="$skip" -v KEEP="$keep" -v PLAYER="$player" -v RECORDER="$0 --record" -v RECORDING="$recording" '
function submenu(name,url) {
    return "\
\n    <menu id=\"" name "\" label=\"" name "\">\
\n        <item label=\"PLAY\">\
\n            <action name=\"Execute\"><command>" PLAYER " \"" url "\"</command></action>\
\n        </item>\
\n        <item label=\"RECORD\">\
\n            <action name=\"Execute\"><command>" RECORDER " \"" url "\" \"" name "\"</command></action>\
\n        </item>\
\n    </menu>"
}
function item(name,url) {
    return "\
\n    <item label=\"" name "\">\
\n        <action name=\"Execute\"><command>" PLAYER " \"" url "\"</command></action>\
\n    </item>"
}

BEGIN {
    MENU=TOPMENU=""
    RS="<a href=\""
    FS="\">"
}
/DOCTYPE/ {next}
/http:\/\/beebotron.org/ {exit}
# $1 is the url, $2 the name+description
$2 ~ TOP {
    sub(/<\/a>.*$/,"",$2)
    if (RECORDING == "true") {
        TOPMENU = TOPMENU submenu($2, $1)
    }
    else {
        TOPMENU = TOPMENU item($2, $1)
    }
    next
}
$2 ~ SKIP {next}
$2 !~ KEEP {next}
{
    sub(/<\/a>.*$/,"",$2)
    if (RECORDING == "true") {
        MENU = MENU submenu($2, $1)
    }
    else {
        MENU = MENU item($2, $1)
    }
}
END {print ("<openbox_pipe_menu>" TOPMENU "\n    <separator/>" MENU "\n</openbox_pipe_menu>")}
' "$cache_file"

exit

John     Please help us keep your forums manageable.
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo