Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containerized branch based on 303-proxy_http_ffmpeg_streams #305

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
import cherrypy
import flask_babel
import psutil
from flask import (Flask, flash, make_response, redirect, render_template,
request, send_file, url_for)
import requests
from flask import (Flask, Response, flash, make_response, redirect,
render_template, request, send_file, url_for)
from flask_socketio import SocketIO
from flask_babel import Babel
from flask_paginate import Pagination, get_page_parameter
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support import expected_conditions as ECf
from selenium.webdriver.support.ui import WebDriverWait

import karaoke
Expand All @@ -43,6 +45,7 @@
app.config['BABEL_TRANSLATION_DIRECTORIES'] = 'translations'
babel = Babel(app)
site_name = "PiKaraoke"
socketio = SocketIO(app)
admin_password = None
is_raspberry_pi = get_platform() == "raspberry_pi"

Expand Down Expand Up @@ -608,6 +611,27 @@ def expand_fs():
flash("You don't have permission to resize the filesystem", "is-danger")
return redirect(url_for("home"))

# Proxy the video stream from ffmpeg to /stream/<path>, so pikaraoke works over a single port
@app.route('/stream/<path>', methods=["GET", "POST"])
def redirect_to_ffmpeg_stream(path): #NOTE var :path will be unused as all path we need will be read from :request ie from flask import request
res = requests.request( # ref. https://stackoverflow.com/a/36601467/248616
method = request.method,
url = request.url.replace(request.host_url, f'{k.ffmpeg_url_base}/'),
headers = {k:v for k,v in request.headers if k.lower() != 'host'}, # exclude 'host' header
data = request.get_data(),
cookies = request.cookies,
allow_redirects = False,
)

#region exlcude some keys in :res response
excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection'] #NOTE we here exclude all "hop-by-hop headers" defined by RFC 2616 section 13.5.1 ref. https://www.rfc-editor.org/rfc/rfc2616#section-13.5.1
headers = [
(k,v) for k,v in res.raw.headers.items()
if k.lower() not in excluded_headers
]
#endregion exclude some keys in :res response
response = Response(res.content, res.status_code, headers)
return response

# Handle sigterm, apparently cherrypy won't shut down without explicit handling
signal.signal(signal.SIGTERM, lambda signum, stack_frame: k.stop())
Expand All @@ -616,24 +640,7 @@ def get_default_youtube_dl_path(platform):
if platform == "windows":
return os.path.join(os.path.dirname(__file__), ".venv\Scripts\yt-dlp.exe")
return os.path.join(os.path.dirname(__file__), ".venv/bin/yt-dlp")
# if platform == "windows":
# choco_ytdl_path = r"C:\ProgramData\chocolatey\bin\yt-dlp.exe"
# scoop_ytdl_path = os.path.expanduser(r"~\scoop\shims\yt-dlp.exe")
# if os.path.isfile(choco_ytdl_path):
# return choco_ytdl_path
# if os.path.isfile(scoop_ytdl_path):
# return scoop_ytdl_path
# return r"C:\Program Files\yt-dlp\yt-dlp.exe"
# default_ytdl_unix_path = "/usr/local/bin/yt-dlp"
# if platform == "osx":
# if os.path.isfile(default_ytdl_unix_path):
# return default_ytdl_unix_path
# else:
# # just a guess based on the default python 3 install in OSX monterey
# return "/Library/Frameworks/Python.framework/Versions/3.10/bin/yt-dlp"
# else:
# return default_ytdl_unix_path



def get_default_dl_dir(platform):
if is_raspberry_pi:
Expand Down
23 changes: 23 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use Alpine as the base image
FROM alpine:latest

# Install required packages
RUN apk add --no-cache bash zsh git gcc python3-dev musl-dev linux-headers py3-pip ffmpeg htop screen figlet

# Clone the pikaraoke repository
RUN git clone -b PiKaraoke-Docker https://github.com/honestlai/pikaraoke.git /pikaraoke
honestlai marked this conversation as resolved.
Show resolved Hide resolved

# Run the setup script
RUN cd /pikaraoke && echo y | bash setup.sh

# Copy the docker logo.png into the containers pikaraoke directory
COPY logo.png /pikaraoke/logo.png

# Copy the entrypoint script into the container
COPY entrypoint.sh /entrypoint.sh

# Set permissions for the entrypoint script
RUN chmod +x /entrypoint.sh

# Set the entrypoint
ENTRYPOINT ["/entrypoint.sh"]
Loading