Giter Site home page Giter Site logo

duracell80 / oceaneyes Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 1.0 440 KB

Python API for Ocean Digital Internet Radios

License: GNU General Public License v3.0

Python 92.85% Shell 6.19% PLSQL 0.96%
automation home-automation home-automation-system homeautomation internetradio openhab presets python radio radiostation

oceaneyes's Introduction

OceanEyes Radio API

Python API for Ocean Digital Internet Radios or radios with the Skytune (ALD) chipset https://www.oceandigitalshop.com/internet-radio

Future proof your investment with hardware that contains station management onboard. Ocean Digital's products provide a better way to ensure our hardware keeps on working even if they discontinue their skytune service. Tested on the Ocean Digital WR-26F, and likely compatible with other radios that contain a similar server to manage favourites.

It's just you, me and an MP3 player. OceanEyes hopes to provide easier and consistent programming access to the onboard preset server.

Usage:

To import as a module.

Be on the same network as your radio device, in the init declare your radio's location on your WiFi network:

#!/usr/bin/python3
import oceaneyes as oe

def main():
	settings, stations = oe.init("192.168.1.200")
	ip = settings["ipaddress"]
	
	print(oe.status())


if __name__ == "__main__":
	main()

Example of bulk import from *.pls

oe.add_import("./import.pls", False)

[i] Importing station presets from ./import.pls
[+] 1 of 3 ...
[+] 2 of 3 ...
[+] 3 of 3 ...

200,OpenFM - EDM Anthems,http://stream.open.fm/361
200,OpenFM - Trance,http://stream.open.fm/7
200,OpenFM - House,http://stream.open.fm/5

Install from terminal

$ chmod +x *.sh
$ chmod +x *.py
$ ./install.sh

Running without Systemd

$ cd ~/python-apps/oceaneyes
$ source bin/activate oceaneyes
$ cd app
$ ../bin/python3 main.py

Load a browser at the address replacing the ipaddr with yours found with ifconfig | grep "192":

firefox http://192.168.x.xx:1929/docs

REST API (Work currently in progress)

Running api.sh in the root directory of the repo will run a FastAPI server at port 1929 that uses the oe module to interact with the device via OceanEyes.

# Read the API endpoints
http://192.168.x.xx:1929/docs

# Search for a station in the Community Radio Browser
http://192.168.x.xx:1929/v1/search/radiobrowser/bbc radio 4

Python API methods (documentation update coming soon, still adding features):

import sys, time
import oceaneyes as oe

# Declare global data
settings, stations = oe.init("192.168.2.20")
ip = settings["ipaddress"]



# Find out if the radio is online
if oe.is_online():
	print("Radio is online")

# Show name of currently playing channel
print(oe.status()) - Returns the currently playing station name.

# Change volume of your radio
oe.volume("up|down|mute|unmute")

# Get stats on favourite storage
fav_remaining  = oe.get_remaining("fav")
fav_total      = oe.get_total("fav")
print("Presets: Total=" + str(fav_total) + " Remaining=" + str(fav_remaining))


# Play a channel on your radio
oe.play("1")

# Play a channel on your computer instead (install vlc)
oe.listen("1")

# Delete a channel
oe.delete("1")

# Edit a channel
oe.edit("1", "Vivaldi", "https://stream.0nlineradio.com/vivaldi", "3;17;-1", "2;15", "0")

# Move a channel from one favourite placement to another
print(oe.move("2", "1"))


# Decode country and genre codes
print(oe.decode_country("3", "17", "-1"))
print(oe.decode_genre("-1", "1", "6"))

# Encode plain text to a country or genre code
print(encode_country("United Kingdom"))
print(encode_genre("Pop"))

# Get info on a channel
print(oe.info_get("1"))



# Exact match search of Community Radio Browser by station name
code, result = oe.search("BBC Radio 4", "RadioBrowser", True)
if code == 200:
       i = 0

       while i < len(result):
       print(result[i]["chname"] + ","  + result[i]["churl"])
           i+=1

