Skip to content

Instantly share code, notes, and snippets.

@unp
Created November 14, 2023 00:30
Show Gist options
  • Save unp/f9297a79f279ba786796ff5ecaafeaa7 to your computer and use it in GitHub Desktop.
Save unp/f9297a79f279ba786796ff5ecaafeaa7 to your computer and use it in GitHub Desktop.
BPMSupreme Downloader
class BPMDownloader
require 'httparty'
require 'byebug'
require 'awesome_print'
require 'io/console'
require 'uri'
include HTTParty
follow_redirects false
def initialize(username, password)
self.class.base_uri "https://www.bpmsupreme.com/"
response = self.class.get("/")
# puts parse_cookie(login(username, password).header).inspect
self.class.default_cookies.add_cookies parse_cookie(response.header)
login(username, password)
end
def download(id)
response = self.class.post("/store/getMediaDetails", body: { iMediaID: id }.to_json)
parsed_response = JSON.parse(response.body)
file_type = parsed_response['eAlbumType']
file_name = parsed_response['vMediaFile']
if file_type == 'Audio'
download = self.class.get("/store/output_file/#{id}")
self.class.default_cookies.add_cookies parse_cookie(download.header)
File.open( "#{file_name}", "w") do |f|
location_url = download.headers["location"].match(/([^\?]+)(\?.*)?/)[1]
f << self.class.get(URI::encode(location_url))
end
puts "Downloaded: #{id}"
puts "Filename: #{file_name}"
elsif file_type == 'Video'
puts "Skipped (Video): #{id}"
else
puts "Not Found: #{id}"
end
end
private
def login(username, password)
self.class.post(
"/login",
body: { email: username, password: password }
)
end
def parse_cookie(res)
cookie_hash = CookieHash.new
res.get_fields('set-cookie').each { |c| cookie_hash.add_cookies(c) }
cookie_hash
end
end
print 'Username: '
username = STDIN.gets.chomp
print 'Password: '
password = STDIN.noecho(&:gets).chomp
puts ''
print 'First: '
first = STDIN.gets.chomp
print 'Last: '
last = STDIN.gets.chomp
puts "Logging in..."
session = BPMDownloader.new(username, password)
all=*(first.to_i..last.to_i).each{ |i| session.download(i) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment