Another release of beeb which takes it to even greater heights! :) And just as an experiment I'm "self-hosting" the 'tar.gz' file so that it can be downloaded from here.

Documentation

This is the documentation for beeb [version 4.0] the all-singing, all-dancing, upgrade to get-iplayer!

The BBC has some superb radio and TV programmes, some of which can be downloaded using get-iplayer, and then can be played with your choice of viewer. This script will -

  • Check to see if you have get-iplayer/get_iplayer installed. If not it will prompt you to install it.
  • Creates the directory where the 'beeb-tv.txt & beeb-radio.txt' files are stored.
  • Downloads the current radio programme feed,
  • Allows you to put the programme numbers in to download, and tell you how much more you can download in this session,
  • Downloads the programmes and saves as *.mp3,
  • Asks you to put any further programme numbers in to download, and tells you how much more you can download in this session,
  • Asks you if you want to create a playing list of the radio programmes that can then be used by MPD.
  • Then downloads the current TV programme feed,
  • Allows you to put the programme numbers in to download, and tell you how much more you can download in this session,
  • Asks you to put any further programme numbers in to download, and tell you how much more you can download in this session,
  • Downloads the programmes,
  • Asks you if you would like to delete any of the 'beeb' downloads which are older than 30 days. If you answer "y" to this, it is DESTRUCTIVE and you will LOSE some programmes.
  • The script will quit and unload itself if left unattended and not downloading anything for thirty minutes. You might have gone to bed leaving it downloading some programmes, but when you go back to it in the morning, all connections to it are broken.

But before any of this can happen you need to configure it all, and this is done using '.beebrc' which should be saved to your "/home/$USER" directory. In '.beebrc' you can see the paths to my various directories, which will give you an idea of what should go where in your setup. So if you open '.beebrc' in your favourite text editor, then change these lines -

  tvsite="where the downloaded tv programmes are to be stored"  
  music="where your main music library is stored"  
  radiosite="where the downloaded radio programmes are to be stored"  
  beebradio="the playlist of your downloaded radio programmes"

Then to run 'beeb' from the terminal, you need to place it somewhere in your executable pathway, maybe home/$USER/bin' or '/usr/local/bin' and then just put 'beeb' in your terminal and follow the questions that it gives you.

Required

get-iplayer

The prime requirement of this script is the programme 'get-iplayer' which is in most linux distributions. Without it, the script will not function!

Hints

  • There is no need to press ENTER to proceed, just answer "y, n, q or r". The only time you need to press ENTER is when you are inputting programme numbers.
  • The "r" command will restart the script from the beginning, just in case you need it.
  • The programme listings for both radio and tv will be found at "home/$USER.beeb/"
  • Don't let ~/.get-iplayer/download/history get too big as it will cause problems in your downloading, like being very slow, or causing the programme to drop the connection.
  • If the programme appears to hang, it may be trying to reconnect, or have just crashed, in which case, you will have to run 'beeb' again with the same input as you used before.
  • If you do need to break out of 'beeb', for whatever reason, you can either answer 'q' when you're prompted for it, or just press 'CONTROL C' to crash out.
  • To access ~/.beeb to read 'beeb-radio.txt' or 'beeb-tv.txt' just enter 'cd $HOME/beeb' which auto-opens it at the prompt. Then you can use '$EDITOR beeb-radio.txt' or '$EDITOR beeb-tv.txt' to display either of the files. $EDITOR is your choice of text editor.
  • You will find that the script silently creates a file called 'touch.m4a' which is needed when creating the MPD playlist. This file has zero content and poses no threat to you or your computer, and should be left in place. If you do delete it, then the script will crash whilst creating the MPD playlist, so please leave it in place as it is needed.

The legalities

Please note, I am not a lawyer, and this section is created using internet sources.

'get-iplayer' is only supposed to be used in the UK, if you do manage to use it outside the UK, then good luck to you but you will be unable to get any support for it. And to use it in the UK you should also have a UK TV licence too. Any files downloaded with 'get-iplayer', or this script, should only be kept for 30 days before being deleted.

Any problems, or further instruction required, please let me know at my email address.

Changelog

4.0 (14-04-2014)

  • Now gives the ability to restart the script from wherever you are.
  • Now gives the ability to delete content older than 30 days.
  • Script quits if left unattended and not downloading for 30 minutes.

3.1 (16-02-2014)

  • Faulty packaging, did not contain all necessary files, therefore repackaged.

3.0 (16-02-2014)

  • Now downloads all the radio programmes as *.mp3

2.8 (11-02-2014)

  • Moved mpd feed update question to just after radio programmes download, where its placement seems more logical.

2.7 (06-02-2014)

  • Updated documentation to reflect the current legal situation, as I understand it.

2.5 (28-01-2014)

  • Checks to see if get-iplayer/get_iplayer is installed. Then runs with whichever is found.

2.0 (26-01-2014)

  • Changed configuration to create ~/.beeb and store feeds in it.

1.5 - and earlier

  • Changed 'beeb.conf' to '.beebrc'

Source code

And now the source code itself -

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/env bash
set -e
#: Title            : beeb
#: Date             : 14 April 2014
#: Version          : 4.0
#: Description      : To work with get-iplayer and use small scripts to download  
#:                  : BBC programmes
#; Requirements     : get-iplayer
#: Uses '.beebrc' saved at $HOME/.beebrc

# Copyright (C) 2014  Sharon Kimble 
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
####################################################
trap "kill -- -$BASHPID" EXIT
function ask {
    while true; do

        if [ "${2:-}" = "Y" ]; then
            prompt="Y/n"
            default=Y
        elif [ "${2:-}" = "N" ]; then
            prompt="y/N"
            default=N
        else
            prompt="y/n"
            default=
        fi

        # Ask the question
        read -p "$1 [$prompt] " REPLY

        # Default?
        if [ -z "$REPLY" ]; then
            REPLY=$default
        fi

        # Check if the reply is valid
        case "$REPLY" in
            Y*|y*) return 0 ;;
            N*|n*) return 1 ;;
        esac

    done
}
function ask2 {
    n=$1                    # the limit on the input length (<1000)
    if [ -z "$2" ] ; then   # the name of variable to hold the input
        echo "Usage $0:  ";
       return 2;
    fi
    result="" # temporary variable to hold the partial input
    while $(true); do
        printf '[%03d] > %s' "$n" "$result"
        stty cbreak
        REPLY=$(dd if=/dev/tty bs=1 count=1 2> /dev/null)
        stty -cbreak

        test "$REPLY" == "$(printf '\n')" && {
             printf "\n"
             eval "$2=\"$result\""
             return 0
        }
        test "$REPLY" == "$(printf '\177')" && {
             # On my terminal 0x7F is the erase character
             result=${result:0:-1}
             (( n = $n + 1 ))
             printf "\r\033[K"
             continue
         }

    result="${result}$REPLY"
        (( n = $n - 1 ))
        if [ $n -eq 0 ] ; then
           printf "\n"
           eval "$2=\"$result\""
           return 1
        fi
        printf "\r\033[K" # to clear the line
    done
}

txtbld=$(tput bold)
bldgrn=${txtbld}$(tput setaf 5) 
tvfeed="$HOME/.beeb/beeb-tv.txt"
radiofeed="$HOME/.beeb/beeb-radio.txt"
beeb="/usr/local/bin/beeb"
source ~/.beebrc

if [[ -x "/usr/bin/get-iplayer" ]]
then player="/usr/bin/get-iplayer"
elif [[ -x "/usr/bin/get_iplayer" ]]
then player="/usr/bin/get_iplayer"
elif [[ -x "/usr/local/bin/get_iplayer" ]]
then player="/usr/local/bin/get_iplayer"
else echo "$0: Error: 'get-iplayer' or 'get_iplayer' is not installed.  
    Please install it." >&2
     exit 1
fi

if [ -d "$radiosite/touch.m4a" ]
then
    echo;
else
    touch "$radiosite"/touch.m4a; echo;
fi

if [ -d "$HOME/.beeb" ]
then
    echo ;
else
echo "$(tput setaf 1) $(tput setab 7) Error: Directory $HOME/.beeb does not  
     exist $(tput sgr0)"
     read -n1 -p ""$bldgrn" Do you want to create the '$HOME/.beeb'  
     directory? [y/n/q] $(tput sgr0)" ynq
    case "$ynq" in
        [Yy]* ) mkdir $HOME/.beeb; touch "$tvfeed"; touch "$radiofeed"; echo;;
        [Nn]* ) echo; exit;;
        [Qq]* ) echo; exit;;
        * ) echo ""$bldgrn" Please answer yes or no. $(tput sgr0)";;
    esac
fi

 {
 read -t 1800 -n1 -p ""$bldgrn" Do you want to update the radio  
        feed? [y/n/q/r] $(tput sgr0)" ynqr
    case "$ynqr" in
        [Yy]* ) rm "$radiofeed"; eval "$player" --type radio >>"$radiofeed";;
        [Nn]* ) echo;;
        [Qq]* ) echo; exit;;
        [Rr]* ) exec "$beeb";;
        * ) echo ""$bldgrn" Please answer yes or no. $(tput sgr0)";;
    esac
 };
