Skip to content

Instantly share code, notes, and snippets.

@arashm
Created April 8, 2014 18:53
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save arashm/10170783 to your computer and use it in GitHub Desktop.
Save arashm/10170783 to your computer and use it in GitHub Desktop.
Simple script to downoad MP3 files from SoundCloud via WGet
#!/usr/bin/env ruby
require 'uri'
require 'httparty'
# Download mp3 files from SoundCloud
# Usage:
# ./soundcloud.rb https://soundcloud.com/tara-tiba/paeez_tara-tiba
class SoundCloud
include HTTParty
base_uri 'https://soundcloud.com'
def initialize(args = {})
@uri = URI(args.fetch(:url))
@link = ''
end
def get_name
@uri.path.split('/').last
end
def get_link_url
content = fetch_page
match = content.match /https?:\/\/media.soundcloud.com\/stream\/[^\"]*/
@link = match[0]
end
def download
get_link_url
system("wget #{@link} -O #{get_name}.mp3")
end
private
def fetch_page
self.class.get @uri.path
end
end
sc = SoundCloud.new(url: ARGV[0])
sc.download
@Nikolop
Copy link

Nikolop commented Oct 19, 2015

54:in require': cannot load such file -- httparty (LoadError) from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from ./soundcloud.rb:3:in `

'

@DanyWallace
Copy link

Nikolip; you need to install that gem.

@prasadeng
Copy link

./downmp3
./downmp3:23: unknown regexp options - artt
./downmp3:23: syntax error, unexpected $undefined, expecting keyword_end
...arshani-peiris-mp3-songs-3.php/stream/[^\"]*/
... ^
./downmp3:29: syntax error, unexpected tIDENTIFIER, expecting keyword_end
system("wget #{@link} -O #{get_name}.mp3")
^

@prasadeng
Copy link

hello i have no idea about scripting please help to resolved this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment