cherrypicker 0.3.10 → 0.3.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cherrypicker/helpers.rb +58 -16
- data/lib/cherrypicker/plugins/hotfile.rb +1 -1
- data/lib/cherrypicker/plugins/megavideo.rb +1 -1
- data/lib/cherrypicker/plugins/rapidshare.rb +1 -1
- data/lib/cherrypicker/plugins/rghost.rb +1 -1
- data/lib/cherrypicker/plugins/vimeo.rb +2 -2
- data/lib/cherrypicker/plugins/youtube.rb +2 -1
- data/lib/cherrypicker/version.rb +1 -1
- data/lib/cherrypicker.rb +0 -1
- data/uml.png +0 -0
- metadata +2 -3
- data/lib/cherrypicker/download.rb +0 -61
data/lib/cherrypicker/helpers.rb
CHANGED
@@ -1,30 +1,72 @@
|
|
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
|
+
|
4
|
+
# it will try and auto detect the size and filename if not supplied
|
5
|
+
# Cherrypicker::download_file("http://download.thinkbroadband.com/10MB.zip", :location => '/location/tosave/file/', :size => 10485760)
|
6
|
+
|
7
|
+
require 'rubygems'
|
3
8
|
require 'net/http'
|
4
9
|
require 'net/https'
|
10
|
+
require 'progressbar'
|
5
11
|
require 'open-uri'
|
6
12
|
|
7
13
|
module Cherrypicker
|
8
14
|
def self.remote_query(url)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
if response["X-APICPU"]
|
19
|
-
|
20
|
-
|
15
|
+
uri = URI.parse(url)
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
http.use_ssl = true if uri.scheme == "https"
|
18
|
+
http.open_timeout = 3 # seconds
|
19
|
+
http.read_timeout = 3 # seconds
|
20
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
21
|
+
request.initialize_http_header({"User-Agent" => random_agent})
|
22
|
+
response = http.request(request)
|
23
|
+
if response["X-APICPU"]
|
24
|
+
if (response["X-APICPU"][/(\d*)\/\d*/, 1]).to_i > 9500
|
25
|
+
sleep 60 # seconds
|
26
|
+
end
|
27
|
+
end
|
28
|
+
return http.request(request)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.download_file(link, opts={})
|
32
|
+
o = {
|
33
|
+
:location => nil,
|
34
|
+
:size => nil,
|
35
|
+
:filename => nil
|
36
|
+
}.merge(opts)
|
37
|
+
|
38
|
+
@link = link
|
39
|
+
@size = o[:size]
|
40
|
+
@location = o[:location] ||= ""
|
41
|
+
@filename = o[:filename]
|
42
|
+
@progress = 0
|
43
|
+
@finished = false
|
44
|
+
|
45
|
+
uri = URI.parse(@link.to_s)
|
46
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
47
|
+
http.use_ssl = true if uri.scheme == "https"
|
48
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
49
|
+
request.initialize_http_header({"User-Agent" => Cherrypicker::random_agent})
|
50
|
+
unless (uri.host.include? 'youtube.com') && (uri.request_uri.include? 'videoplayback') #youtube throws EOFError
|
51
|
+
head = http.request_head(URI.escape(uri.path))
|
52
|
+
case head
|
53
|
+
when Net::HTTPForbidden
|
54
|
+
@size = nil #no content-length no progress bar
|
55
|
+
else
|
56
|
+
@size = head['content-length'] if @size.nil? && head['content-length'].to_i > 1024
|
57
|
+
end
|
58
|
+
end
|
59
|
+
http.request(request) do |response|
|
60
|
+
bar = ProgressBar.new((@filename ||= File.basename(uri.path)), @size.to_i) unless @size.nil?
|
61
|
+
File.open(@location + (@filename ||= File.basename(uri.path)), "wb") do |file|
|
62
|
+
response.read_body do |segment|
|
63
|
+
@progress += segment.length
|
64
|
+
bar.set(@progress) unless @size.nil?
|
65
|
+
file.write(segment)
|
21
66
|
end
|
22
67
|
end
|
23
|
-
return response
|
24
|
-
rescue SocketError
|
25
|
-
$stderr.print "IO failed: " + $!
|
26
|
-
raise
|
27
68
|
end
|
69
|
+
@finished = true
|
28
70
|
end
|
29
71
|
|
30
72
|
def self.hash_to_url(hash)
|
@@ -32,7 +32,7 @@ module Cherrypicker
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def download
|
35
|
-
|
35
|
+
Cherrypicker::download_file(download_url, :location => @location, :size => @size, :filename => @filename)
|
36
36
|
end
|
37
37
|
|
38
38
|
def create_url
|
@@ -29,7 +29,7 @@ module Cherrypicker
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def download
|
32
|
-
|
32
|
+
Cherrypicker::download_file(@hostname + remote_url, :location => @location, :size => @size, :filename => @filename)
|
33
33
|
end
|
34
34
|
|
35
35
|
def fileid
|
@@ -39,13 +39,13 @@ module Cherrypicker
|
|
39
39
|
download_url = ":#{vimeo_id}/#{request_signature}/#{request_signature_expires}/?q=hd"
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
@filename = title.delete("\"'").gsub(/[^0-9A-Za-z]/, '_') + ".mp4"
|
43
43
|
reply = Cherrypicker::remote_query("#{hostname}#{download_url}")
|
44
44
|
@download_url = reply.response['location']
|
45
45
|
end
|
46
46
|
|
47
47
|
def download
|
48
|
-
|
48
|
+
Cherrypicker::download_file(@download_url, :location => @location, :filename => @filename)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -60,6 +60,7 @@ module Cherrypicker
|
|
60
60
|
download_url = video_info_hash["fmt_url_map"][formats.first]
|
61
61
|
@filename = video_info_hash["title"].delete("\"'").gsub(/[^0-9A-Za-z]/, '_') + "." + format_ext[formats.first].first
|
62
62
|
|
63
|
+
#there might be a redirect let check
|
63
64
|
reply = Cherrypicker::remote_query("#{download_url}")
|
64
65
|
if reply.response['location']
|
65
66
|
@download_url = reply.response['location']
|
@@ -69,7 +70,7 @@ module Cherrypicker
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def download
|
72
|
-
|
73
|
+
Cherrypicker::download_file(@download_url, :location => @location, :filename => @filename)
|
73
74
|
end
|
74
75
|
end
|
75
76
|
end
|
data/lib/cherrypicker/version.rb
CHANGED
data/lib/cherrypicker.rb
CHANGED
data/uml.png
CHANGED
Binary file
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: cherrypicker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.11
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Karl Entwistle
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-02 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -42,7 +42,6 @@ files:
|
|
42
42
|
- cherrypicker.gemspec
|
43
43
|
- lib/cherrypicker.rb
|
44
44
|
- lib/cherrypicker/cherrypick.rb
|
45
|
-
- lib/cherrypicker/download.rb
|
46
45
|
- lib/cherrypicker/helpers.rb
|
47
46
|
- lib/cherrypicker/linkchecker.rb
|
48
47
|
- lib/cherrypicker/plugins/hotfile.rb
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# Class that can download files from cyberlockers or generic URLs
|
2
|
-
# it will try and auto detect the size and filename if not supplied
|
3
|
-
# Download.new("http://download.thinkbroadband.com/10MB.zip", :location => '/location/tosave/file/')
|
4
|
-
# Download.new("http://download.thinkbroadband.com/10MB.zip", :location => '/location/tosave/file/', :size => 10485760)
|
5
|
-
|
6
|
-
require 'rubygems'
|
7
|
-
require 'net/http'
|
8
|
-
require 'net/https'
|
9
|
-
require 'progressbar'
|
10
|
-
require 'open-uri'
|
11
|
-
|
12
|
-
module Cherrypicker
|
13
|
-
class Download
|
14
|
-
attr_accessor :link, :size, :location, :progress, :filename, :finished
|
15
|
-
|
16
|
-
def initialize(link, opts={})
|
17
|
-
o = {
|
18
|
-
:location => nil,
|
19
|
-
:size => nil,
|
20
|
-
:filename => nil
|
21
|
-
}.merge(opts)
|
22
|
-
|
23
|
-
@link = link
|
24
|
-
@size = o[:size]
|
25
|
-
@location = o[:location] ||= ""
|
26
|
-
@filename = o[:filename]
|
27
|
-
@progress = 0
|
28
|
-
@finished = false
|
29
|
-
|
30
|
-
download_file
|
31
|
-
end
|
32
|
-
|
33
|
-
def download_file
|
34
|
-
uri = URI.parse(@link.to_s)
|
35
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
36
|
-
http.use_ssl = true if uri.scheme == "https"
|
37
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
38
|
-
request.initialize_http_header({"User-Agent" => Cherrypicker::random_agent})
|
39
|
-
unless (uri.host.include? 'youtube.com') && (uri.request_uri.include? 'videoplayback') #youtube throws EOFError
|
40
|
-
head = http.request_head(URI.escape(uri.path))
|
41
|
-
case head
|
42
|
-
when Net::HTTPForbidden
|
43
|
-
@size = nil #no content-length no progress bar
|
44
|
-
else
|
45
|
-
@size = head['content-length'] if @size.nil? && head['content-length'].to_i > 1024
|
46
|
-
end
|
47
|
-
end
|
48
|
-
http.request(request) do |response|
|
49
|
-
bar = ProgressBar.new((@filename ||= File.basename(uri.path)), @size.to_i) unless @size.nil?
|
50
|
-
File.open(@location + (@filename ||= File.basename(uri.path)), "wb") do |file|
|
51
|
-
response.read_body do |segment|
|
52
|
-
@progress += segment.length
|
53
|
-
bar.set(@progress) unless @size.nil?
|
54
|
-
file.write(segment)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
@finished = true
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|