Code Monkey home page Code Monkey logo

radio_api's Introduction

build our image

radio_api

Simple mplayer-based radio player controllable via REST API

Overview

Stations are stored with their URL in a SQLite database.

Requirements

For using this application, you will need:

  • Python 3
  • Flask
  • SQLite 3

Docker container

There is a Dockerfile for running this application inside a container based on Ubuntu Linux. To create the image, run the following command:

$ docker build -t radio .

This will take a couple of minutes, afterwards you should see the image:

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
radio               latest              84572d3b8826        1 hour ago          504.8MB
...

To start a new container based on this image, execute:

$ docker run -d -p 5000:5000 radio
b4735f102afb6e288b0a35d17b0e63da4d6bd2652467709c5c28538088ae5d30

$ docker ps
CONTAINER ID        IMAGE                      COMMAND                   CREATED             STATUS                PORTS                                                                                                  NAMES
b4735f102afb        radio                      "/bin/sh -c \"/opt/jo…"   16 seconds ago      Up 14 seconds         0.0.0.0:5000->5000/tcp                                                                                 boring_chebyshev
...

It is also possible to use shipped docker-compose file:

$ docker-compose create
$ docker-compose up
Starting radio ... done
Attaching to radio
...
radio       |  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

API calls

There is also a pre-defined Postman collection.

Call Method Parameters Description
/api/stations GET - returns all available stations
/api/stations/<id/name> GET station ID or name returns a particular station
/api/stations/<id/name>/play GET station ID or name plays a particular station
/api/stations POST { "item": { "url": "<str>" } } creates a new station
/api/stations/<id/name> PUT,POST station ID or name, { "item": {"id": <int>, "url": "<str>"} } updates an existing station
/api/stations/<id/name> DELETE station ID or name removes a station
/api/next GET - plays the next station
/api/previous GET - plays the previous station
/api/stop GET - stops the radio
/api/current GET - returns the currently played station
/api/volume GET - returns the current volume level
/api/volume POST { "level": <int> } sets volume to a specific level
/api/volume/up GET - increases the volume by 10%
/api/volume/down GET - decreases the volume by 10%

Database layout

stations

Field name Field type Description
station_id INTEGER PRIMARY KEY AUTOINCREMENT station ID
station_name TEXT NOT NULL station name
station_url TEXT NOT NULL station URL

radio_api's People

Contributors

stdevel avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

nianhbg

radio_api's Issues

Option for mplayer to write to FIFO?

Thanks for your willing to assist!
Well I have the HA running in a docker container amd64. I think that this is what is causing the fact that I cannot play media streams through lovelace cards or when I call the media_player service. ffmpeg is installed in the official docker image, but it does nothing when called and no log errors either.

Wanted:
I simply would like to have the abilitiy to stream a radio and snapcast it to a speaker (snapclient), with the issues above, this is not working and I cannot see why.
So Far:
I have been able to take your image and plug into it a /etc/asound.conf as well as a /etc/pulse/client.conf which tells it to output to write to a pipe of the snapfifo which is in a shared /tmp - this actually works! After working around file permissions but it works for albeit a few seconds until the mpeg in the radio_api crashes due to resources (already at max).
Needed/Wanted:
An image that will be able to write to a tmp file which will be configured to be the snapfifo of snapcast server (not docker) - ideally what would be REALLY awesome would be that I call via API radio station "1" with the output of snapclient and stream... https://github.com/badaix/snapcast/blob/master/doc/json_rpc_api/v2_0_0.md shows that if your radio_api could simply take an ENV of what IP is snapcast and plug in the above on call - this might actually work. Meaning of course the user would need to know the actual client_ids of the snapclient to plug into the api call to radio_api.

  • I agree that this is not the current scope of your program, however this is what I am looking at achieving for my HA setup and this is only because I cannot get it to stream a simple mp3 and cast it to clients... If it is simply an image that will be able to output to a pipe file and not crash, that is already pretty great! I would be able to manually chose the stream and client maybe afterwards.

Thanks so much for your help and interest!

Highest regards,
Jeff

Originally posted by @ThongSong7 in #1 (comment)

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.