get-pytube / pytube3

A lightweight, dependency-free Python 3 library (and command-line utility) for downloading YouTube Videos.
https://pytube3.readthedocs.io
Other
178 stars 55 forks source link

AttributeError: 'NoneType' object has no attribute 'filesize_approx' #115

Closed STEM-Coders closed 3 years ago

STEM-Coders commented 3 years ago

Error: AttributeError: 'NoneType' object has no attribute 'filesize_approx' My Code:

from pytube import YouTube
from pytube import Playlist
import shutil

def getVideo(url):
    yt = YouTube(url).streams.get_by_resolution("720p").download()
    return yt

print("YouTube To MP4. By: Name.")

inp = input(f"Video (1)\nPlayList(2)\nOr type Exit to quit\n")

if inp == "1":
    url = input("Youtube URL: ")
    print("Your YouTube file: " + getVideo(url).title())
elif inp == "2":
    # create folder with playlist.
    Purl = input("Youtube PlayList URL: ")
    for vid in Playlist(Purl).video_urls:
        print(getVideo(vid))
        # shutil.move(getVideo(vid), Playlist(Purl).title())
    print("Your YouTube PlayList Folder: " + Playlist(Purl).title)
elif inp.lower() == "exit":
    exit()
else:
   print("Not Valid Input.")
STEM-Coders commented 3 years ago

If you trying doing print(YouTube(url).streams.get_by_resolution("720p")) then it prints None.