Switch to using yt-dlp via subprocess

This commit is contained in:
Roman 2023-06-06 17:01:17 -04:00
parent 824e818888
commit 99faecabd9
2 changed files with 9 additions and 10 deletions

View file

@ -1,16 +1,14 @@
FROM python:3 FROM python:3
# Install dependencies # Install dependencies
RUN pip3 install python-dotenv RUN apt update
RUN pip3 install discord.py RUN apt install -y ffmpeg
RUN pip3 install pynacl RUN pip3 install discord.py python-dotenv pynacl
RUN pip3 install youtube_dl
RUN pip3 install git+https://github.com/Cupcakus/pafy
WORKDIR /usr/src/app WORKDIR /usr/src/app
COPY . . COPY . .
RUN apt update RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp
RUN apt install -y ffmpeg RUN chmod a+rx /usr/local/bin/yt-dlp
CMD ["python3", "main.py"] CMD ["python3", "main.py"]

View file

@ -1,9 +1,10 @@
import os import os
import subprocess
from dotenv import load_dotenv from dotenv import load_dotenv
from functools import partial from functools import partial
import discord import discord
import pafy
class Client(discord.Client): class Client(discord.Client):
def __init__(self): def __init__(self):
@ -28,8 +29,8 @@ class Client(discord.Client):
user = message.channel.recipient.id user = message.channel.recipient.id
# Download file if it doesn't exist already # Download file if it doesn't exist already
if not os.path.exists(url): if not os.path.exists(v_id):
pafy.new(url).getbestaudio().download(filepath=v_id) subprocess.run(["yt-dlp", "-f", "ba/b", "-o", v_id, url])
for chan in self.get_all_channels(): for chan in self.get_all_channels():
# Check if Channel is Voice Channel # Check if Channel is Voice Channel