-1

So I have a for loop with a lot of YouTube links, and I want to download them in that loop. There is an error that says 'Unavailable Video' when I do this:

for post in hot_posts:
    yt = YouTube(post.url)
    yt.download()

So let me explain this code, I'm using PRAW to get hot posts from Reddit, and I want to download them in a for loop. hot_posts is a variable for 25 hot posts and post.url is the url of the post.

When I remove the for loop and put a link in the YouTube() part, it works perfectly. I've also tried str(post.url) to make sure it's a string.

How does this work in a for loop???

snocc
  • 19
  • 4
  • I suggest using a `try`-`except` block to catch the exception that is raised when a download fails. Unfortunately, your question doesn't include enough detail to determine which exception is being raised, and from which line. – jarhill0 Jul 24 '19 at 00:09

2 Answers2

0

Using pytube3 you can do download like: yt.streams.get_highest_resolution().download()

Martin
  • 770
  • 6
  • 22
0

This error is raised in some cases if you are using an older version of pytube. Try this:

python -m pip uninstall pytube pytube3 pytubex pytube4

then:

pip install pytube         
gab
  • 792
  • 1
  • 10
  • 36