Kod: Označi sve
File "converter.py", line 124, in <module>
b_video = vbitrate_askif()
File "converter.py", line 49, in vbitrate_askif
b_video = str(vbitrate_calculate())
File "converter.py", line 17, in vbitrate_calculate
filebitrate = vidstat.st_size / int(math.floor(vidlength))
TypeError: a float is required
Kod: Označi sve
if ('h' in url) and ('t' in url) and ('p' in url) and (':' in url) and ('/' in url):Kod: Označi sve
#!/usr/bin/env python
import os, sys, subprocess, math
audiopf = "audioprep"
vf = "video.mp4"
addparm = ""
def vbitrate_calculate():
vidlengthp1 = subprocess.Popen(["ffprobe", "-loglevel", "error", "-show_streams", vf], stdout=subprocess.PIPE)
vidlengthp2 = subprocess.Popen(["grep", "duration"], stdin=vidlengthp1.stdout, stdout=subprocess.PIPE)
vidlengthp3 = subprocess.Popen(["cut", "-f2", "-d="], stdin=vidlengthp2.stdout, stdout=subprocess.PIPE)
vidlengtht = vidlengthp3.communicate()[0]
vidlengthstr = vidlengtht.decode("utf-8")
vidlength = vidlengthstr.splitlines()[1]
vidstat = os.stat(vf)
filebitrate = vidstat.st_size / int(math.floor(vidlength))
vbitrate = filebitrate - b_audio
return vbitrate
def remove_o_files():
afexists = os.path.isfile(afilename)
if afexists == True:
os.remove(afilename)
afiexists = os.path.isfile(afilename+".part")
if afiexists == True:
os.remove(afilename+".part")
afiiexists = os.path.isfile(rstr)
if afiiexists == True:
os.remove(rstr)
afiiiexists = os.path.isfile(fafilename)
if afiiiexists == True:
os.remove(fafilename)
vfexists = os.path.isfile(vfilename)
if vfexists == True:
os.remove(vfilename)
vfiexists = os.path.isfile(vfilename+".part")
if vfiexists == True:
os.remove(vfilename+".part")
vfiiexists = os.path.isfile(vf)
if vfiiexists == True:
os.remove(vf)
def vbitrate_askif():
b_askif = input("Do you want to input the target video stream bitrate yourself of let it be calculated? (y/n) ")
if b_askif == "y":
b_video = input("Input target bitrate: ")
else:
b_video = str(vbitrate_calculate())
if b_video[-1:]!="k":
b_video = b_video + "k"
return b_video
url = input("URL: ")
if ('h' in url) and ('t' in url) and ('p' in url) and (':' in url) and ('/' in url):
os.system("youtube-dl -F " + url)
else:
print("Incorrect input")
sys.exit()
audiohack = input("192k audio? (y/n) ")
if audiohack=="y":
audiofile = 22
b_audio=192
else:
audiofile = 140
b_audio=128
videofile = input("Video number (mp4): ")
vfilenamep = subprocess.Popen(["youtube-dl", "-f", str(videofile), url, "--get-filename"], stdout=subprocess.PIPE)
vfilenamet = vfilenamep.communicate()
vfilenamestr = vfilenamet[0]
vfilename = vfilenamestr[:-1].decode("utf-8")
vextstr = vfilenamestr[-5:]
vext = vextstr[:-1].decode("utf-8")
if vext!=".mp4":
print ("Unsupported file container format")
sys.exit()
afilenamep = subprocess.Popen(["youtube-dl", "-f", str(audiofile), url, "--get-filename"], stdout=subprocess.PIPE)
afilenamet = afilenamep.communicate()
afilenamestr = afilenamet[0]
afilename = afilenamestr[:-1].decode("utf-8")
aextstr = afilenamestr[-5:]
aext = aextstr[:-1].decode("utf-8")
rstr = audiopf + str(aext)
fafilename = "audio" + str(aext)
remove_o_files()
os.system("youtube-dl -f " + str(videofile) + " " + url)
os.rename(vfilename, vf)
os.system("youtube-dl -f " + str(audiofile) + " " + url)
os.rename(afilename, rstr)
os.system("ffmpeg -i " + rstr + " -vn -c:a copy " + '"' + fafilename + '"')
if audiohack=="y":
os.remove(rstr)
print("Files have been downloaded")
print("Select one of the operations below:")
print("0 - quit")
print("1 - stream copy/join audio and video files")
print("2 - audio: libopus; video: libtheora")
print("3 - audio: flac; video: libtheora")
print("4 - audio: mp3; video: libxvid")
selectoperation = input("Option: ")
if selectoperation=="0":
sys.exit()
else:
outfilename = input("Enter output file name (without extension): ")
if selectoperation=="1":
os.system("ffmpeg -i " + fafilename + " -i " + vf + " -c:a copy -c:v copy " + outfilename + ".mp4")
print("Output file is saved as " + outfilename + ".mp4")
if selectoperation=="2":
mqscale = input("Do you want the best quality video, regardless of file size? (y/n) ")
if mqscale=="y":
os.system("ffmpeg -i " + fafilename + " -i " + vf + " -c:a libopus -b:a " + str(b_audio) + "k -c:v libtheora -qscale:v 10 " + addparm + " " + outfilename + ".ogv")
else:
b_video = vbitrate_askif()
os.system("ffmpeg -i " + fafilename + " -i " + vf + " -c:a libopus -b:a " + str(b_audio) + "k -c:v libtheora -b:v " + b_video + addparm + " " + outfilename + ".ogv")
print("Output file is saved as " + outfilename + ".ogv")
remove_o_files()