I have written a small python program to download videos from youtube. The function takes a URL as input and then downloads it.
Code:
def download(i):
global path
global c
global threads
try:
fh1 = open(path + "done.txt","a")
fh = open(path +"err.txt", "a")
video = pafy.new(i)
name = str(c) + '. ' + video.title
c += 1
try:
for p in ('|', '?', '\\', '/', ':', '*', '<', '>', '\"'):
name = name.replace(p, '_')
best = video.getbest(preftype="mp4")
print("Downloading "+name+"...")
best.download(quiet=False, filepath= path + name + '.' + best.extension)
print("Done Downloading "+name)
fh1.write("Done : " +name+ '\n')
fh1.close()
best.download(quiet=False, filepath= path + name + '.' + best.extension)
line is showing the download percentage speed time left and some other stuff but I cannot find a proper way to get the data that is being shown there. I want to store the data in some variable so that I can show the data in some other place or write it in some file.