diff --git a/mumbledj/download_audio.py b/mumbledj/download_audio.py new file mode 100644 index 0000000..39f340b --- /dev/null +++ b/mumbledj/download_audio.py @@ -0,0 +1,26 @@ +#---------------------# +# MumbleDJ # +# By Matthieu Grieger # +#---------------------#--------------------------------------------------# +# download_audio.py # +# Downloads audio (ogg format) from specified YouTube ID. If no ogg file # +# exists, it creates an empty file called .video_fail that tells the Lua # +# side of the program that the download failed. .video_fail will get # +# deleted on the next successful download. # +#------------------------------------------------------------------------# + +import pafy +from sys import argv +from os.path import isfile +from os import remove + +url = argv[1] +video = pafy.new(url) + +try: + video.oggstreams[0].download(filepath = "song.ogg", quiet = True) + if isfile(".video_fail"): + remove(".video_fail") +except: + with open(".video_fail", "w+") as f: + f.close()