Spaces:
Runtime error
Runtime error
import gradio as gr | |
import pytubefix | |
import base64 | |
from pytubefix.cli import on_progress | |
proxies = { | |
"https": "344444:444" | |
} | |
def download_youtube(url, choice, res): | |
encoded_f1="" | |
yt = pytubefix.yt = pytubefix.YouTube(url, proxies=proxies,use_po_token=True, allow_oauth_cache=True, token_file="/home/m/public_html/1.json", on_progress_callback=on_progress) | |
if choice == 'mp3': | |
audio = yt.streams.get_audio_only() | |
print(f"Downloading {audio.title} as MP3") | |
return audio.download(mp3=True),audio.download(mp3=True), None | |
elif choice == 'mp4': | |
video = yt.streams.get_highest_resolution() | |
print(f"Downloading {video.title} at {video.resolution}") | |
# with open(audio.download(), "rb") as f1,open("b64.txt", "w") as f2: | |
# encoded_f1 = base64.b64encode(f1.read()) | |
# encoded_f1=str(encoded_f1,'ascii', 'ignore') | |
return video.download(),None,video.download() | |
else: | |
return "Invalid choice" | |
choice_options = ["mp3", "mp4"] | |
resolution_options = ["720p", "1080p", "2160p"] | |
iface = gr.Interface(fn=download_youtube, | |
inputs=["text", | |
gr.Radio(choices=choice_options), | |
gr.Radio(choices=resolution_options)], | |
outputs=[gr.File(),gr.Audio(),gr.Video()], | |
title="Download Youtube Video", | |
examples=[["https://www.youtube.com/watch?v=nk0GiiwRS24","mp3",None],["https://www.youtube.com/watch?v=nk0GiiwRS24","mp4","720p"]]) | |
iface.launch() |