diff --git a/Dockerfile b/Dockerfile index ce623a2..eeacfc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,11 @@ FROM python:3.10-slim +RUN apt-get update && apt-get install -y \ + build-essential \ + software-properties-common \ + ffmpeg \ + && rm -rf /var/lib/apt/lists/* + WORKDIR /home ENV PYTHONPATH=. diff --git a/README.md b/README.md index 9fd9f62..f2ad5c3 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,5 @@ Or run via Docker ```sh docker compose up ``` + +If running natively (not Docker) you will need [ffmpeg](https://www.ffmpeg.org/download.html) installed on your machine. \ No newline at end of file diff --git a/youtube_downloader/app.py b/youtube_downloader/app.py index de2cf48..efe4e74 100644 --- a/youtube_downloader/app.py +++ b/youtube_downloader/app.py @@ -29,16 +29,18 @@ with gr.Row(): og_video = gr.Video( - visible=False, + visible=True, + show_download_button=True, + show_label=True, + label="your video", + format="mp4", + width="50vw", + height="50vw", ) @download_button.click(inputs=[url_input, resolution_dropdown], outputs=[og_video]) def download_this(url_input, resolution_dropdown): - # temporary_video_location = tmpdirname + "/original_" + str(uuid.uuid4()) + ".mp4" - # temporary_audio_location = temporary_video_location.replace("mp4", "mp3") - - temporary_video_location = download_video(url_input, tmpdirname) - temporary_audio_location = temporary_video_location.replace("mp4", "mp3") + temporary_video_location = download_video(url_input, tmpdirname, resolution_dropdown) filename = open(temporary_video_location, "rb") byte_file = io.BytesIO(filename.read()) @@ -58,6 +60,19 @@ def download_this(url_input, resolution_dropdown): return new_og_video + with gr.TabItem("💡 About"): + with gr.Blocks() as about: + gr.Markdown( + ( + "### About \n" + "Some notes on how this works: \n\n" + "1. **youtube / google login**: you do **not** need to be logged into a google account to use the app, with one exception: age restricted videos" + "2. **age restricted videos**: this app cannot fetch age restricted videos yet, which requires a user login to google / youtube - this feature is not yet available" + "3. **video resolution**: not all videos have all possible resolutions, so you may not be able to fetch the resolution you want for some videos (as they don't exist) \n" + "4. **recommended hardware**: this is a very light weight app, so minimum specs should work fine" + "5. **proxies**: there is an option in the yt_download module to enter proxy server ips" + ) + ) if __name__ == "__main__": diff --git a/youtube_downloader/yt_download.py b/youtube_downloader/yt_download.py index 495418b..002b1c5 100644 --- a/youtube_downloader/yt_download.py +++ b/youtube_downloader/yt_download.py @@ -12,27 +12,46 @@ def is_valid_youtube_url(url: str) -> bool: return re.match(pattern, url) is not None -def download_video(url: str, savedir: str, my_proxies: dict = {}) -> str: +def download_video(url: str, savedir: str, resolution_dropdown: str, my_proxies: dict = {}) -> str: try: print("Downloading video from youtube...") if is_valid_youtube_url(url): - with YoutubeDL() as ydl: + with YoutubeDL() as ydl: info_dict = ydl.extract_info(url, download=False) video_url = info_dict.get("url", None) video_id = info_dict.get("id", None) - video_title = info_dict.get('title', None) + video_title = info_dict.get("title", None) if video_title is None: savepath = savedir + "/" + video_id + ".mp4" else: savepath = savedir + "/" + video_title + ".mp4" - print("Title: " + video_title) - ydl_opts = { - "format": "bestvideo[height<=720]+bestaudio/best", + "format": "bestvideo+bestaudio/best", "merge_output_format": "mp4", "outtmpl": savepath, } + if resolution_dropdown == "1080": + ydl_opts = { + "format": "bestvideo[height<=1080]+bestaudio/best", + "merge_output_format": "mp4", + "outtmpl": savepath, + } + + if resolution_dropdown == "720": + ydl_opts = { + "format": "bestvideo[height<=720]+bestaudio/best", + "merge_output_format": "mp4", + "outtmpl": savepath, + } + + if resolution_dropdown == "360": + ydl_opts = { + "format": "bestvideo[height<=360]+bestaudio/best", + "merge_output_format": "mp4", + "outtmpl": savepath, + } + with yt_dlp.YoutubeDL(ydl_opts) as ydl: ydl.download([url])