# Use Community Radio Browser to replace a masked URL from skytune
print(oe.enrich_url("BBC Radio 4"))



# Export favourties in these formats 
# (json-rpp exports to Linux Mint's Radio++ Applet directly)

print(oe.get_list("plain", False))
print(oe.get_list("json", True))
print(oe.get_list("json-rpp", True))
print(oe.get_list("csv", False))
print(oe.get_list("ssv", False))
print(oe.get_list("m3u", True))
print(oe.get_list("pls", False))

-- You would not believe your eyes if ten million fireflies lit up the world as I fell asleep - Adam Young

Useful Resources

Ideas and features

  • Cache Community Radio Browser locally and direct REST API to look up that instead
  • Evolve the onboard web server to allow more playback controls and device configuration
  • Automate station selection on a schedule
  • Automate emergency alerts by changing the station to an emergency broadcast and back again
  • Automate the import of favourites from a local database or online community radio browser
  • Export presets in as many formats as possible
  • Syncronize station presets across other software
  • Display now playing data in a Home Automation Dashboard
  • Analyse listening habits and own this data yourself
  • Control volume upon system events such as phone or video calls or when playing videos
  • Export favourites from radio to Rhythmbox, Moode or Volumio
  • Import favourites from Radio++, Rhythmbox, Moode or Volumio to radio
  • Store favourite profiles locally (themed presets, like UK Radio, US Radio) to send to radio

-- I've never fallen from quite this high, Fallin' into your ocean eyes, Those ocean eyes - Billie Eilish

Own your URL's!

Open Source our radio preset systems! Sick and tired of Internet Radio portals shutting down? Help send a message to the industry that the potential of service shutdowns is leading to the dimise of a whole product category and it need not be this way. Internet Radio as a standalone category of hardware can continue to grow if we invest in the right ways to allow people to manage their own databases.

Ways we can solve this problem

  • As buyers, make preset data a high priority in product research
  • As buyers, ask for technical teardowns by community members
  • As reviewers, review the features of a device that would allow the device to operate without service
  • As reviewers, update reviews if a device has been broken by a brand and offer their remediation path
  • As providers, free the station database or category browser from an online only service
  • As providers, cache the entire database in a format like sqlite3, schedule updates directly to the device
  • As providers, allow end users to update this cache of data also
  • As providers, standardize an import and export file format that allows portablity of preset data
  • As providers, protect buyers of your products with a sandboxed portion of the device that the user can own, even a simple samba share and M3U file could save the device from landfill!
  • As providers, offer more than one way for the device to browse a list of stations
  • As buyers, reviewers and providers; maintain a healthy ecosystem by investing in open software and right to repair

What is Right to Repair?

https://www.eff.org/issues/right-to-repair

https://www.repair.org/stand-up

https://www.zdnet.com/home-and-office/sustainability/right-to-repair-what-it-means-and-why-it-matters-to-you/

https://hackaday.io/project/183339-saving-a-reciva-box-from-the-landfill

Radios that may use Skytune:

  • Most Ocean Digital's
  • Ocean's (WR-50CD, WR-26F, WR-336F, WR-336N, WR-210N, WR-880N, WR-23D, WR-230SF)
  • Denver Electronics IR-140
  • Denver Electronics IR-135B
  • Release WiFi Internet Radios
  • Renkforce RF-IR-MONOV2
  • Opticum Ton4 DAB+, Internet, FM Radio
  • CC WiFi 3 Internet Radio (with Skytune)

To protect your investment and lengthen the life of your device ask community members or reviewers if the device lets you add your own station URL's directly. Avoid known Reciva radios, like older CC Crane's, Grace Digital's, and Sirius radios that have a vested interest in broadcast technologies like satelite radio. Frontier service based devices are also risky unless adding station URl's directly is allowed via upgrade.

Avoid Pure and Pure Evoke's and Inscabin's, Lemega's, NakiRadio, Sungale's, most Sangean's, AUNA's.

Non-Skytune Radios that have long life potenital: Tivoli, Logitech, Brennan, Raspbery Pi / DIY devices and Single Board based retro handhelds, as well as set-top boxes or streaming devices like Roku, Amazon Fire, Apple TV or iOS devices, Now TV, Android or Android TV devices, Chromecast and AirPlay devices.

Hybrid Digital Radio

Ocean Digital chips decode DAB and DAB + and are sold in the US but we use the HDRadio system instead. It would be nice to buy a radio with a HD tuner. However there is the potenital to feed an RTL SDR into nrsc5, if that output from nrsc5 could be sent to icecast or ezstream to icecast then a local URL could be added to listen to HDRadio on the Ocean Digitals.

oceaneyes's People

Contributors

duracell80 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

hanbule

oceaneyes's Issues

Feature Request: Add stop playback / shutdown option.

Add a dummy/null station that can be tuned to to cause playback to stop on a given radio device. In this way the radio may then timeout and shutdown after no playback is found.

(Conversely there's currently no way to "wake up" the device remotely)

various build errors

Building wheels for collected packages: PyAudio
  Building wheel for PyAudio (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for PyAudio (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [19 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-311
      creating build/lib.linux-x86_64-cpython-311/pyaudio
      copying src/pyaudio/__init__.py -> build/lib.linux-x86_64-cpython-311/pyaudio
      running build_ext
      building 'pyaudio._portaudio' extension
      creating build/temp.linux-x86_64-cpython-311
      creating build/temp.linux-x86_64-cpython-311/src
      creating build/temp.linux-x86_64-cpython-311/src/pyaudio
      x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/usr/local/include -I/usr/include -I/home/avetik/python-apps/oceaneyes/include -I/usr/include/python3.11 -c src/pyaudio/device_api.c -o build/temp.linux-x86_64-cpython-311/src/pyaudio/device_api.o
      In file included from src/pyaudio/device_api.c:1:
      src/pyaudio/device_api.h:7:10: fatal error: Python.h: No such file or directory
          7 | #include "Python.h"
            |          ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for PyAudio
Failed to build PyAudio
ERROR: Could not build wheels for PyAudio, which is required to install pyproject.toml-based projects
install.sh: 45: source: not found
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.11/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
Configuration file /lib/systemd/system/oe.service is marked executable. Please remove executable permission bits. Proceeding anyway.
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
[i] Installed requirements in the venv ...
Package    Version
---------- -------
pip        23.0.1
setuptools 66.1.1

systemd error

Trying to install the program and getting this issue:

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

How to address?

More errors when running run.sh

Getting a few more issues here as I'm trying to use the app:

avetik@lobya:~/python-apps/oceaneyes
$ sh run.sh 
run.sh: 17: [[: not found
[i] Running App from within ... /home/avetik/python-apps/oceaneyes
[i] Radio @192.168.1.1 status: Offline
Traceback (most recent call last):
  File "/home/avetik/python-apps/oceaneyes/app/main.py", line 222, in <module>
    main()
  File "/home/avetik/python-apps/oceaneyes/app/main.py", line 103, in main
    fav_remaining  = oe.get_remaining("fav")
                     ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/avetik/python-apps/oceaneyes/app/oceaneyes.py", line 542, in get_remaining
    f = int(get_total("fav"))
            ^^^^^^^^^^^^^^^^
  File "/home/avetik/python-apps/oceaneyes/app/oceaneyes.py", line 534, in get_total
    f = c[2].split(",")
        ~^^^
IndexError: list index out of range
INFO:root:[i] FastAPI available
INFO:root:[i] Starting FastAPI as background task
sh: 1: kill: Illegal number: 0.0
INFO:     Started server process [4901]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://192.168.1.237:1929 (Press CTRL+C to quit)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.