aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2026-02-18 01:09:01 -0800
committerPinapelz <yukais@pinapelz.com>2026-02-18 01:09:01 -0800
commita9329a03592d2634926da2dbe9559b6c4a39dd6d (patch)
treea61c5b8472a3a5db7660ae971235b9fcffe65475
parentd7d83d6e733aec3ec0da40e28d185d79911a4cbf (diff)
add gunicorn
-rw-r--r--.env.template3
-rw-r--r--README.md7
-rw-r--r--pyproject.toml1
-rw-r--r--uv.lock23
-rw-r--r--yt_radio.py15
5 files changed, 39 insertions, 10 deletions
diff --git a/.env.template b/.env.template
new file mode 100644
index 0000000..d851df7
--- /dev/null
+++ b/.env.template
@@ -0,0 +1,3 @@
+PLAYLIST_URL=""
+BASE_URL="http://localhost:8000"
+RANDOMIZE_PLAYLIST=True
diff --git a/README.md b/README.md
index a1ea890..6a8cc39 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,9 @@
# yt-playlist-radio
Simple demo of YouTube playlist to m3u playlist, all in about 100 lines of Python.
+
+## How to run?
+First set the environment variables as per `.env.template`, then just run it with gunicorn or something else (gunicorn comes bundled as part of the deps here)
+```bash
+uv sync
+uv run gunicorn -w 4 -b 0.0.0.0:8000 yt_radio:app
+```
diff --git a/pyproject.toml b/pyproject.toml
index 6a84e61..5c7f830 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -6,6 +6,7 @@ readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"flask>=3.1.2",
+ "gunicorn>=25.1.0",
"python-dotenv>=1.2.1",
"yt-dlp>=2026.2.4",
]
diff --git a/uv.lock b/uv.lock
index c77aa88..704ce12 100644
--- a/uv.lock
+++ b/uv.lock
@@ -50,6 +50,18 @@ wheels = [
]
[[package]]
+name = "gunicorn"
+version = "25.1.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "packaging" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/66/13/ef67f59f6a7896fdc2c1d62b5665c5219d6b0a9a1784938eb9a28e55e128/gunicorn-25.1.0.tar.gz", hash = "sha256:1426611d959fa77e7de89f8c0f32eed6aa03ee735f98c01efba3e281b1c47616", size = 594377, upload-time = "2026-02-13T11:09:58.989Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/da/73/4ad5b1f6a2e21cf1e85afdaad2b7b1a933985e2f5d679147a1953aaa192c/gunicorn-25.1.0-py3-none-any.whl", hash = "sha256:d0b1236ccf27f72cfe14bce7caadf467186f19e865094ca84221424e839b8b8b", size = 197067, upload-time = "2026-02-13T11:09:57.146Z" },
+]
+
+[[package]]
name = "itsdangerous"
version = "2.2.0"
source = { registry = "https://pypi.org/simple" }
@@ -123,6 +135,15 @@ wheels = [
]
[[package]]
+name = "packaging"
+version = "26.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/65/ee/299d360cdc32edc7d2cf530f3accf79c4fca01e96ffc950d8a52213bd8e4/packaging-26.0.tar.gz", hash = "sha256:00243ae351a257117b6a241061796684b084ed1c516a08c48a3f7e147a9d80b4", size = 143416, upload-time = "2026-01-21T20:50:39.064Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b7/b9/c538f279a4e237a006a2c98387d081e9eb060d203d8ed34467cc0f0b9b53/packaging-26.0-py3-none-any.whl", hash = "sha256:b36f1fef9334a5588b4166f8bcd26a14e521f2b55e6b9de3aaa80d3ff7a37529", size = 74366, upload-time = "2026-01-21T20:50:37.788Z" },
+]
+
+[[package]]
name = "python-dotenv"
version = "1.2.1"
source = { registry = "https://pypi.org/simple" }
@@ -158,6 +179,7 @@ version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "flask" },
+ { name = "gunicorn" },
{ name = "python-dotenv" },
{ name = "yt-dlp" },
]
@@ -165,6 +187,7 @@ dependencies = [
[package.metadata]
requires-dist = [
{ name = "flask", specifier = ">=3.1.2" },
+ { name = "gunicorn", specifier = ">=25.1.0" },
{ name = "python-dotenv", specifier = ">=1.2.1" },
{ name = "yt-dlp", specifier = ">=2026.2.4" },
]
diff --git a/yt_radio.py b/yt_radio.py
index 3897899..52de4f1 100644
--- a/yt_radio.py
+++ b/yt_radio.py
@@ -5,7 +5,6 @@ import json
import threading
import random
import os
-import sys
from dotenv import load_dotenv
load_dotenv()
@@ -16,6 +15,7 @@ PLAYLIST = [
]
BASE_URL = os.environ.get("BASE_URL")
+PLAYLIST_URL = os.environ.get("PLAYLIST_URL")
RANDOMIZE_PLAYLIST = os.environ.get("RANDOMIZE_PLAYLIST")
METADATA = {}
@@ -107,12 +107,7 @@ def track(index):
)
-if __name__ == "__main__":
- if len(sys.argv) <= 1:
- print("ERROR: Specify link to YouTube playlist")
- playlist_url = sys.argv[1]
- print("Converting Playlist to YouTube Links")
- PLAYLIST = convert_playlist_to_links(playlist_url)
- print(PLAYLIST)
- print(f"OK. Now serving, you can access the m3u at {BASE_URL}/playlist.m3u")
- app.run(host="0.0.0.0", port=8000, threaded=True)
+if not PLAYLIST_URL:
+ print("ERROR: Please set PLAYLIST_URL environment variable")
+PLAYLIST = convert_playlist_to_links(PLAYLIST_URL)
+print(f"OK. Now serving, you can access the m3u at {BASE_URL}/playlist.m3u")
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage