diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..86461da112f6b85db4ac0e2b398e49ffc0c88096 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2018 Benoît Harrault + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index b360a96fb617576e3bb47c389f859d15b6b8b27e..3bd4df11cf30dadff58a10c3ea05fa0542d560dc 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -# plugin.audio.fip +# Fip Radio KODI Plugin +Listen to FIP radio streams diff --git a/addon.xml b/addon.xml new file mode 100644 index 0000000000000000000000000000000000000000..d74a48bd743ce82fec1de2480d03909f6cadc1e7 --- /dev/null +++ b/addon.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<addon id="plugin.audio.fip" name="Fip, an eclectic music radio" version="0.0.1" provider-name="Benoît Harrault"> + <requires> + <import addon="xbmc.python" version="2.20.0"/> + </requires> + <extension point="xbmc.python.pluginsource" library="default.py"> + <provides>audio</provides> + </extension> + <extension point="xbmc.addon.metadata"> + <platform>all</platform> + <license>MIT</license> + <language>en</language> + <summary lang="en">Fip, an eclectic music radio</summary> + <description lang="en">Listen to fip french radio streams</description> + </extension> +</addon> diff --git a/default.py b/default.py new file mode 100644 index 0000000000000000000000000000000000000000..530d11e4683aa41d461bf30f7bd663d08677cb4c --- /dev/null +++ b/default.py @@ -0,0 +1,93 @@ +# https://docs.python.org/2.7/ +import os +import sys +import urllib +import urlparse +# http://mirrors.kodi.tv/docs/python-docs/ +import xbmcaddon +import xbmcgui +import xbmcplugin + + +def get_streams(): + streams = {} + base_stream_url = 'https://direct.fipradio.fr/live/' + streams.update({ + 1: { + 'title': 'fip', + 'url': base_stream_url + 'fip-midfi.mp3?ID=radiofrance', + 'album_cover': 'https://www.fip.fr/sites/default/files/fip-quadri-filet.png' + }, + 2: { + 'title': 'fip / electro', + 'url': base_stream_url + 'fip-webradio8.mp3?ID=radiofrance', + 'album_cover': 'https://www.fip.fr/sites/default/files/asset/images/2017/05/webradio-electro-small.png' + }, + 3: { + 'title': 'fip / groove', + 'url': base_stream_url + 'fip-webradio3.mp3?ID=radiofrance', + 'album_cover': 'https://www.fip.fr/sites/default/files/asset/images/2016/06/webradio-groove-small.png' + }, + 4: { + 'title': 'fip / rock', + 'url': base_stream_url + 'fip-webradio1.mp3?ID=radiofrance', + 'album_cover': 'https://www.fip.fr/sites/default/files/asset/images/2016/06/webradio-rock-small.png' + } + }) + return streams + + +def build_url(query): + base_url = sys.argv[0] + return base_url + '?' + urllib.urlencode(query) + + +def build_streams_list(streams): + stream_list = [] + for stream in streams: + # create a list item using the stream filename for the label + li = xbmcgui.ListItem( + label=streams[stream]['title'], thumbnailImage=streams[stream]['album_cover']) + # set the fanart to the albumc cover + li.setProperty('fanart_image', streams[stream]['album_cover']) + # set the list item to playable + li.setProperty('IsPlayable', 'true') + # build the plugin url for Kodi + # Example: plugin://plugin.audio.example/?url=http%3A%2F%2Fwww.theaudiodb.com%2Ftestfiles%2F01-pablo_perez-your_ad_here.mp3&mode=stream&title=01-pablo_perez-your_ad_here.mp3 + url = build_url({ + 'mode': 'stream', + 'url': streams[stream]['url'], + 'title': streams[stream]['title'] + }) + # add the current list item to a list + stream_list.append((url, li, False)) + # add list to Kodi per Martijn + # http://forum.kodi.tv/showthread.php?tid=209948&pid=2094170#pid2094170 + xbmcplugin.addDirectoryItems(addon_handle, stream_list, len(stream_list)) + # set the content of the directory + xbmcplugin.setContent(addon_handle, 'songs') + xbmcplugin.endOfDirectory(addon_handle) + + +def play_stream(url): + play_item = xbmcgui.ListItem(path=url) + xbmcplugin.setResolvedUrl(addon_handle, True, listitem=play_item) + + +def main(): + args = urlparse.parse_qs(sys.argv[2][1:]) + mode = args.get('mode', None) + + # initial launch of add-on + if mode is None: + streams = get_streams() + build_streams_list(streams) + # a stream from the list has been selected + elif mode[0] == 'stream': + # pass the url of the stream to play_stream + play_stream(args['url'][0]) + + +if __name__ == '__main__': + addon_handle = int(sys.argv[1]) + main() diff --git a/icon.png b/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..9daae2081e5176374265fad9328bde373f7eccf5 Binary files /dev/null and b/icon.png differ