5

While trying to download a YouTube video from python, I come across this error AttributeError: 'YouTube' object has no attribute 'get_videos'.

Last line causes the error.

import pytube

link = ""
yt = pytube.YouTube(link)
videos = yt.get_videos()

Thanks!

Vallie
  • 472
  • 6
  • 16
user9594573
  • 79
  • 1
  • 5
  • 2
    What made you think the object _would_ have that method? I don't see anything remotely similar in [the readme](https://github.com/nficano/pytube) or [the docs](https://python-pytube.readthedocs.io/en/latest/user/quickstart.html). – abarnert Apr 04 '18 at 05:14

2 Answers2

15
import pytube
link = "https://www.youtube.com/watch?v=mpjREfvZiDs"
yt = pytube.YouTube(link)
stream = yt.streams.first()
stream.download()

Try above code. Here and here similar code which does not work.

Vallie
  • 472
  • 6
  • 16
  • Thanks a lot for the quick reply. Works pretty well. However, two adjoining add-ons with this. 1. Any line to show the progress of the download. 2. Could this be amended to crop only a small duration from the link and download/save that duration bit? Thanks, again. – user9594573 Apr 04 '18 at 06:16
  • This is a new question altogether. I guess progress is possible but not sure of crop. – Vallie Apr 04 '18 at 06:24
  • @Vallie, how do I set the download location? – mLstudent33 Aug 18 '19 at 04:09
  • Refer to this [doc](https://python-pytube.readthedocs.io/en/latest/user/quickstart.html#downloading-a-video) Specify your path in the parenthesis download('/tmp') – Vallie Aug 20 '19 at 10:27
1
from pytube import YouTube
yt = YouTube("Please copy and paste the video link here")
print(yt.title)
stream = yt.streams.first()
stream.download()
  • While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. [From Review](/review/low-quality-posts/25983293) – double-beep Apr 29 '20 at 08:40