pm74

Bash Soundcloud simple downloader v 1.1

Jan 22nd, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.19 KB | None | 0 0
  1. # SOUNDCLOUD download script by pm74 - probably the shortest you can find in the net!
  2.  
  3. # Will not do anything fancy, but just download CURRENT song.
  4. # DON'T mess around in the browser cache, but take URL from the address bar.
  5. # Comments to andi3 (AT) gmx (DOT) net
  6.  
  7. #!/bin/bash
  8.  
  9. # make this script idiot-proof
  10. # (since some people always feel like putting us to the test if we can code)
  11.  
  12. if [[ "$1" == "" ]]; then
  13.  echo "Usage: $0 <URI>"
  14.  exit 1
  15. fi
  16.  
  17. echo "Retrieving file, hang on ... "
  18.  
  19. dest=$(wget "$1" -O- -q | grep -o 'streamUrl.*' | cut -f2-3 -d: | cut -f2 -d\" | head -1)
  20.  
  21. wget -q -nd --no-use-server-timestamps $dest
  22. # URL -> filename
  23. destbase=$(basename $dest)
  24.  
  25. if [ -s $destbase ]; then
  26.   echo -e "\nDownloaded $dest to current directory.\n"
  27.   # is this MP3 ?
  28.   if [ "$(file -b --mime-type $destbase)" == "audio/mpeg" ]; then
  29.     # rename mp3 to something (a little) more reasonable
  30.     destfinal=$(cut -f1 -d? <<< $destbase)
  31.     mv $destbase $destfinal.mp3
  32.     echo "File type was identified as 'audio/mpeg' and file renamed to $destfinal.mp3."
  33.   fi
  34.  
  35. else
  36.   echo -e "\nERROR: Something went wrong! Please make sure you've typed a valid URI.\n"
  37.   rm -f $destbase
  38. fi
Add Comment
Please, Sign In to add comment