Skip to content

Instantly share code, notes, and snippets.

@isratmir
Last active March 29, 2016 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isratmir/5ce53695cfd8b3ae1516 to your computer and use it in GitHub Desktop.
Save isratmir/5ce53695cfd8b3ae1516 to your computer and use it in GitHub Desktop.
Parse namba playlist
require 'json'
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'net/http'
file = File.read('music.json')
data_hash = JSON.parse(file)
url = "http://download.files.namba.kg/files/"
length = data_hash.length
for i in 0..length
id = data_hash["#{i}"]
page = Nokogiri::HTML(open(url + id))
file_name =page.css('title').text.strip
file_name = file_name.gsub("'", '')
file_name = file_name.gsub("Бесплатно скачать файл ", '')
file_url = page.css('div.startdownload a')[1]["href"]
puts "Downloading " + file_name
File.open("music/" + file_name, "a+") do |file|
file.write open(file_url).read
end
puts file_name + " downloaded."
puts "-----------------------------"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment