Skip to content

Instantly share code, notes, and snippets.

@victorcreed
Last active December 24, 2015 13:49
Show Gist options
  • Save victorcreed/6808132 to your computer and use it in GitHub Desktop.
Save victorcreed/6808132 to your computer and use it in GitHub Desktop.
download all the songs from the songspk.name its first create the album locally then fetch all the songs of that album from, currently a list is getting download
#!/usr/bin/env ruby
require "rubygems"
require "nokogiri"
require "open-uri"
require "faraday"
doc = Nokogiri::HTML(open("http://www.songspk.name/a_list.html"))
doc.css(".ctlg-holder").each do |ul_holder|
ul_holder.css("li a").each do |anchor_holder|
puts "Directory created in /home/kamal/Music/#{anchor_holder.text.gsub(/\\t\\n/i, "" )}", anchor_holder["href"]
Dir.mkdir("/home/kamal/Music/#{anchor_holder.text.gsub(/\\t\\n/i, "" )}") rescue puts "already existed"
begin
inner_doc = Nokogiri::HTML((open(anchor_holder["href"]) rescue open("http://www.songpk.name/#{anchor_holder["href"] }") ) )
inner_doc.css("a").each do |aa|
if aa["href"] =~ /songid/
response = Faraday.head aa["href"]
unless File.exists?("/home/kamal/Music/#{anchor_holder.text.gsub(/\\t\\n/i, "")}/#{response.headers["Location"].split("/").last}")
File.open("/home/kamal/Music/#{anchor_holder.text.gsub(/\\t\\n/i, "")}/#{response.headers["Location"].split("/").last}", "wb") do |file|
open(response.headers["Location"]) do |mp3|
file.write mp3.read
end
end
end
end
end
rescue Exception => e
puts "its error", e
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment