Skip to content

Commit

Permalink
Merge pull request #4 from arsenstorm/youtube-dl
Browse files Browse the repository at this point in the history
Youtube Downloader API
  • Loading branch information
arsenstorm authored Jan 11, 2025
2 parents 0dd6054 + e162e1f commit a862cc2
Show file tree
Hide file tree
Showing 17 changed files with 875 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/generate_upload_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ on:
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
id-token: write
packages: write
contents: read
attestations: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 2

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.venv/
.DS_Store
*.egg-info/
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ To see details about the Face Landmarks API, go to the [Face Landmarks README](.

To see details about the Age and Gender API, go to the [Age and Gender README](./ageandgender/README.md)

<sub>Copyright © 2024 Arsen Shkrumelyak. All rights reserved.</sub>
## YouTube Downloader API

To see details about the YouTube Downloader API, go to the [YouTube Downloader README](./youtubedl/README.md)

<sub>Copyright © 2024 Arsen Shkrumelyak. All rights reserved.</sub>
1 change: 1 addition & 0 deletions imagetalker/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
34 changes: 34 additions & 0 deletions imagetalker/Dockerfile
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"]
64 changes: 64 additions & 0 deletions imagetalker/README.md
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.
7 changes: 7 additions & 0 deletions imagetalker/pyproject.toml
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 = []
4 changes: 4 additions & 0 deletions imagetalker/requirements.txt
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
2 changes: 2 additions & 0 deletions imagetalker/src/imagetalker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if __name__ == '__main__':
print('Running ImageTalker')
63 changes: 63 additions & 0 deletions imagetalker/src/main.py
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)
2 changes: 2 additions & 0 deletions youtube-dl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
downloads/
1 change: 1 addition & 0 deletions youtube-dl/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
43 changes: 43 additions & 0 deletions youtube-dl/Dockerfile
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"]
72 changes: 72 additions & 0 deletions youtube-dl/README.md
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.
13 changes: 13 additions & 0 deletions youtube-dl/pyproject.toml
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",
]
Loading

0 comments on commit a862cc2

Please sign in to comment.