cherrypicker 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == Description
4
4
 
5
- Cherrypicker is Ruby Gem it lets you download from; Rapidshare and Hotfile
5
+ Cherrypicker is a Ruby Gem that lets you download from; Rapidshare and Hotfile
6
6
 
7
7
  == Installation
8
8
 
@@ -0,0 +1,26 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require 'open-uri'
4
+
5
+ def remote_query(url)
6
+ begin
7
+ uri = URI.parse(url)
8
+ http = Net::HTTP.new(uri.host, uri.port)
9
+ http.open_timeout = 3 # in seconds
10
+ http.read_timeout = 3 # in seconds
11
+ request = Net::HTTP::Get.new(uri.request_uri)
12
+ request.initialize_http_header({"User-Agent" => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.1 (KHTML, like Gecko) Chrome/4.0.219.6 Safari/532.1"})
13
+ response = http.request(request)
14
+ return response
15
+ rescue SocketError
16
+ $stderr.print "IO failed: " + $!
17
+ raise
18
+ end
19
+ end
20
+
21
+ def hash_to_url(hash)
22
+ hash.keys.inject('') do |query_string, key|
23
+ query_string << '&' unless key == hash.keys.first
24
+ query_string << "#{URI.encode(key.to_s)}=#{URI.encode(hash[key])}"
25
+ end
26
+ end
@@ -6,10 +6,14 @@
6
6
  require 'open-uri'
7
7
 
8
8
  class Hotfile
9
- attr_accessor :link, :hostname, :filename, :username, :password, :remote_url
9
+ attr_accessor :link, :hostname, :filename, :username, :password
10
10
 
11
11
  def initialize(link, username, password)
12
- @link = link
12
+ if link =~ /hotfile.com\/dl\/\d*\/[0-9a-f]*\/.*.*\.html/
13
+ @link = link[/(.*)\.html/, 1]
14
+ else
15
+ @link = link
16
+ end
13
17
  @username = username
14
18
  @password = password
15
19
  @hostname = hostname
@@ -25,38 +29,23 @@ class Hotfile
25
29
  end
26
30
 
27
31
  def create_url
28
- Hash.new({
32
+ hash_to_url({
29
33
  link: self.link,
30
34
  username: self.username.to_s,
31
35
  password: self.password.to_s
32
- }).url
36
+ })
37
+ end
38
+
39
+ def request
40
+ query = remote_query("http://api.hotfile.com/?action=getdirectdownloadlink&" + create_url)
41
+ query.response.body
33
42
  end
34
43
 
35
44
  def hostname
36
- query = "http://api.hotfile.com/?action=getdirectdownloadlink&" + create_url
37
- begin
38
- open(query) do |f|
39
- f.each do |line|
40
- return "#{line[/http:\/\/(.*).hotfile.com/, 1]}" + ".hotfile.com"
41
- end
42
- end
43
- rescue SocketError
44
- $stderr.print "IO failed: " + $!
45
- raise
46
- end
45
+ "#{request[/http:\/\/(.*).hotfile.com/, 1]}" + ".hotfile.com"
47
46
  end
48
47
 
49
48
  def remote_url
50
- query = "http://api.hotfile.com/?action=getdirectdownloadlink&" + create_url
51
- begin
52
- open(query) do |f|
53
- f.each do |line|
54
- return "#{line[/http:\/\/.*.hotfile.com(.*)/, 1]}"
55
- end
56
- end
57
- rescue SocketError
58
- $stderr.print "IO failed: " + $!
59
- raise
60
- end
49
+ "#{request[/http:\/\/.*.hotfile.com(.*)/, 1]}"
61
50
  end
62
51
  end
@@ -5,7 +5,8 @@
5
5
  # puts rapid.fileid
6
6
  # puts rapid.filename
7
7
  # puts rapid.host
8
- require 'open-uri'
8
+ require "net/http"
9
+ require "uri"
9
10
 
10
11
  class Rapidshare
11
12
  attr_accessor :link, :fileid, :filename, :hostname, :username, :password
@@ -36,25 +37,16 @@ class Rapidshare
36
37
  end
37
38
 
38
39
  def create_url
39
- Hash.new({
40
+ hash_to_url({
40
41
  fileid: self.fileid,
41
42
  filename: self.filename,
42
43
  login: self.username.to_s,
43
44
  password: self.password.to_s
44
- }).url
45
+ })
45
46
  end
46
47
 
47
- def hostname
48
- query = "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&" + create_url
49
- begin
50
- open(query) do |f|
51
- f.each do |line|
52
- return "#{line[/DL:(.*).rapidshare.com/, 1]}" + ".rapidshare.com"
53
- end
54
- end
55
- rescue SocketError
56
- $stderr.print "IO failed: " + $!
57
- raise
58
- end
59
- end
48
+ def hostname
49
+ query = remote_query("http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&" + create_url)
50
+ query.response.body[/DL:(.*).rapidshare.com/, 1] + ".rapidshare.com"
51
+ end
60
52
  end
@@ -1,3 +1,3 @@
1
1
  module Cherrypicker
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/cherrypicker.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  require 'cherrypicker/rapidshare'
2
2
  require "cherrypicker/hotfile"
3
3
  require 'cherrypicker/download'
4
- require "cherrypicker/hash"
4
+ require "cherrypicker/functions"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cherrypicker
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Karl Entwistle
@@ -31,7 +31,7 @@ files:
31
31
  - cherrypicker.gemspec
32
32
  - lib/cherrypicker.rb
33
33
  - lib/cherrypicker/download.rb
34
- - lib/cherrypicker/hash.rb
34
+ - lib/cherrypicker/functions.rb
35
35
  - lib/cherrypicker/hotfile.rb
36
36
  - lib/cherrypicker/rapidshare.rb
37
37
  - lib/cherrypicker/version.rb
@@ -1,21 +0,0 @@
1
- # Class that can create URL from hash
2
- #
3
- # print Hash.new(Hash["a", "b"]).url
4
- require 'open-uri'
5
-
6
- class Hash
7
- attr_accessor :hash, :url
8
-
9
- def initialize(hash)
10
- @hash = hash
11
- @url = hash_to_url
12
- end
13
-
14
- def hash_to_url
15
- hash = self.hash
16
- hash.keys.inject('') do |query_string, key|
17
- query_string << '&' unless key == hash.keys.first
18
- query_string << "#{URI.encode(key.to_s)}=#{URI.encode(hash[key])}"
19
- end
20
- end
21
- end