Module: Cherrypicker
- Defined in:
- lib/cherrypicker/linkchecker.rb,
lib/cherrypicker/helpers.rb,
lib/cherrypicker/version.rb,
lib/cherrypicker/cherrypick.rb,
lib/cherrypicker/plugins/vimeo.rb,
lib/cherrypicker/plugins/rghost.rb,
lib/cherrypicker/plugins/hotfile.rb,
lib/cherrypicker/plugins/youtube.rb,
lib/cherrypicker/plugins/megavideo.rb,
lib/cherrypicker/plugins/rapidshare.rb
Overview
<!– _
__ _|_|_ __ ___ ___ ___
\ \ / / | '_ ' _ \ / _ \/ _ \
\ V /| | | | | | | __/ |_| |
\_/ |_|_| |_| |_|\___|\___/
you know, for videos
–>
Defined Under Namespace
Classes: Cherrypick, Hotfile, LinkChecker, Megavideo, Rapidshare, Rghost, SingleLink, Vimeo, Youtube
Constant Summary
collapse
- VERSION =
"0.3.14"
Class Method Summary
collapse
Class Method Details
.download_file(link, opts = {}) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/cherrypicker/helpers.rb', line 31
def self.download_file(link, opts={})
o = {
:location => nil,
:size => nil,
:filename => nil
}.merge(opts)
@link = link
@size = o[:size]
@location = o[:location] ||= ""
@filename = o[:filename]
@progress = 0
@finished = false
uri = URI.parse(@link.to_s)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == "https"
http.open_timeout = 3 http.read_timeout = 3 request = Net::HTTP::Get.new(uri.request_uri)
request.({"User-Agent" => Cherrypicker::random_agent})
unless (uri.host.include? 'youtube.com') && (uri.request_uri.include? 'videoplayback') head = http.request_head(URI.escape(uri.path))
case head
when Net::HTTPForbidden
@size = nil else
@size = head['content-length'] if @size.nil? && head['content-length'].to_i > 1024
end
end
puts "unknown file size for #{@filename} but downloading..." if @size.nil?
puts @link.to_s
http.request(request) do |response|
bar = ProgressBar.new((@filename ||= File.basename(uri.path)), @size.to_i) unless @size.nil?
bar.format_arguments=[:title, :percentage, :bar, :stat_for_file_transfer] unless @size.nil?
File.open(@location + (@filename ||= File.basename(uri.path)), "wb") do |file|
response.read_body do |segment|
@progress += segment.length
bar.set(@progress) unless @size.nil?
file.write(segment)
end
end
end
@finished = true
puts
puts "download completed"
puts
end
|
.hash_to_url(hash) ⇒ Object
85
86
87
88
89
90
|
# File 'lib/cherrypicker/helpers.rb', line 85
def self.hash_to_url(hash)
hash.keys.inject('') do |query_string, key|
query_string << '&' unless key == hash.keys.first
query_string << "#{URI.encode(key.to_s)}=#{URI.encode(hash[key])}"
end
end
|
.random_agent ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/cherrypicker/helpers.rb', line 92
def self.random_agent
useragent = [ "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090913 Firefox/3.5.3",
"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)",
"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)",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.1) Gecko/20090718 Firefox/3.5.1",
"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",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.2)",
"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)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Win64; x64; Trident/4.0)",
"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)",
"Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.50 Safari/534.24"]
return useragent[rand(useragent.length)]
end
|
.remote_query(url) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/cherrypicker/helpers.rb', line 14
def self.remote_query(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == "https"
http.open_timeout = 3 http.read_timeout = 3 request = Net::HTTP::Get.new(uri.request_uri)
request.({"User-Agent" => random_agent})
response = http.request(request)
if response["X-APICPU"]
if (response["X-APICPU"][/(\d*)\/\d*/, 1]).to_i > 9500
sleep 60 end
end
return http.request(request)
end
|