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
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,497
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!

Last edited by johnraff (2012-04-12 12:00:30)


John
--------------------
( a boring Japan blog , and idle twitterings )

Offline

Help fund CrunchBang, donate to the project!

#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: PRC
Registered: 2009-07-02
Posts: 6,272
Website

Re: BBC radio programmes pipe menu

John,

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


Start Distrohopping here! -> Roast your ownVSIDO | LinuxCNC | AntiX | <-

Keep it what way?

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
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,497
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
--------------------
( a boring Japan blog , and idle twitterings )

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
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,497
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
--------------------
( a boring Japan blog , and idle twitterings )

Offline

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

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,497
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
--------------------
( a boring Japan blog , and idle twitterings )

Offline

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

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,497
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
--------------------
( a boring Japan blog , and idle twitterings )

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
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,497
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
--------------------
( a boring Japan blog , and idle twitterings )

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

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