simpleQ
This commit is contained in:
parent
1efb2e1775
commit
713ab9c44a
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
venv/
|
venv/
|
||||||
|
node_modules/
|
16
main.py
16
main.py
|
@ -7,10 +7,12 @@ import time
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
# Define a data model for the queue item
|
# Define a data model for the queue item
|
||||||
class VideoLink(BaseModel):
|
class VideoLink(BaseModel):
|
||||||
url: str
|
url: str
|
||||||
|
|
||||||
|
|
||||||
# Queue to store video URLs
|
# Queue to store video URLs
|
||||||
video_queue = []
|
video_queue = []
|
||||||
current_video = None
|
current_video = None
|
||||||
|
@ -18,7 +20,8 @@ current_video = None
|
||||||
# VLC player instance
|
# VLC player instance
|
||||||
vlc_instance = vlc.Instance()
|
vlc_instance = vlc.Instance()
|
||||||
player = vlc_instance.media_player_new()
|
player = vlc_instance.media_player_new()
|
||||||
player.fullscreen = True
|
player.set_fullscreen(True)
|
||||||
|
|
||||||
|
|
||||||
# Add video URL to the queue
|
# Add video URL to the queue
|
||||||
@app.post("/add")
|
@app.post("/add")
|
||||||
|
@ -26,11 +29,13 @@ def add_video(video_link: VideoLink):
|
||||||
video_queue.append(video_link.url)
|
video_queue.append(video_link.url)
|
||||||
return {"message": "Video added to the queue"}
|
return {"message": "Video added to the queue"}
|
||||||
|
|
||||||
|
|
||||||
# Get current queue
|
# Get current queue
|
||||||
@app.get("/queue")
|
@app.get("/queue")
|
||||||
def get_queue():
|
def get_queue():
|
||||||
return {"queue": video_queue}
|
return {"queue": video_queue}
|
||||||
|
|
||||||
|
|
||||||
# Control playback: play, pause, stop
|
# Control playback: play, pause, stop
|
||||||
@app.post("/control/{action}")
|
@app.post("/control/{action}")
|
||||||
def control_playback(action: str):
|
def control_playback(action: str):
|
||||||
|
@ -42,6 +47,11 @@ def control_playback(action: str):
|
||||||
player.stop()
|
player.stop()
|
||||||
elif action == "mute":
|
elif action == "mute":
|
||||||
player.audio_toggle_mute()
|
player.audio_toggle_mute()
|
||||||
|
elif action == "fullscreen":
|
||||||
|
if player.get_fullscreen():
|
||||||
|
player.set_fullscreen(False)
|
||||||
|
else:
|
||||||
|
player.set_fullscreen(True)
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=400, detail="Invalid action")
|
raise HTTPException(status_code=400, detail="Invalid action")
|
||||||
return {"message": f"Player action {action} executed"}
|
return {"message": f"Player action {action} executed"}
|
||||||
|
@ -52,6 +62,7 @@ def seek(seconds: int):
|
||||||
player.set_time(seconds * 1000)
|
player.set_time(seconds * 1000)
|
||||||
return {"message": f"Seeked to {seconds} seconds"}
|
return {"message": f"Seeked to {seconds} seconds"}
|
||||||
|
|
||||||
|
|
||||||
# Function to play videos from the queue
|
# Function to play videos from the queue
|
||||||
def play_videos():
|
def play_videos():
|
||||||
global current_video
|
global current_video
|
||||||
|
@ -68,6 +79,7 @@ def play_videos():
|
||||||
time.sleep(1) # Give some time for the player to start
|
time.sleep(1) # Give some time for the player to start
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
# Start the video playing thread
|
# Start the video playing thread
|
||||||
video_thread = threading.Thread(target=play_videos, daemon=True)
|
video_thread = threading.Thread(target=play_videos, daemon=True)
|
||||||
video_thread.start()
|
video_thread.start()
|
||||||
|
@ -75,4 +87,4 @@ video_thread.start()
|
||||||
# Run FastAPI
|
# Run FastAPI
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
uvicorn.run(app, host="127.0.0.1", port=1337)
|
||||||
|
|
129
readme.md
Normal file
129
readme.md
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
Sure, here is a "leet" README for your project `SpaceInvaderz`:
|
||||||
|
|
||||||
|
# 🌌 SpaceInvaderz API 🌌
|
||||||
|
|
||||||
|
Welcome to the **SpaceInvaderz** API! Control your video playback like a true interstellar commander using this FastAPI-powered interface.
|
||||||
|
|
||||||
|
## 🚀 Getting Started
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- **Python** installed
|
||||||
|
- Required Python packages: `yt-dlp`, `python-vlc`, `fastapi`, `uvicorn`
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
1. **Clone the repository:**
|
||||||
|
```sh
|
||||||
|
git clone gitea.telavivmakers.space/SpaceInvaderz/spaceinvaderz.git
|
||||||
|
cd spaceinvaderz
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Install dependencies:**
|
||||||
|
```sh
|
||||||
|
pip install yt-dlp python-vlc fastapi uvicorn
|
||||||
|
# or
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Run the server:**
|
||||||
|
```sh
|
||||||
|
python main.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Your SpaceInvaderz API should now be running on `http://0.0.0.0:1337`.
|
||||||
|
|
||||||
|
## 🌌 API Endpoints
|
||||||
|
|
||||||
|
### 1. Add Video to Queue
|
||||||
|
|
||||||
|
**Description:** Adds a video to the playback queue.
|
||||||
|
|
||||||
|
- **URL:** `/add`
|
||||||
|
- **Method:** `POST`
|
||||||
|
- **Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"url": "VIDEO_URL"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### PowerShell:
|
||||||
|
```powershell
|
||||||
|
$videoUrl = "https://www.youtube.com/watch?v=u-Wi1_O3pKQ"
|
||||||
|
Invoke-RestMethod -Uri http://localhost:1337/add -Method Post -Body (@{url = $videoUrl} | ConvertTo-Json) -ContentType "application/json"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### cURL:
|
||||||
|
```sh
|
||||||
|
curl -X POST "http://localhost:1337/add" -H "Content-Type: application/json" -d "{\"url\":\"YOUR_VIDEO_URL\"}"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Get Current Queue
|
||||||
|
|
||||||
|
**Description:** Retrieves the current queue of videos.
|
||||||
|
|
||||||
|
- **URL:** `/queue`
|
||||||
|
- **Method:** `GET`
|
||||||
|
|
||||||
|
#### PowerShell:
|
||||||
|
```powershell
|
||||||
|
Invoke-RestMethod -Uri http://localhost:1337/queue -Method Get
|
||||||
|
```
|
||||||
|
|
||||||
|
#### cURL:
|
||||||
|
```sh
|
||||||
|
curl -X GET "http://localhost:1337/queue"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Control Playback
|
||||||
|
|
||||||
|
**Description:** Control video playback with actions like play, pause, stop, and mute.
|
||||||
|
|
||||||
|
- **URL:** `/control/{action}`
|
||||||
|
- **Method:** `POST`
|
||||||
|
- **Actions:** `play`, `pause`, `stop`, `mute`
|
||||||
|
|
||||||
|
#### PowerShell:
|
||||||
|
```powershell
|
||||||
|
$action = "play" # Or "pause", "stop", "mute"
|
||||||
|
Invoke-RestMethod -Uri http://localhost:1337/control/$action -Method Post
|
||||||
|
```
|
||||||
|
|
||||||
|
#### cURL:
|
||||||
|
```sh
|
||||||
|
action="play" # Or "pause", "stop", "mute"
|
||||||
|
curl -X POST "http://localhost:1337/control/$action"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Seek Video
|
||||||
|
|
||||||
|
**Description:** Seek to a specific time in the video.
|
||||||
|
|
||||||
|
- **URL:** `/seek/{seconds}`
|
||||||
|
- **Method:** `POST`
|
||||||
|
- **Parameters:** `seconds` (Time in seconds to seek to)
|
||||||
|
|
||||||
|
#### PowerShell:
|
||||||
|
```powershell
|
||||||
|
$seconds = 120 # Time in seconds
|
||||||
|
Invoke-RestMethod -Uri http://localhost:1337/seek/$seconds -Method Post
|
||||||
|
```
|
||||||
|
|
||||||
|
#### cURL:
|
||||||
|
```sh
|
||||||
|
seconds=120 # Time in seconds
|
||||||
|
curl -X POST "http://localhost:1337/seek/$seconds"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🌌 Contribute
|
||||||
|
|
||||||
|
Feel free to submit issues, fork the repo and create pull requests. May the code be with you! 🚀
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
With **SpaceInvaderz**, you're not just watching videos, you're commanding an intergalactic fleet of multimedia! 🌠
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Happy coding, space invaders! 👾
|
Loading…
Reference in New Issue
Block a user