How do I search for and download videos in pytube?

Question:

I want to create a song or video downloader in python with pytube. I have only seen that you can download videos if you have the link. I want to use the search feature in pytube and then download the first video that comes up. can you show me a snippet of how you can do this.

I have tried using the search in pytube but I do not know how to grab a link from a video or download it.

Asked By: Gaboni Bones

||

Answers:

Google is your friend. Try searching for your answer online before posting a question here.

Regardless, this code should return a dictionary of results from your search link, link

from pytube import Search

s = Search('Your search here')
searchResults = {}
for v in s.results:
  searchResults[v.title] = v.watch_url

To return a list of URLs:

from pytube import Search

s = Search('Your search here')
searchResults = []
for v in s.results:
  searchResults.append(v.watch_url)
Answered By: Cheesebellies
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.