├── docs └── tingbot-buttons.png ├── bbcradio.tingapp ├── bbc_1xtra.png ├── bbc_6music.png ├── bbc_radio_cymru.png ├── bbc_radio_four.png ├── bbc_radio_foyle.png ├── bbc_radio_one.png ├── bbc_radio_three.png ├── bbc_radio_two.png ├── bbc_radio_wales.png ├── bbc_asian_network.png ├── bbc_radio_ulster.png ├── bbc_world_service.png ├── bbc_radio_five_live.png ├── bbc_radio_four_extra.png ├── bbc_radio_scotland.png ├── bbc_radio_nan_gaidheal.png ├── bbc_radio_five_live_sports_extra.png ├── app.tbinfo ├── main.py └── stations.json └── README.md /docs/tingbot-buttons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/docs/tingbot-buttons.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_1xtra.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_1xtra.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_6music.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_6music.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_cymru.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_cymru.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_four.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_four.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_foyle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_foyle.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_one.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_one.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_three.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_three.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_two.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_two.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_wales.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_wales.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_asian_network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_asian_network.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_ulster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_ulster.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_world_service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_world_service.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_five_live.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_five_live.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_four_extra.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_four_extra.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_scotland.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_scotland.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_nan_gaidheal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_nan_gaidheal.png -------------------------------------------------------------------------------- /bbcradio.tingapp/bbc_radio_five_live_sports_extra.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njh/bbcradio-tingapp/main/bbcradio.tingapp/bbc_radio_five_live_sports_extra.png -------------------------------------------------------------------------------- /bbcradio.tingapp/app.tbinfo: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BBC Radio", 3 | "author": "Nicholas Humfrey", 4 | "version": "0.1", 5 | "twitter": "@njh", 6 | "website": "http://njh.me/", 7 | "background_color": "000" 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BBC Radio Tingbot App 2 | ===================== 3 | 4 | This Tingbot App allows you to listen to BBC Radio on your [TingBot]. 5 | 6 | * To change station press the left and right buttons. 7 | * To change the volume, press the middle two buttons. 8 | 9 | ![logo](https://raw.github.com/njh/bbcradio-tingapp/master/docs/tingbot-buttons.png) 10 | 11 | Installing mpg123 12 | ----------------- 13 | 14 | The BBC radio streams are played back using [mpg123]. To install it on your [Tingbot] / Raspberry Pi, use the following command: 15 | 16 | sudo apt-get install mpg123 17 | 18 | Or if you want to run the app in the Tingbot Simulator on a Mac, you can install it using: 19 | 20 | brew install mpg123 21 | 22 | 23 | Making USB audio default 24 | ------------------------ 25 | 26 | Because the [Tingbot] does not have a built-in speaker, and the 3.5mm audio jack is not easily accessible, I have been using a USB speaker to playback the audio. 27 | 28 | To make the USB speaker the default audio output device, I had add some configuration. I created the file `/etc/modprobe.d/alsa.conf`: 29 | 30 | ``` 31 | blacklist snd-bcm2835 32 | alias snd-card-0 snd-usb-audio 33 | options snd-usb-audio index=0 34 | ``` 35 | 36 | This tells the Linux kernel to load the USB audio first and disables the built-in audio. 37 | 38 | Finally, `reboot` your Tingbot. 39 | 40 | 41 | [mpg123]: http://www.mpg123.org/ 42 | [TingBot]: http://www.tingbot.com/ 43 | [Tide]: http://docs.tingbot.com/tide/ 44 | -------------------------------------------------------------------------------- /bbcradio.tingapp/main.py: -------------------------------------------------------------------------------- 1 | # Tingbot App for listening to BBC Radio 2 | # 3 | # Requires mpg123: 4 | # apt-get install mpg123 5 | # 6 | 7 | import tingbot 8 | import json 9 | import atexit 10 | from tingbot import * 11 | from subprocess import Popen, check_call 12 | 13 | 14 | with open('stations.json') as stations_file: 15 | stations = json.load(stations_file) 16 | 17 | state = { 18 | 'station': 0, 19 | 'volume': 10, 20 | 'playing': None 21 | } 22 | 23 | proc = None 24 | 25 | 26 | @atexit.register 27 | def stop_stream(): 28 | global proc 29 | if proc != None: 30 | proc.terminate(); 31 | 32 | def start_stream(stream_url): 33 | global proc 34 | stop_stream() 35 | proc = Popen(['mpg123', '-@', stream_url], env={"PATH": "/usr/local/bin:/usr/bin"}) 36 | 37 | def set_volume(percent): 38 | check_call(["amixer", "set", "PCM", str(percent) + '%']) 39 | 40 | @left_button.press 41 | def press(): 42 | state['station'] -= 1 43 | if state['station'] < 0: 44 | state['station'] = len(stations) - 1 45 | 46 | @right_button.press 47 | def press(): 48 | state['station'] += 1 49 | if state['station'] >= len(stations): 50 | state['station'] = 0 51 | 52 | @midleft_button.press 53 | def press(): 54 | state['volume'] -= 10 55 | if state['volume'] < 0: 56 | state['volume'] = 0 57 | set_volume(state['volume']) 58 | 59 | @midright_button.press 60 | def press(): 61 | state['volume'] += 10 62 | if state['volume'] >= 100: 63 | state['volume'] = 100 64 | set_volume(state['volume']) 65 | 66 | @every(seconds=0.1) 67 | def loop(): 68 | station = stations[state['station']] 69 | screen.image(station['logo']) 70 | if state['station'] != state['playing']: 71 | start_stream(station['stream']['url']) 72 | state['playing'] = state['station'] 73 | 74 | tingbot.run() 75 | 76 | -------------------------------------------------------------------------------- /bbcradio.tingapp/stations.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "BBC Radio 1", 4 | "logo": "bbc_radio_one.png", 5 | "stream": { 6 | "type": "http-icy-mp3", 7 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_one.pls" 8 | } 9 | }, 10 | { 11 | "name": "BBC Radio 1Xtra", 12 | "logo": "bbc_1xtra.png", 13 | "stream": { 14 | "type": "http-icy-mp3", 15 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_1xtra.pls" 16 | } 17 | }, 18 | { 19 | "name": "BBC Radio 2", 20 | "logo": "bbc_radio_two.png", 21 | "stream": { 22 | "type": "http-icy-mp3", 23 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_two.pls" 24 | } 25 | }, 26 | { 27 | "name": "BBC Radio 3", 28 | "logo": "bbc_radio_three.png", 29 | "stream": { 30 | "type": "http-icy-mp3", 31 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_three.pls" 32 | } 33 | }, 34 | { 35 | "name": "BBC Radio 4", 36 | "logo": "bbc_radio_four.png", 37 | "stream": { 38 | "type": "http-icy-mp3", 39 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_fourfm.pls" 40 | } 41 | }, 42 | { 43 | "name": "BBC Radio 4 Extra", 44 | "logo": "bbc_radio_four_extra.png", 45 | "stream": { 46 | "type": "http-icy-mp3", 47 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_four_extra.pls" 48 | } 49 | }, 50 | { 51 | "name": "BBC Radio 5 live", 52 | "logo": "bbc_radio_five_live.png", 53 | "stream": { 54 | "type": "http-icy-mp3", 55 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_five_live.pls" 56 | } 57 | }, 58 | { 59 | "name": "BBC Radio 5 live sports extra", 60 | "logo": "bbc_radio_five_live_sports_extra.png", 61 | "stream": { 62 | "type": "http-icy-mp3", 63 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_five_live_sports_extra.pls" 64 | } 65 | }, 66 | { 67 | "name": "BBC Radio 6 Music", 68 | "logo": "bbc_6music.png", 69 | "stream": { 70 | "type": "http-icy-mp3", 71 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_6music.pls" 72 | } 73 | }, 74 | { 75 | "name": "BBC Asian Network", 76 | "logo": "bbc_asian_network.png", 77 | "stream": { 78 | "type": "http-icy-mp3", 79 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_asian_network.pls" 80 | } 81 | }, 82 | { 83 | "name": "BBC World Service", 84 | "logo": "bbc_world_service.png", 85 | "stream": { 86 | "type": "http-icy-mp3", 87 | "url": "http://wsdownload.bbc.co.uk/worldservice/meta/live/shoutcast/mp3/eieuk.pls" 88 | } 89 | }, 90 | { 91 | "name": "BBC Radio Scotland", 92 | "logo": "bbc_radio_scotland.png", 93 | "stream": { 94 | "type": "http-icy-mp3", 95 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_scotland_fm.pls" 96 | } 97 | }, 98 | { 99 | "name": "BBC Radio nan Gàidheal", 100 | "logo": "bbc_radio_nan_gaidheal.png", 101 | "stream": { 102 | "type": "http-icy-mp3", 103 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_nan_gaidheal.pls" 104 | } 105 | }, 106 | { 107 | "name": "BBC Radio Ulster", 108 | "logo": "bbc_radio_ulster.png", 109 | "stream": { 110 | "type": "http-icy-mp3", 111 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_ulster.pls" 112 | } 113 | }, 114 | { 115 | "name": "BBC Radio Foyle", 116 | "logo": "bbc_radio_foyle.png", 117 | "stream": { 118 | "type": "http-icy-mp3", 119 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_foyle.pls" 120 | } 121 | }, 122 | { 123 | "name": "BBC Radio Wales", 124 | "logo": "bbc_radio_wales.png", 125 | "stream": { 126 | "type": "http-icy-mp3", 127 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_wales_fm.pls" 128 | } 129 | }, 130 | { 131 | "name": "BBC Radio Cymru", 132 | "logo": "bbc_radio_cymru.png", 133 | "stream": { 134 | "type": "http-icy-mp3", 135 | "url": "http://open.live.bbc.co.uk/mediaselector/5/select/mediaset/http-icy-mp3-a/format/pls/vpid/bbc_radio_cymru.pls" 136 | } 137 | } 138 | ] 139 | --------------------------------------------------------------------------------