Skip to content

Commit

Permalink
Merge pull request #2668 from alxndr42/script-radioparadise
Browse files Browse the repository at this point in the history
[script.radioparadise] 2.1.1
  • Loading branch information
basrieter authored Nov 10, 2024
2 parents f1ad426 + 2b6a476 commit 22a250d
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 97 deletions.
8 changes: 8 additions & 0 deletions script.radioparadise/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## v2.1.1

- Improve metadata handling

## v2.1.0

- Add Serenity channel

## v2.0.1

- Use new metadata API
Expand Down
23 changes: 11 additions & 12 deletions script.radioparadise/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Radio Paradise addon for Kodi

Plays [Radio Paradise][] music mixes, accompanied by the HD slideshow.
Plays [Radio Paradise][] music streams, accompanied by the HD slideshow.

[radio paradise]: https://radioparadise.com/

## Features

- Radio Paradise music mixes in AAC or FLAC
- Radio Paradise music streams in AAC or FLAC
- HD slideshow (optional)
- Auto Play (optional)

Expand All @@ -16,24 +16,23 @@ Plays [Radio Paradise][] music mixes, accompanied by the HD slideshow.

[release]: https://kodi.wiki/view/Releases

## Mix Selection by Script Parameter
## Channel Selection by Script Parameter

In addition to the Auto Play feature, the addon script can be called with a
parameter to start a particular RP mix:
parameter to start a particular RP channel:

```python
RunScript('script.radioparadise', 1)
```

Mix parameter:

| Value | Mix |
| Value | Channel |
| --- | --- |
| 0 | RP Main Mix |
| 1 | RP Mellow Mix |
| 2 | RP Rock Mix |
| 3 | RP Global Mix |
| 0 | Main Mix |
| 1 | Mellow Mix |
| 2 | Rock Mix |
| 3 | Global Mix |
| 4 | Serenity |

This can be used to add shortcuts for RP mixes in [favourites.xml][].
This can be used to add shortcuts for RP channels in [favourites.xml][].

