Skip to content

Instantly share code, notes, and snippets.

@ssut
Last active December 17, 2015 13:29
Show Gist options
  • Save ssut/5617892 to your computer and use it in GitHub Desktop.
Save ssut/5617892 to your computer and use it in GitHub Desktop.
Get SkyDrive direct download link with Ruby.
#encoding: UTF-8
class SkydriveGetter
attr_reader :fullLocation, :file
def initialize(id, file)
id = URI.decode(id) if id.include?('%')
@loc = id
@file = file
@cid = @loc.gsub(/!.+/i, '')
@fullLocation = "https://skydrive.live.com/?cid=#{@cid}&id=#{@loc}"
end
def get_html_content(url)
str = ''
begin
open(url) { |f|
f.each_line { |line|
str += line
}
}
rescue OpenURI::HTTPError => ex
return "err|#{ex}"
end
return str
end
def self.extract_link(id, file)
@instance = new id, file
content = @instance.get_html_content @instance.fullLocation
enc = @instance.file.gsub(/ /i, '%20').gsub(/\+/i, '%2B').gsub(/\(/i, '\(').gsub(/\)/i, '\)')
if content =~ /(?<="download":")https:[^:]+#{enc}/i
out = content.scan(/(?<="download":")https:[^:]+#{enc}/i).join().gsub(/\\\\/i, '').gsub(/\\\//i, '/')
return out
else
return nil
end
@instance = nil
end
private_class_method :new
end
#encoding: UTF-8
require './skydrivedl.rb'
# Get phpMyAdmin 3.5.8 All-language download link from SkyDrive.
puts SkydriveGetter.extract_link('4AC97C30D70CBFEF!250', 'phpMyAdmin-3.5.8-all-languages.tar.gz')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment