-
-
Save DanyWallace/14e8673171aff779fa2f to your computer and use it in GitHub Desktop.
Simple script to downoad MP3 files from SoundCloud via WGet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment