Skip to content

Commit

Permalink
compose update
Browse files Browse the repository at this point in the history
  • Loading branch information
neonwatty committed Jul 17, 2024
1 parent ada2c13 commit b9ac313
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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=.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
27 changes: 21 additions & 6 deletions youtube_downloader/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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__":
Expand Down
31 changes: 25 additions & 6 deletions youtube_downloader/yt_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down

0 comments on commit b9ac313

Please sign in to comment.