-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from arsenstorm/youtube-dl
Youtube Downloader API
- Loading branch information
Showing
17 changed files
with
875 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.venv/ | ||
.DS_Store | ||
*.egg-info/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
FROM python:3.12-slim | ||
|
||
WORKDIR /app | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
libgl1 \ | ||
libgl1-mesa-glx \ | ||
libglib2.0-0 \ | ||
libomp-dev \ | ||
libopenblas-dev \ | ||
wget && \ | ||
wget https://github.com/<insert> && \ | ||
apt-get remove -y wget && apt-get autoremove -y && apt-get clean | ||
|
||
COPY requirements.txt . | ||
|
||
RUN pip install -r requirements.txt | ||
|
||
COPY . . | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 7004 | ||
|
||
# Set environment variables | ||
ENV IMAGETALKER_DEBUG=false | ||
ENV IMAGETALKER_PORT=7004 | ||
|
||
# If you are using Replicate to run Image Talker | ||
# then you can set the variables here: | ||
ENV IMAGETALKER_RUN_LOCAL=false | ||
ENV IMAGETALKER_REPLICATE_MODEL=imagetalker | ||
ENV IMAGETALKER_REPLICATE_API_KEY=sk... | ||
|
||
CMD ["python", "src/main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Image Talker API | ||
|
||
This API is based on the work found | ||
[here](https://github.com/<insert-link>). | ||
|
||
It’s designed to be used with Request Directory and you can find more details | ||
[here](https://request.directory/imagetalker) | ||
|
||
## Development | ||
|
||
### Install dependencies | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### Run the API | ||
|
||
```bash | ||
python src/main.py | ||
``` | ||
|
||
## Usage | ||
|
||
By default, the API runs on port 7004. | ||
|
||
```bash | ||
docker run -it -p7004:7004 ghcr.io/arsenstorm/imagetalker:latest | ||
``` | ||
|
||
## API | ||
|
||
To use the API, you need to send a POST request containing form data to the | ||
`/create` endpoint with the following parameters: | ||
|
||
#### Parameters | ||
|
||
- `image`: The image. | ||
- `audio`: The audio. | ||
|
||
#### Example Request | ||
|
||
As an example, we’ll... | ||
|
||
```bash | ||
curl -X POST http://localhost:7004/create -F "[email protected]/imagetalker/example_input.jpg" | ||
``` | ||
|
||
#### Example Response | ||
|
||
We get the following response: | ||
|
||
```json | ||
{ | ||
// ... | ||
"result": {}, | ||
"success": true | ||
} | ||
``` | ||
|
||
In this response, we’ve received these details: | ||
|
||
- `result`: The important stuff. | ||
- `success`: Whether the request was successful. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[project] | ||
name = "imagetalker" | ||
version = "0.1.0" | ||
description = "Add your description here" | ||
readme = "README.md" | ||
requires-python = ">=3.10" | ||
dependencies = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Flask==2.3.2 | ||
flask-cors>=4.0.2 | ||
python-dotenv==1.0.0 | ||
opencv-python==4.10.0.84 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
if __name__ == '__main__': | ||
print('Running ImageTalker') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
from flask import Flask, request, jsonify | ||
|
||
|
||
load_dotenv() | ||
|
||
DEBUG_MODE = os.getenv('IMAGETALKER_DEBUG', 'false').lower() == 'true' | ||
|
||
RUN_LOCAL = os.getenv('IMAGETALKER_RUN_LOCAL', 'false').lower() == 'true' | ||
# If we're running locally, then we don't need the replicate settings | ||
REPLICATE = { | ||
"id": os.getenv('IMAGETALKER_REPLICATE_MODEL', ''), | ||
"key": os.getenv('IMAGETALKER_REPLICATE_API_KEY', ''), | ||
} | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
@app.route('/create', methods=['POST']) | ||
def create(): | ||
if 'image' not in request.files: | ||
return jsonify({ | ||
"error": "You haven’t included an image in the `image` parameter.", | ||
"success": False | ||
}), 400 | ||
|
||
image = request.files['image'] | ||
|
||
if image.filename == '': | ||
return jsonify({ | ||
"error": "The image you have uploaded is invalid.", | ||
"success": False | ||
}), 400 | ||
|
||
if "audio" not in request.files: | ||
return jsonify({ | ||
"error": "You haven’t included an audio file via the `audio` parameter.", | ||
"success": False | ||
}), 400 | ||
|
||
audio = request.files["audio"] | ||
|
||
if audio.filename == "": | ||
return jsonify({ | ||
"error": "The audio file you have uploaded is invalid.", | ||
"success": False | ||
}), 400 | ||
|
||
# If we're running locally, then we use the local model, otherwise we use the replicate model | ||
|
||
try: | ||
return | ||
except Exception as e: | ||
return jsonify({ | ||
"error": str(e), | ||
"success": False | ||
}), 500 | ||
|
||
|
||
if __name__ == '__main__': | ||
port = int(os.getenv('IMAGETALKER_PORT', 7004)) | ||
app.run(host='0.0.0.0', port=port, debug=DEBUG_MODE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
downloads/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
FROM python:3.13-slim | ||
|
||
WORKDIR /app | ||
|
||
# Install system dependencies and uv in the same layer | ||
RUN apt-get update && apt-get install -y \ | ||
curl \ | ||
wget \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& curl -LsSf https://astral.sh/uv/install.sh | sh \ | ||
&& . "${HOME}/.local/bin/env" | ||
|
||
# Copy project files | ||
COPY pyproject.toml . | ||
COPY uv.lock . | ||
|
||
# uv stuff | ||
RUN . "${HOME}/.local/bin/env" \ | ||
&& uv venv .venv \ | ||
&& . .venv/bin/activate \ | ||
&& uv pip install -e . \ | ||
# Install yt-dlp | ||
&& uv pip install -U --pre yt-dlp | ||
|
||
# Copy application code | ||
COPY . . | ||
|
||
# Create downloads directory | ||
RUN mkdir -p src/downloads | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 7005 | ||
|
||
# Set environment variables | ||
ENV YOUTUBEDL_DEBUG=false \ | ||
YOUTUBEDL_PORT=7005 \ | ||
R2_ENDPOINT="" \ | ||
R2_BUCKET="" \ | ||
R2_PUBLIC_URL="" \ | ||
PATH="/app/.venv/bin:${PATH}" | ||
|
||
# Run the app using the Python from the virtual environment | ||
CMD ["/app/.venv/bin/python", "src/main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Youtube DL API | ||
|
||
This API is based on the work found | ||
[here](https://github.com/ytdl-org/youtube-dl). | ||
|
||
It’s designed to be used with Request Directory and you can find more details | ||
[here](https://request.directory/youtube-dl). | ||
|
||
## Development | ||
|
||
### Install dependencies | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### Run the API | ||
|
||
```bash | ||
python src/main.py | ||
``` | ||
|
||
## Usage | ||
|
||
By default, the API runs on port 7005. | ||
|
||
```bash | ||
docker run -it -p7005:7005 ghcr.io/arsenstorm/youtube-dl:latest | ||
``` | ||
|
||
## API | ||
|
||
To use the API, you need to send a POST request containing JSON data to the | ||
`/download` endpoint with the following parameters: | ||
|
||
#### Parameters | ||
|
||
- `url`: The URL of the video to download. | ||
|
||
#### Example Request | ||
|
||
As an example, we’ll use the following URL: | ||
|
||
```bash | ||
curl -X POST http://localhost:7005/download -H "Content-Type: application/json" -d '{"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"}' | ||
``` | ||
|
||
#### Example Response | ||
|
||
We get the following response: | ||
|
||
```json | ||
{ | ||
"result": { | ||
"video_id": "dQw4w9WgXcQ", | ||
"thumbnails": { | ||
"max": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg", // 1280x720 | ||
"high": "https://i.ytimg.com/vi/dQw4w9WgXcQ/sddefault.jpg", // 640x360 | ||
"mid": "https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg", // 480x360 | ||
"low": "https://i.ytimg.com/vi/dQw4w9WgXcQ/mqdefault.jpg", // 320x180 | ||
"min": "https://i.ytimg.com/vi/dQw4w9WgXcQ/default.jpg" // 120x90 | ||
}, | ||
"download_url": "https://request.directory/download/..." // The downloaded video expires after 24 hours | ||
}, | ||
"success": true | ||
} | ||
``` | ||
|
||
In this response, we’ve received these details: | ||
|
||
- `result`: The important stuff. | ||
- `success`: Whether the request was successful. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[project] | ||
name = "youtube-dl" | ||
version = "0.1.0" | ||
description = "Add your description here" | ||
readme = "README.md" | ||
requires-python = ">=3.13" | ||
dependencies = [ | ||
"boto3>=1.35.97", | ||
"Flask==2.3.2", | ||
"flask-cors>=4.0.2", | ||
"python-dotenv==1.0.0", | ||
"yt-dlp==2024.3.10", | ||
] |
Oops, something went wrong.