Advertisement
Guest User

iftux.wordpress.com

a guest
Dec 1st, 2013
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.78 KB | None | 0 0
  1. #!/bin/bash
  2. #*********************
  3. #
  4. #    Variables
  5. #
  6. #*********************
  7. artista="artista"
  8. cancion="cancion"
  9. archivo="archivo"
  10.  
  11. #*********************
  12. #
  13. #    Searching Downloading and converting
  14. #
  15. #*********************
  16.  
  17. #artista + cancion + archivo = archivo.l
  18. function getList() {
  19.     lynx -dump -listonly http://www.youtube.com/results?search_query="${1}"+"${2}">>${3}.rl
  20.     grep http://www.youtube.com/watch?v= ${3}.rl >> ${3}.rl1
  21.     rm ${3}.rl
  22.     cut -b 1-6 --complement ${3}.rl1 >> ${3}.rl2
  23.     rm ${3}.rl1
  24.     uniq ${3}.rl2 >> ${3}.rl3
  25.     rm ${3}.rl2
  26.     grep -v \& ${3}.rl3 >> ${3}.l
  27.     rm ${3}.rl3
  28. }
  29.  
  30. #link + archivo = archivo.ytb
  31. function download() {
  32.     youtube-dl ${1} -o ${2}.ytb
  33. }
  34.  
  35. #archivo = archivo.wav
  36. function extractAudio() {
  37.     ffmpeg -i ${1}.ytb -ac 2 ${1}.wav
  38. }
  39.  
  40. #archivo = archivo.mp3
  41. function toMp3() {
  42.     lame -b 320 ${1}.wav ${1}.mp3
  43. }
  44.  
  45. #*********************
  46. #
  47. #    MAIN
  48. #
  49. #*********************
  50. index=`expr index "${lista}" \|`
  51. read -p "Banda: " artista
  52. read -p "Tema: " cancion
  53. archivo=$(echo "${artista} ${cancion}" | sed -e 's/ /_/g')
  54. if [ -f "${archivo}".mp3 ]
  55. then
  56.     echo "Ya existe!"
  57.     break
  58. fi
  59. getList "$artista" "$cancion" "$archivo"
  60. for link in $(cat ${archivo}.l)
  61. do
  62.     download $link $archivo
  63.     if [ -f "${archivo}.ytb" ]
  64.     then
  65.         extractAudio $archivo
  66.         if [ -f "${archivo}.wav" ]
  67.         then
  68.             toMp3 $archivo
  69.             if [ -f "${archivo}.mp3" ]
  70.             then
  71.                 rm ${archivo}.l
  72.                 rm ${archivo}.ytb
  73.                 rm ${archivo}.wav
  74.                 break
  75.             else
  76.                 rm ${archivo}.ytb
  77.                 rm ${archivo}.wav
  78.             fi
  79.         else
  80.             rm ${archivo}.ytb
  81.         fi
  82.     fi
  83. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement