Making a Docker application
In keeping with the self-hosted/homelab theme of the last post, I decided to try my hand at creating a service to run in a Docker container, namely a local network 'radio station' organiser with a web interface.
The program is written in Python (no surprises there) with the network streaming handled by VLC, the downloading of audio files (playlists) carried out by YouTube-DL, Python module Bottle fulfilling webserver duties and SQLite3 storing information about downloaded playlists and created streams.
The bash commands that are used to start the VLC streams and to download a YouTube playlist are quite specific.
VLC streams are launched in the background, with a never-ending, randomly selected order of file playback to be transcoded to mp3 and streamed via http.
nohup cvlc -vvv ~/Music/$playlist --random --loop --sout "#gather,transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100,scodec=none}:http{mux=mp3,dst=:$port/}" --sout-keep &
Downloads from YouTube also take place in the background and save only the audio files of each downloaded video into a directory for each playlist.
nohup youtube-dl $url --extract-audio --no-overwrites --ignore-errors --audio-format mp3 -o "~/Music/$shorturl/%(title)s.%(ext)s" &
Here's the web UI:
To create the Docker image, I used the official Debian image off of Docker Hub with the following dockerfile:
FROM debian
RUN apt-get update && apt-get install -y vlc youtube-dl python3 psmisc
RUN sed -i 's/geteuid/getppid/' /usr/bin/vlc
ADD vlc_radio /srv/vlc_radio
RUN chmod a+x /srv/vlc_radio/main.py
WORKDIR /srv/vlc_radio
CMD ["./main.py"]
Here's the program's source code and dockerfile on GitHub.
The program is written in Python (no surprises there) with the network streaming handled by VLC, the downloading of audio files (playlists) carried out by YouTube-DL, Python module Bottle fulfilling webserver duties and SQLite3 storing information about downloaded playlists and created streams.
The bash commands that are used to start the VLC streams and to download a YouTube playlist are quite specific.
VLC streams are launched in the background, with a never-ending, randomly selected order of file playback to be transcoded to mp3 and streamed via http.
nohup cvlc -vvv ~/Music/$playlist --random --loop --sout "#gather,transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100,scodec=none}:http{mux=mp3,dst=:$port/}" --sout-keep &
Downloads from YouTube also take place in the background and save only the audio files of each downloaded video into a directory for each playlist.
nohup youtube-dl $url --extract-audio --no-overwrites --ignore-errors --audio-format mp3 -o "~/Music/$shorturl/%(title)s.%(ext)s" &
Here's the web UI:
![]() |
| Main screen, shows all streams and playlists -- clicking stream name changes page to that stream's controls, clicking playlist entry opens YouTube link |
![]() |
| Stream controls -- status indicator and start, stop, delete |
![]() |
| Admin control -- Download playlist, create stream, restart program and remove all program data (files and config) |
To create the Docker image, I used the official Debian image off of Docker Hub with the following dockerfile:
FROM debian
RUN apt-get update && apt-get install -y vlc youtube-dl python3 psmisc
RUN sed -i 's/geteuid/getppid/' /usr/bin/vlc
ADD vlc_radio /srv/vlc_radio
RUN chmod a+x /srv/vlc_radio/main.py
WORKDIR /srv/vlc_radio
CMD ["./main.py"]
Here's the program's source code and dockerfile on GitHub.



Comments
Post a Comment