nanorocks

download_mp3_from_file_youtube

May 17th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.69 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. # CREATOR
  5. # This code in writen by nanorocks
  6. #
  7.  
  8. #
  9. # POINT
  10. # Helping script to download mp3 music from file filled with links from youtube
  11. #
  12.  
  13. #
  14. # USAGE
  15. # For OS's who compile SHELL SCRIPTS (GNU/LINUX)
  16. #
  17.  
  18. #GLOBAL VARIABLES
  19. data=$1
  20. flag=0
  21.  
  22. # just logo on start up
  23. function logo()
  24. {
  25.     echo "---------------------------------"
  26.     echo "| YOUTUBE SONGS LIST DOWNLOADER |"
  27.     echo "---------------------------------"
  28. }
  29.  
  30. # requirements on start up
  31. function checkRequirements()
  32. {
  33.   echo -e "REQUIREMENTS: (youtube-dl,ffmpeg)"
  34.   if ! type "youtube-dl" > /dev/null; then
  35.     echo "You must install youtube-dl on your system."
  36.     exit
  37.   elif ! type "ffmpeg" > /dev/null; then
  38.     echo "You must install ffmpeg on your system."
  39.     exit
  40.   else
  41.     echo "Your requirements are installed."
  42.   fi
  43.  
  44. }
  45.  
  46.  
  47. # validation input goes here
  48. function validationInput()
  49. {
  50.     if ! [ -f $data ]
  51.     then
  52.         echo "File $data not exist."
  53.         exit
  54.     elif [[ -z "$data" ]]
  55.     then
  56.         echo -e "Set file as parameter after this script.\n E.G: bash <scriptname> <file>"
  57.         exit
  58.     fi
  59.    
  60.     if ! [ -d songs ]
  61.     then
  62.         mkdir songs
  63.     fi
  64.    
  65. }
  66.  
  67. # main fuction for music
  68. function loopingMusic()
  69. {
  70.    
  71.     for i in `cat $data`
  72.     do
  73.         echo "Downloading new song from youtube!!!"
  74.         echo `youtube-dl --extract-audio --audio-format mp3 $i`
  75.         flag=$((flag+1))
  76.     done
  77.    
  78.     ls | grep '.mp3' | while read j
  79.     do
  80.         # echo "$j"
  81.         mv "$j" songs
  82.     done
  83.        
  84.     echo "You downloaded $flag songs from youtube."
  85.    
  86. }
  87.  
  88. logo .
  89. checkRequirements .
  90. validationInput .
  91. loopingMusic .
Add Comment
Please, Sign In to add comment