Skip to content

Instantly share code, notes, and snippets.

@0xKD
Created May 20, 2021 15:15
Show Gist options
  • Save 0xKD/a19b4d8ed349f095865226b1b69a9359 to your computer and use it in GitHub Desktop.
Save 0xKD/a19b4d8ed349f095865226b1b69a9359 to your computer and use it in GitHub Desktop.
youdl-gui-bulk
import youtube_dl
from gooey import Gooey, GooeyParser
from youtube_dl import read_batch_urls, preferredencoding
def on_progress(d):
print("", flush=True)
audio_options = {
"format": "bestaudio/best",
"postprocessors": [
{
"key": "FFmpegExtractAudio",
"preferredcodec": "mp3",
"preferredquality": "192",
}
],
}
# [download] 3.1% of 444.80MiB at 5.31MiB/s ETA 01:21
@Gooey(progress_regex=r"^\[\w+\]\s+(\d+).+$", hide_progress_msg=True)
def main():
parser = GooeyParser(description="Download YouTube videos")
parser.add_argument(
"file",
metavar="Select File",
help="File with YouTube video links",
widget="FileChooser"
)
parser.add_argument(
"-x",
"--extract-audio",
action="store_true",
metavar="Extract Audio",
help="Check this box to only download audio",
)
args = parser.parse_args()
ydl_options = {"format": "mp4", "progress_hooks": [on_progress]}
if args.extract_audio:
ydl_options.update(audio_options)
with open(args.file) as f:
urls = read_batch_urls(f)
_enc = preferredencoding()
urls = [url.decode(_enc, 'ignore') if isinstance(url, bytes) else url for url in urls]
with youtube_dl.YoutubeDL(ydl_options) as ydl:
ydl.download(urls)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment