Advertisement
Guest User

thank you for looking

a guest
Jul 9th, 2022
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.03 KB | None | 0 0
  1. if __name__ == '__main__':
  2.     import moviepy.editor as mp
  3.  
  4.  
  5.  
  6.     Audio_type = input("Please inpute a audio type(mp3, wav): ")
  7.     while Audio_type != "mp3" and Audio_type != "wav":
  8.         Audio_type = input("You appeared to have missinput mp3 or wav please try again: ")
  9.     Choice = ""
  10.  
  11.  
  12.  
  13.     def Choice_choosing():
  14.         global Choice
  15.         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: ")
  16.         while Choice != "1" and Choice != "2"  and Choice != "3":
  17.             Choice = input("You appeared to have missinput 1,2 or 3 please try : ")
  18.  
  19.  
  20.  
  21.     Choice_choosing()
  22.  
  23.  
  24.  
  25.     def Youtube_playlist_downloader():
  26.         import pytube
  27.         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
  28.         num = 0
  29.         for v in playlist.videos:
  30.             print(v.watch_url)
  31.             Video = pytube.YouTube(v.watch_url)
  32.             Video_v = Video.streams.get_lowest_resolution()
  33.             Name = Video_v.default_filename
  34.             try:
  35.                 Video_v.download("./videos")
  36.             except:
  37.                 print("Failed to download" + Name[:-3])
  38.             num += 1
  39.             try:
  40.                 audio = mp.VideoFileClip(r"./videos/" + Name)
  41.                 audio.audio.write_audiofile(r"./audio/" + Name[:-3] + Audio_type)
  42.             except:
  43.                 print("Failed to extract audio from" + Name[:-3])
  44.         Choice_choosing()
  45.  
  46.  
  47.  
  48.     def Youtube_single_video_downloader():
  49.         import pytube
  50.         Video = pytube.YouTube(input("Please input a youtube url: "))
  51.         Video_v = Video.streams.get_highest_resolution()
  52.         Name = Video_v.default_filename
  53.         try:
  54.             Video_v.download("./videos")
  55.         except:
  56.             print("Failed to download" + Name[:-3])
  57.         try:
  58.             Audio = mp.VideoFileClip(r"./videos/" + Name)
  59.             Audio.audio.write_audiofile(r"./audio/" + Name[:-3] + Audio_type)
  60.         except:
  61.             print("Failed to extract audio from" + Name[:-3])
  62.         Choice_choosing()
  63.  
  64.  
  65.                
  66.     def Single_video_converter():
  67.         try:
  68.             File_location = input("Please input the file location and name i.e C:/Users/User/Videos/filename: ")
  69.             Audio = mp.VideoFileClip(r"%s" % File_location)
  70.             Audio.audio.write_audiofile(r"./audio/" + "Extracted audio." + Audio_type)
  71.         except:
  72.             print("Failed to extract audio from " + File_location)
  73.         Choice_choosing()
  74.  
  75.     def Choice_selected():
  76.         global Choice
  77.         if Choice == "1":
  78.             Single_video_converter()
  79.            
  80.         elif Choice == "2":
  81.             Youtube_playlist_downloader()
  82.  
  83.         elif Choice == "3":
  84.             Youtube_single_video_downloader()
  85.  
  86.  
  87.            
  88.     Choice_selected()
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement