From 99faecabd9b259f0c0c355947182eee68eebaf48 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 6 Jun 2023 17:01:17 -0400 Subject: [PATCH] Switch to using yt-dlp via subprocess --- Dockerfile | 12 +++++------- main.py | 7 ++++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8a4042c..7300cd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,14 @@ FROM python:3 # Install dependencies -RUN pip3 install python-dotenv -RUN pip3 install discord.py -RUN pip3 install pynacl -RUN pip3 install youtube_dl -RUN pip3 install git+https://github.com/Cupcakus/pafy +RUN apt update +RUN apt install -y ffmpeg +RUN pip3 install discord.py python-dotenv pynacl WORKDIR /usr/src/app COPY . . -RUN apt update -RUN apt install -y ffmpeg +RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp +RUN chmod a+rx /usr/local/bin/yt-dlp CMD ["python3", "main.py"] diff --git a/main.py b/main.py index 334016f..3fe51d2 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,10 @@ import os +import subprocess + from dotenv import load_dotenv from functools import partial import discord -import pafy class Client(discord.Client): def __init__(self): @@ -28,8 +29,8 @@ class Client(discord.Client): user = message.channel.recipient.id # Download file if it doesn't exist already - if not os.path.exists(url): - pafy.new(url).getbestaudio().download(filepath=v_id) + if not os.path.exists(v_id): + subprocess.run(["yt-dlp", "-f", "ba/b", "-o", v_id, url]) for chan in self.get_all_channels(): # Check if Channel is Voice Channel