cherrypicker 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,10 @@
1
1
  # Class that can download files from cyberlockers
2
2
  #
3
- # Download.new(hostname, url, username, password)
3
+ # Download.new(hostname, url, size, password)
4
4
  require 'net/http'
5
+ require 'net/https'
5
6
  require 'progressbar'
7
+ require 'open-uri'
6
8
 
7
9
  class Download
8
10
  attr_accessor :hostname, :url, :filename, :size, :progress, :location
@@ -14,15 +16,17 @@ class Download
14
16
  @size = size
15
17
  @location = location
16
18
  @progress = 0
17
-
19
+
18
20
  download_file
19
21
  end
20
-
21
- private
22
22
 
23
23
  def download_file
24
- http = Net::HTTP.new("#{self.hostname}")
25
- http.request_get("#{self.url}") do |response|
24
+ uri = URI.parse("#{self.hostname}" + "#{self.url}")
25
+ http = Net::HTTP.new(uri.host, uri.port)
26
+ http.use_ssl = true if uri.scheme == "https"
27
+ request = Net::HTTP::Get.new(uri.request_uri)
28
+ request.initialize_http_header({"User-Agent" => random_agent})
29
+ http.request(request) do |response|
26
30
  bar = ProgressBar.new("#{self.filename}", self.size.to_i)
27
31
  File.open("#{self.location}" + "#{self.filename}", "wb") do |file|
28
32
  response.read_body do |segment|
@@ -1,12 +1,14 @@
1
1
  #The points are decremented by 1000 per minute. If you are able to parse the http header,
2
2
  #you can parse "X-APICPU: x/y", where x stands for your current points
3
3
  require 'net/http'
4
+ require 'net/https'
4
5
  require 'open-uri'
5
6
 
6
7
  def remote_query(url)
7
8
  begin
8
9
  uri = URI.parse(url)
9
10
  http = Net::HTTP.new(uri.host, uri.port)
11
+ http.use_ssl = true if uri.scheme == "https"
10
12
  http.open_timeout = 3 # seconds
11
13
  http.read_timeout = 3 # seconds
12
14
  request = Net::HTTP::Get.new(uri.request_uri)
@@ -31,24 +33,7 @@ def hash_to_url(hash)
31
33
  end
32
34
  end
33
35
 
34
- private
35
-
36
- # Have a random Browser User Agent just incase
37
36
  def random_agent
38
- @useragent = ["Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090913 Firefox/3.5.3",
39
- "Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)",
40
- "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)",
41
- "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.1) Gecko/20090718 Firefox/3.5.1",
42
- "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",
43
- "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.2)",
44
- "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30729)",
45
- "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Win64; x64; Trident/4.0)",
46
- "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; .NET CLR 2.0.50727; InfoPath.2)Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)",
47
- "Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)",
48
- "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.151 Safari/534.16",
49
- "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27",
50
- "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.151 Safari/534.16",
51
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
52
- "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.14) Gecko/20110218 Firefox/3.6.14"]
53
- @useragent[rand(14)]
37
+ @useragent = ["Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090913 Firefox/3.5.3"]
38
+ return @useragent[0]
54
39
  end
@@ -12,7 +12,7 @@ class LinkChecker
12
12
 
13
13
  def initialize(links)
14
14
  @links = links
15
- if links[0] =~ /^http:\/\/rapidshare.com/
15
+ if links[0] =~ /^http:\/\/(www.|)rapidshare.com/
16
16
  @status = rapidshare
17
17
  else
18
18
  @status = hotfile
@@ -13,7 +13,7 @@ class Rapidshare
13
13
  @link = link
14
14
  @fileid = fileid
15
15
  @filename = filename
16
- # @hostname = hostname
16
+ @hostname = hostname
17
17
  @username = username
18
18
  @password = password
19
19
  @size = size
@@ -47,6 +47,6 @@ class Rapidshare
47
47
 
48
48
  def hostname
49
49
  query = remote_query("http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&" + create_url)
50
- query.response.response["Location"][/https:\/\/(.*).rapidshare.com/, 1] + ".rapidshare.com"
50
+ query.response.response["Location"][/(.*).rapidshare.com/, 1] + ".rapidshare.com"
51
51
  end
52
52
  end
@@ -1,3 +1,3 @@
1
1
  module Cherrypicker
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cherrypicker
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.2.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Karl Entwistle