Rule creation for IR remotes
This commit is contained in:
@@ -6,6 +6,7 @@ import sys
|
||||
from typing import List, Tuple
|
||||
import voluptuous as vol
|
||||
from ..reconnecting_client import ReconnectingClient
|
||||
from .radio import find_local_radio_url_by_name
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
MediaPlayerDevice, PLATFORM_SCHEMA)
|
||||
@@ -485,6 +486,9 @@ class SqueezeBoxDevice(MediaPlayerDevice):
|
||||
If ATTR_MEDIA_ENQUEUE is True, add `media_id` to the current playlist.
|
||||
This method must be run in the event loop and returns a coroutine.
|
||||
"""
|
||||
if media_type == 'channel':
|
||||
media_id = find_local_radio_url_by_name(media_id)
|
||||
|
||||
if kwargs.get(ATTR_MEDIA_ENQUEUE):
|
||||
return self._add_uri_to_playlist(media_id)
|
||||
|
||||
|
||||
68
custom_components/squeezebox_telnet/radio.py
Normal file
68
custom_components/squeezebox_telnet/radio.py
Normal file
@@ -0,0 +1,68 @@
|
||||
import xml.etree.ElementTree as ET
|
||||
from urllib.request import urlopen
|
||||
|
||||
ompl_radio_browse_url = 'http://opml.radiotime.com/Browse.ashx'
|
||||
|
||||
|
||||
def radio_name_cleanup(radio_name):
|
||||
"""Removes tokens with brackets or points
|
||||
"Radio Bamberg 106.1 (Top 40/Pop)" -> "Radio Bamberg 106.1"
|
||||
"""
|
||||
radio_name = radio_name.split()
|
||||
res = []
|
||||
for token in radio_name:
|
||||
if '(' in token or ')' in token:
|
||||
continue
|
||||
res.append(token)
|
||||
return " ".join(res)
|
||||
|
||||
|
||||
def get_sender_information(queryURL):
|
||||
"""
|
||||
Example Query: GET http://opml.radiotime.com/Browse.ashx?partnerId=<partnerid>&serial=<serial>
|
||||
partnerid and serial does not seem to be necessary - so we do not use it here,
|
||||
"""
|
||||
xmlfile = urlopen(queryURL)
|
||||
tree = ET.ElementTree(file=xmlfile)
|
||||
rootnode = tree.getroot()
|
||||
|
||||
result = dict()
|
||||
for node in rootnode.iter('outline'):
|
||||
if 'type' not in node.attrib or node.attrib['type'] != "audio":
|
||||
continue
|
||||
station_name = radio_name_cleanup(node.attrib['text'])
|
||||
station_url = node.attrib['URL']
|
||||
station_id = node.attrib['guide_id']
|
||||
print(station_name)
|
||||
result[station_id] = {'name': station_name, 'url': station_url}
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def get_related_radio_stations(stationID):
|
||||
query_url = ompl_radio_browse_url + '?id=' + stationID
|
||||
return get_sender_information(query_url)
|
||||
|
||||
|
||||
def get_local_radio_stations():
|
||||
# goto ompl.radiotime with parameter ?c=local and look for your city there then paste id here
|
||||
query_url = ompl_radio_browse_url + '?id=r100765'
|
||||
result = get_sender_information(query_url)
|
||||
print(result)
|
||||
return result
|
||||
|
||||
|
||||
def find_local_radio_url_by_name(search_name):
|
||||
"""Searches at the Radiotime database for a local radiostation which contains the searchName """
|
||||
search_name = search_name.lower().strip()
|
||||
if search_name.startswith('http'):
|
||||
return search_name
|
||||
|
||||
for radioId, radio in find_local_radio_url_by_name.stations.items():
|
||||
if search_name in radio['name'].lower():
|
||||
return radio['url']
|
||||
|
||||
raise ValueError("Could not find radio station " + search_name)
|
||||
|
||||
|
||||
find_local_radio_url_by_name.stations = get_local_radio_stations()
|
||||
Reference in New Issue
Block a user