echo;
{
read -t 1800 -n1 -p ""$bldgrn" Do you want to download some radio  
    programmes? [y/n/q/r] $(tput sgr0)" ynqr ;
    case "$ynqr" in
        [Yy]) echo
        echo ""$bldgrn" Please input the radio programme numbers  
              to download [max 200 characters] $(tput sgr0)"
              ask2 200 'radiobox'
              echo "$radiobox"
              echo
              cd "$radiosite"
              eval "$player" --g "$radiobox" --aactomp3; echo;;
        [Nn]) echo;;
        [Qq]) echo; exit;;
        [Rr]) exec "$beeb";;
        * ) echo ""$bldgrn" Thank you $(tput sgr0)";;
    esac
  };
echo;
{
read -t 1800 -n1 -p ""$bldgrn" Do you want to download some more  
      radio programmes? [y/n/q/r] $(tput sgr0)" ynqr ;
    case "$ynqr" in
        [Yy]) echo
        echo ""$bldgrn" Please input the radio programme numbers to   
              download [max 200 characters] $(tput sgr0)"
              ask2 200 'radiobox'
              echo "$radiobox"
              echo
              cd "$radiosite"
              eval "$player" --g "$radiobox" --aactomp3; echo;;
        [Nn]) echo;;
        [Qq]) echo; exit;;
        [Rr]) exec "$beeb";;
        * ) echo ""$bldgrn" Thank you $(tput sgr0)";;
    esac
  };
echo;
{
read -t 1800 -n1 -p ""$bldgrn" Do you want to update the mpd  
        feed? [y/n/q/r] $(tput sgr0)" ynqr
    case "$ynqr" in
        [Yy]* ) cd "$music"
                rm "$beebradio"
                ls -1 "$radiosite"*.{mp3,m4a} >"$beebradio"
                echo;;
        [Nn]* ) echo;;
        [Qq]* ) echo; exit;;
        [Rr]* ) exec "$beeb";;
        * ) echo ""$bldgrn" Please answer yes or no. $(tput sgr0)";;
    esac
};
echo;
{
read -t 1800 -n1 -p ""$bldgrn" Do you want to update the tv  
          feed? [y/n/q/r] $(tput sgr0)" ynqr
    case "$ynqr" in
        [Yy]* ) rm "$tvfeed"; eval "$player" --type tv >>"$tvfeed";;
        [Nn]* ) echo;;
        [Qq]* ) echo; exit;;
        [Rr]* ) exec "$beeb";;
        * ) echo ""$bldgrn" Please answer yes or no. $(tput sgr0)";;
    esac
 };
echo;
{
read -t 1800 -n1 -p ""$bldgrn" Do you want to download some tv   
    programmes? [y/n/q/r] $(tput sgr0)" ynqr ;
    case "$ynqr" in
        [Yy]) echo
        echo ""$bldgrn" Please input the tv programme numbers to  
             download [max 200 characters] $(tput sgr0)"
              ask2 200 'tvbox'
              echo "$tvbox"
              echo
              cd "$tvsite"
              eval "$player" -g "$tvbox"
              echo;;
        [Nn]) echo;;
        [Qq]) echo; exit;;
        [Rr]) exec "$beeb";;
        * ) echo ""$bldgrn" Thank you $(tput sgr0)";;
    esac
 };
echo;
{
read -t 1800 -n1 -p ""$bldgrn" Do you want to download some more tv  
           programmes? [y/n/q/r] $(tput sgr0)" ynqr ;
    case "$ynqr" in
        [Yy]) echo
        echo ""$bldgrn" Please input the tv programme numbers to   
               download [max 200 characters] $(tput sgr0)"
              ask2 200 'tvbox'
              echo "$tvbox"
              echo
              cd "$tvsite"
              eval "$player" -g "$tvbox"
              echo;;
        [Nn]) echo;;
        [Qq]) echo; exit;;
        [Rr]) exec "$beeb";;
        * ) echo ""$bldgrn" Thank you $(tput sgr0)";;
    esac
 };
echo;
{
read -t 1800 -n1 -p "$(tput setaf 1) $(tput setab 7) Do you want to  
       delete programmes older than 30 days? [y/n/q/r]  $(tput sgr0)" ynqr ;
    case "$ynqr" in
        [Yy]) find "$radiosite" -mtime +30 -type f -delete;
              find "$tvsite" -mtime +30 -type f -delete; echo; exit;;
        [Nn]) echo; exit;;
        [Qq]) echo; exit;;
        [Rr]) exec "$beeb";;
        * ) echo ""$bldgrn" Thank you $(tput sgr0)";;
    esac
 };


Comments

comments powered by Disqus