[favourites.xml]: https://kodi.wiki/view/Favourites.xml
4 changes: 2 additions & 2 deletions script.radioparadise/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.radioparadise" name="Radio Paradise" version="2.0.1" provider-name="Alexander Dietrich">
<addon id="script.radioparadise" name="Radio Paradise" version="2.1.1" provider-name="Alexander Dietrich">
<requires>
<import addon="xbmc.python" version="3.0.1"/>
<import addon="script.module.requests" version="2.0.0"/>
Expand All @@ -9,7 +9,7 @@
</extension>
<extension point="xbmc.service" library="service.py"/>
<extension point="xbmc.addon.metadata">
<summary lang="en_GB">Radio Paradise addon for Kodi</summary>
<summary lang="en_GB">Radio Paradise music and slideshows</summary>
<description lang="en_GB">An eclectic DJ-mixed blend of rock, indie, electronica, world music, and more. Listener supported &amp; always 100% commercial free.</description>
<website>https://radioparadise.com/</website>
<source>https://codeberg.org/alxndr42/script.radioparadise</source>
Expand Down
32 changes: 32 additions & 0 deletions script.radioparadise/resources/channels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"channel_id": "0",
"title": "Main Mix",
"url_aac": "http://stream.radioparadise.com/aac-128",
"url_flac": "http://stream.radioparadise.com/flacm"
},
{
"channel_id": "1",
"title": "Mellow Mix",
"url_aac": "http://stream.radioparadise.com/mellow-128",
"url_flac": "http://stream.radioparadise.com/mellow-flacm"
},
{
"channel_id": "2",
"title": "Rock Mix",
"url_aac": "http://stream.radioparadise.com/rock-128",
"url_flac": "http://stream.radioparadise.com/rock-flacm"
},
{
"channel_id": "3",
"title": "Global Mix",
"url_aac": "http://stream.radioparadise.com/global-128",
"url_flac": "http://stream.radioparadise.com/global-flacm"
},
{
"channel_id": "42",
"title": "Serenity",
"url_aac": "http://stream.radioparadise.com/serenity",
"url_flac": "http://stream.radioparadise.com/serenity"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,25 @@ msgid "FLAC"
msgstr ""

msgctxt "#30203"
msgid "RP Main Mix"
msgid "Main Mix"
msgstr ""

msgctxt "#30204"
msgid "RP Mellow Mix"
msgid "Mellow Mix"
msgstr ""

msgctxt "#30205"
msgid "RP Rock Mix"
msgid "Rock Mix"
msgstr ""

msgctxt "#30206"
msgid "RP Global Mix"
msgid "Global Mix"
msgstr ""

msgctxt "#30207"
msgid "RP Slideshow"
msgstr ""

msgctxt "#30208"
msgid "Serenity"
msgstr ""
27 changes: 27 additions & 0 deletions script.radioparadise/resources/lib/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import traceback

import xbmc


DEVELOPMENT = False


class Logger():
def __init__(self, name):
self.name = name

def log(self, message, level=None):
"""Log the message."""
if level is not None:
xbmc.log(f'{self.name}: {message}', level)
elif DEVELOPMENT:
xbmc.log(f'{self.name}: {message}', xbmc.LOGINFO)
else:
xbmc.log(f'{self.name}: {message}', xbmc.LOGDEBUG)

def exception(self, exc):
"""Log the exception."""
if DEVELOPMENT:
self.log(traceback.format_exc(), xbmc.LOGERROR)
else:
self.log(repr(exc), xbmc.LOGERROR)
56 changes: 24 additions & 32 deletions script.radioparadise/resources/lib/radioparadise.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from collections import OrderedDict
import json
from pathlib import Path
import re
import time

import requests
import xbmcaddon


NOWPLAYING_URL = 'https://api.radioparadise.com/api/nowplaying_list_v2022?chan={}&list_num=10'
Expand All @@ -21,34 +24,10 @@
# Number of seconds to wait before retrying API updates
UPDATE_WAIT = 5

STREAMS = [
{
'channel': 0,
'title': 'RP Main Mix',
'url_aac': 'http://stream.radioparadise.com/aac-128',
'url_flac': 'http://stream.radioparadise.com/flacm',
},
{
'channel': 1,
'title': 'RP Mellow Mix',
'url_aac': 'http://stream.radioparadise.com/mellow-128',
'url_flac': 'http://stream.radioparadise.com/mellow-flacm',
},
{
'channel': 2,
'title': 'RP Rock Mix',
'url_aac': 'http://stream.radioparadise.com/rock-128',
'url_flac': 'http://stream.radioparadise.com/rock-flacm',
},
{
'channel': 3,
'title': 'RP Global Mix',
'url_aac': 'http://stream.radioparadise.com/global-128',
'url_flac': 'http://stream.radioparadise.com/global-flacm',
},
]
STREAM_INFO = {s['url_aac']: s for s in STREAMS}
STREAM_INFO.update({s['url_flac']: s for s in STREAMS})
# List of channel objects from channels.json
CHANNELS = None
# Map of stream URL to channel object
CHANNEL_INFO = None


class NowPlaying():
Expand All @@ -74,10 +53,10 @@ def get_next_song(self, song_key):
next_key = self.songs.get(song_key, {}).get('next_key')
return self.songs.get(next_key)

def set_channel(self, channel):
"""Set the RP channel number, or None."""
if channel is not None:
self.url = NOWPLAYING_URL.format(channel)
def set_channel(self, channel_id):
"""Set the RP channel ID, or None."""
if channel_id is not None:
self.url = NOWPLAYING_URL.format(channel_id)
else:
self.url = None
self.current = None
Expand Down Expand Up @@ -146,3 +125,16 @@ def build_key(strings):
words = KEY_FILTER_RE.sub(' ', s).casefold().split()
result.extend(words)
return tuple(sorted(result))


def init():
global CHANNELS, CHANNEL_INFO
addon = xbmcaddon.Addon()
addon_path = addon.getAddonInfo('path')
channels_json = Path(addon_path, 'resources', 'channels.json')
CHANNELS = json.loads(channels_json.read_text())
CHANNEL_INFO = {s['url_aac']: s for s in CHANNELS}
CHANNEL_INFO.update({s['url_flac']: s for s in CHANNELS})


init()
20 changes: 10 additions & 10 deletions script.radioparadise/resources/lib/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import xbmcaddon
import xbmcgui

from .radioparadise import STREAMS
from .radioparadise import CHANNELS


class Window(xbmcgui.WindowXML):
def onInit(self):
xbmc.executebuiltin('Container.SetViewMode(100)')
listitems = []
for s in STREAMS:
item = xbmcgui.ListItem(s['title'])
item.setProperty('channel', str(s['channel']))
for idx, channel in enumerate(CHANNELS):
item = xbmcgui.ListItem(channel['title'])
item.setProperty('channel_index', str(idx))
listitems.append(item)
self.clearList()
self.addItems(listitems)
Expand All @@ -23,20 +23,20 @@ def onInit(self):
def onClick(self, controlId):
if controlId == 100:
item = self.getListItem(self.getCurrentListPosition())
channel = int(item.getProperty('channel'))
play_channel(channel)
channel_index = int(item.getProperty('channel_index'))
play_channel(channel_index)
self.close()


def play_channel(channel_number):
def play_channel(channel_index):
"""Play the channel, unless it's already playing."""
stream = STREAMS[channel_number]
channel = CHANNELS[channel_index]
addon = xbmcaddon.Addon()
audio_format = addon.getSetting('audio_format')
if audio_format == 'flac':
url = stream['url_flac']
url = channel['url_flac']
else:
url = stream['url_aac']
url = channel['url_aac']
player = xbmc.Player()
if not player.isPlayingAudio() or player.getPlayingFile() != url:
player.stop()
Expand Down
Loading

0 comments on commit 22a250d

Please sign in to comment.