Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if __name__ == '__main__':
- import moviepy.editor as mp
- Audio_type = input("Please inpute a audio type(mp3, wav): ")
- while Audio_type != "mp3" and Audio_type != "wav":
- Audio_type = input("You appeared to have missinput mp3 or wav please try again: ")
- Choice = ""
- def Choice_choosing():
- global Choice
- Choice = input("Please input an option for\n 1) Changing an individual video on your drive to audio\n 2) Changing a youtube playlist in to a folder full of songs\n 3) A single youtube video\n Input here please: ")
- while Choice != "1" and Choice != "2" and Choice != "3":
- Choice = input("You appeared to have missinput 1,2 or 3 please try : ")
- Choice_choosing()
- def Youtube_playlist_downloader():
- import pytube
- playlist = pytube.Playlist(input("input playlist url here (note if it is a irl with &index=number at the end that's a song url not a playlist url):"))#note playlist is a list of urls
- num = 0
- for v in playlist.videos:
- print(v.watch_url)
- Video = pytube.YouTube(v.watch_url)
- Video_v = Video.streams.get_lowest_resolution()
- Name = Video_v.default_filename
- try:
- Video_v.download("./videos")
- except:
- print("Failed to download" + Name[:-3])
- num += 1
- try:
- audio = mp.VideoFileClip(r"./videos/" + Name)
- audio.audio.write_audiofile(r"./audio/" + Name[:-3] + Audio_type)
- except:
- print("Failed to extract audio from" + Name[:-3])
- Choice_choosing()
- def Youtube_single_video_downloader():
- import pytube
- Video = pytube.YouTube(input("Please input a youtube url: "))
- Video_v = Video.streams.get_highest_resolution()
- Name = Video_v.default_filename
- try:
- Video_v.download("./videos")
- except:
- print("Failed to download" + Name[:-3])
- try:
- Audio = mp.VideoFileClip(r"./videos/" + Name)
- Audio.audio.write_audiofile(r"./audio/" + Name[:-3] + Audio_type)
- except:
- print("Failed to extract audio from" + Name[:-3])
- Choice_choosing()
- def Single_video_converter():
- try:
- File_location = input("Please input the file location and name i.e C:/Users/User/Videos/filename: ")
- Audio = mp.VideoFileClip(r"%s" % File_location)
- Audio.audio.write_audiofile(r"./audio/" + "Extracted audio." + Audio_type)
- except:
- print("Failed to extract audio from " + File_location)
- Choice_choosing()
- def Choice_selected():
- global Choice
- if Choice == "1":
- Single_video_converter()
- elif Choice == "2":
- Youtube_playlist_downloader()
- elif Choice == "3":
- Youtube_single_video_downloader()
- Choice_selected()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement