cherrypicker 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -31,9 +31,12 @@ Examples
31
31
  "http://rapidshare.com/files/329036215/myfile.rar",
32
32
  "http://rapidshare.com/files/329036764/deadfile.rar"]).status
33
33
 
34
- test3 = Rapidshare.new("http://rapidshare.com/files/329036215/myfile.rar", "username", "password", "size", "location")
34
+ test3 = Rapidshare.new("http://rapidshare.com/files/329036215/myfile.rar", "username", "password", "size", "/location/tosave/file/")
35
35
  test3.download
36
36
 
37
+ Download.new("http://download.thinkbroadband.com/10MB.zip", "/location/tosave/file/")
38
+ Download.new("http://download.thinkbroadband.com/10MB.zip", "/location/tosave/file/", "10485760")
39
+
37
40
  Contributing
38
41
  ------------
39
42
 
@@ -1,18 +1,18 @@
1
- # Class that can download files from cyberlockers
1
+ # Class that can download files from cyberlockers or generic URLs
2
2
  #
3
- # Download.new(hostname, url, size, password)
3
+ # Download.new("http://download.thinkbroadband.com/10MB.zip", "/location/tosave/file/")
4
+ # Download.new("http://download.thinkbroadband.com/10MB.zip", "/location/tosave/file/", "10485760")
5
+
4
6
  require 'net/http'
5
7
  require 'net/https'
6
8
  require 'progressbar'
7
9
  require 'open-uri'
8
10
 
9
11
  class Download
10
- attr_accessor :hostname, :url, :filename, :size, :progress, :location
12
+ attr_accessor :link, :size, :location, :progress
11
13
 
12
- def initialize(hostname, url, filename, size = nil, location = nil)
13
- @hostname = hostname
14
- @url = url
15
- @filename = filename
14
+ def initialize(link, location = nil, size = nil)
15
+ @link = link
16
16
  @size = size
17
17
  @location = location
18
18
  @progress = 0
@@ -21,17 +21,18 @@ class Download
21
21
  end
22
22
 
23
23
  def download_file
24
- uri = URI.parse("#{self.hostname}" + "#{self.url}")
24
+ uri = URI.parse(@link.to_s)
25
25
  http = Net::HTTP.new(uri.host, uri.port)
26
26
  http.use_ssl = true if uri.scheme == "https"
27
27
  request = Net::HTTP::Get.new(uri.request_uri)
28
28
  request.initialize_http_header({"User-Agent" => random_agent})
29
+ @size = http.request_head(URI.escape(uri.path))['content-length'].to_i if @size.nil?
29
30
  http.request(request) do |response|
30
- bar = ProgressBar.new("#{self.filename}", self.size.to_i)
31
- File.open("#{self.location}" + "#{self.filename}", "wb") do |file|
31
+ bar = ProgressBar.new(File.basename(uri.path), @size.to_i)
32
+ File.open(@location + File.basename(uri.path), "wb") do |file|
32
33
  response.read_body do |segment|
33
- self.progress += segment.length
34
- bar.set(self.progress)
34
+ @progress += segment.length
35
+ bar.set(@progress)
35
36
  file.write(segment)
36
37
  end
37
38
  end
@@ -1,3 +1,5 @@
1
+ require 'open-uri'
2
+
1
3
  # Class that can sort Hotfile link into sections as specified by Hotfile API
2
4
  #
3
5
  # hotfile = Hotfile.new("http://hotfile.com/dl/110589431/6ad2666/ROT007-WEB-2011.rar.html", "username", "password")
@@ -8,6 +10,7 @@ class Hotfile
8
10
  attr_accessor :link, :hostname, :filename, :username, :password, :size, :location
9
11
 
10
12
  def initialize(link, username, password, size = nil, location = "")
13
+ uri = URI.parse(link)
11
14
  if link =~ /hotfile.com\/dl\/\d*\/[0-9a-f]*\/.*.*\.html/
12
15
  @link = link[/(.*)\.html/, 1]
13
16
  else
@@ -16,24 +19,24 @@ class Hotfile
16
19
  @username = username
17
20
  @password = password
18
21
  @hostname = hostname
19
- @filename = filename
22
+ @filename = File.basename(uri.path)
20
23
  @size = size
21
24
  @location = location
22
25
  end
23
26
 
24
27
  def download
25
- Download.new(self.hostname, remote_url, self.filename, self.size, self.location)
28
+ Download.new(@hostname + remote_url, @location, @size)
26
29
  end
27
30
 
28
31
  def filename
29
- self.link[/dl\/\d*\/[0-9a-f]*\/(.*)/, 1]
32
+ @link[/dl\/\d*\/[0-9a-f]*\/(.*)/, 1]
30
33
  end
31
34
 
32
35
  def create_url
33
36
  hash_to_url({
34
- :link => self.link,
35
- :username => self.username.to_s,
36
- :password => self.password.to_s
37
+ :link => @link,
38
+ :username => @username.to_s,
39
+ :password => @password.to_s
37
40
  })
38
41
  end
39
42
 
@@ -1,3 +1,5 @@
1
+ require 'open-uri'
2
+
1
3
  # Class that can sort Rapidshare link into sections as specified by RapidShare API
2
4
  #
3
5
  # rapid = Rapidshare.new("http://rapidshare.com/files/329036215/The.Matrix.bandaa25.part06.rar", "username", "password")
@@ -10,9 +12,10 @@ class Rapidshare
10
12
  attr_accessor :link, :fileid, :filename, :hostname, :username, :password, :size, :location
11
13
 
12
14
  def initialize(link, username, password, size = nil, location = "")
15
+ uri = URI.parse(link)
13
16
  @link = link
14
17
  @fileid = fileid
15
- @filename = filename
18
+ @filename = File.basename(uri.path)
16
19
  @hostname = hostname
17
20
  @username = username
18
21
  @password = password
@@ -21,27 +24,23 @@ class Rapidshare
21
24
  end
22
25
 
23
26
  def download
24
- Download.new(self.hostname, remote_url, self.filename, self.size, self.location)
27
+ Download.new(@hostname + remote_url, @location, @size,)
25
28
  end
26
29
 
27
30
  def fileid
28
- self.link[/files\/(\d*)\//, 1]
29
- end
30
-
31
- def filename
32
- self.link[/files\/\d*\/(.*)/, 1]
31
+ @link[/files\/(\d*)\//, 1]
33
32
  end
34
-
33
+
35
34
  def remote_url
36
35
  "/cgi-bin/rsapi.cgi?sub=download&" + create_url
37
36
  end
38
37
 
39
38
  def create_url
40
39
  hash_to_url({
41
- :fileid => self.fileid,
42
- :filename => self.filename,
43
- :login => self.username.to_s,
44
- :password => self.password.to_s
40
+ :fileid => @fileid,
41
+ :filename => @filename,
42
+ :login => @username.to_s,
43
+ :password => @password.to_s
45
44
  })
46
45
  end
47
46
 
@@ -1,3 +1,3 @@
1
1
  module Cherrypicker
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.4"
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.2
5
+ version: 0.2.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Karl Entwistle