soundcloud.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. #Quickly add sounds from soundcloud to a directory for Internet synthesizing DJ mangle mashing
  3. #start file from command line with: ./sc.sh
  4. #wget is required, though a rewrite to curl works fine
  5. which wget &>/dev/null
  6. if ! [ $? -eq 0 ]; then echo "wget is currently required (curl could replace it) Go install it! " && exit;
  7. fi
  8. cd ~/Podcasts
  9. for (( ; ; ))
  10. do
  11. echo "what artist?"
  12. read input
  13. if [[ -z "$input" ]]; then
  14. echo "put an artist name here to search"
  15. break
  16. fi
  17. input="http://soundcloud.com/$input";
  18. link=`wget "$input" -q --user-agent 'Mozilla/5.0' -O -`;
  19. artist=`echo "$input" | sed s/[https]*:[\/]*soundcloud\.com[\/]// | grep "[^\/]"`;
  20. pages=`echo "$link" | tr '"' "\n" | grep "tracks?" | grep "page=" | awk -F= '{print $NF}' | sort -nu | tail -n 1`
  21. this=`wget -q --user-agent='Mozilla/5.0' $input -O -`;
  22. songs=`echo "$this" | grep 'streamUrl' | tr '"' "\n" | sed 's/\\u0026amp;/\&/' | grep 'http://media.soundcloud.com/stream/' | sed 's/\\\\//'`;
  23. titles=`echo "$this" | grep 'title":"' | tr ',' "\n" | grep 'title' | cut -d '"' -f 4`
  24. songcount=`echo "$songs" | wc -l`
  25. if [ -z "$songs" ]; then
  26. echo "[!] No songs found at $input." && exit
  27. fi
  28. for (( songid=1; songid <= $songcount; songid++ ))
  29. do
  30. title=`echo "$titles" | sed -n "$songid"p`
  31. echo "$songid $title"
  32. done
  33. for (( ; ; ))
  34. do
  35. echo "Select a song, (d) download all,(q) quit search";
  36. read -s songinput
  37. songregex=`echo "$songinput" | grep '[0-9]'`;
  38. if [[ "$songinput" = "d" ]]; then
  39. file=`ls | grep "$artist"`;
  40. if [ -z "$file" ]; then
  41. mkdir $artist;
  42. fi
  43. cd $artist;
  44. echo "download all";
  45. for (( songid=1; songid <= $songcount; songid++ ))
  46. do
  47. title=`echo "$titles" | sed -n "$songid"p`
  48. echo "[-] Downloading $title..."
  49. url=`echo "$songs" | sed -n "$songid"p`;
  50. wget -c -q -nc --user-agent='Mozilla/5.0' -O "$title.mp3" $url;
  51. done
  52. elif [[ "$songinput" = "q" ]]
  53. then break
  54. elif [[ "$songregex" ]]; then
  55. mkdir -p $artist
  56. cd $artist
  57. title=`echo "$titles" | sed -n "$songregex"p`
  58. echo "[-] Downloading $title..."
  59. url=`echo "$songs" | sed -n "$songregex"p`;
  60. wget -c -q -nc --user-agent='Mozilla/5.0' -O "$title.mp3" $url;
  61. fi
  62. done
  63. done