cherrypicker 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,9 +2,9 @@ Cherrypicker
2
2
  =========
3
3
 
4
4
  Cherrypicker was part of my final year project for university it
5
- is a Ruby Gem that lets you download from; Rapidshare or Hotfile
5
+ is a Ruby Gem that lets you download from; Rapidshare, Hotfile and Vimeo
6
6
  You can also utilise the LinkChecker to see if your files are
7
- alive on Rapidshare or Hotfile
7
+ alive on Rapidshare and Hotfile
8
8
 
9
9
  Enjoy!
10
10
 
@@ -34,6 +34,8 @@ Examples
34
34
  test3 = Rapidshare.new("http://rapidshare.com/files/329036215/myfile.rar", "username", "password", "size", "/location/tosave/file/")
35
35
  test3.download
36
36
 
37
+ Vimeo.new("http://www.vimeo.com/2119458", "/Volumes/Storage/Desktop/cherrytest/").download
38
+
37
39
  Download.new("http://download.thinkbroadband.com/10MB.zip", "/location/tosave/file/")
38
40
  Download.new("http://download.thinkbroadband.com/10MB.zip", "/location/tosave/file/", "10485760")
39
41
 
@@ -27,14 +27,26 @@ class Download
27
27
  http.use_ssl = true if uri.scheme == "https"
28
28
  request = Net::HTTP::Get.new(uri.request_uri)
29
29
  request.initialize_http_header({"User-Agent" => random_agent})
30
- @size = http.request_head(URI.escape(uri.path))['content-length'].to_i if @size.nil?
31
- http.request(request) do |response|
32
- bar = ProgressBar.new((@filename ||= File.basename(uri.path)), @size.to_i)
33
- File.open(@location + (@filename ||= File.basename(uri.path)), "wb") do |file|
34
- response.read_body do |segment|
35
- @progress += segment.length
36
- bar.set(@progress)
37
- file.write(segment)
30
+ @size = http.request_head(URI.escape(uri.path))['content-length'] if @size.nil?
31
+ #no content-length no progress bar
32
+ if @size.nil? || uri.host == "av.vimeo.com" #catch vimeo
33
+ http.request(request) do |response|
34
+ File.open(@location + (@filename ||= File.basename(uri.path)), "wb") do |file|
35
+ response.read_body do |segment|
36
+ @progress += segment.length
37
+ file.write(segment)
38
+ end
39
+ end
40
+ end
41
+ else
42
+ http.request(request) do |response|
43
+ bar = ProgressBar.new((@filename ||= File.basename(uri.path)), @size.to_i)
44
+ File.open(@location + (@filename ||= File.basename(uri.path)), "wb") do |file|
45
+ response.read_body do |segment|
46
+ @progress += segment.length
47
+ bar.set(@progress)
48
+ file.write(segment)
49
+ end
38
50
  end
39
51
  end
40
52
  end
@@ -1,11 +1,11 @@
1
- require 'open-uri'
2
-
3
1
  # Class that can sort Hotfile link into sections as specified by Hotfile API
4
2
  #
5
3
  # hotfile = Hotfile.new("http://hotfile.com/dl/110589431/6ad2666/ROT007-WEB-2011.rar.html", "username", "password")
6
4
  # puts hotfile.link
7
5
  # puts hotfile.hostname
8
6
  # hotfile.download
7
+ require 'open-uri'
8
+
9
9
  class Hotfile
10
10
  attr_accessor :link, :hostname, :filename, :username, :password, :size, :location
11
11
 
@@ -1,5 +1,3 @@
1
- require 'open-uri'
2
-
3
1
  # Class that can sort Rapidshare link into sections as specified by RapidShare API
4
2
  #
5
3
  # rapid = Rapidshare.new("http://rapidshare.com/files/329036215/The.Matrix.bandaa25.part06.rar", "username", "password")
@@ -8,6 +6,8 @@ require 'open-uri'
8
6
  # puts rapid.filename
9
7
  # puts rapid.host
10
8
  # rapid.download
9
+ require 'open-uri'
10
+
11
11
  class Rapidshare
12
12
  attr_accessor :link, :fileid, :filename, :hostname, :username, :password, :size, :location
13
13
 
@@ -0,0 +1,45 @@
1
+ # Class that can download from Vimeo
2
+ # Vimeo.new("http://www.vimeo.com/2119458", "/Volumes/Storage/Desktop/cherrytest/").download
3
+
4
+ #<!-- _
5
+ # __ _|_|_ __ ___ ___ ___
6
+ # \ \ / / | '_ ' _ \ / _ \/ _ \
7
+ # \ V /| | | | | | | __/ |_| |
8
+ # \_/ |_|_| |_| |_|\___|\___/
9
+ # you know, for videos
10
+ #-->
11
+
12
+ class Vimeo
13
+ attr_accessor :link, :filename, :location, :download_url
14
+
15
+ def initialize(link, location = "")
16
+ @link = link
17
+ @filename = ""
18
+ @location = location
19
+ @download_url = ""
20
+
21
+ hostname = "http://www.vimeo.com/moogaloop/play/clip"
22
+
23
+ #the vimeo ID consists of decimal numbers in the URL
24
+ vimeo_id = @link[/\d+/]
25
+ response = remote_query("http://www.vimeo.com/moogaloop/load/clip:#{vimeo_id}")
26
+ title = response.body[/<caption>(.*)<\/caption>/, 1]
27
+ request_signature = response.body[/<request_signature>(.*)<\/request_signature>/, 1]
28
+ request_signature_expires = response.body[/<request_signature_expires>(\d+)<\/request_signature_expires>/, 1]
29
+ hd = response.body[/<isHD>(.*)<\/isHD>/, 1]
30
+
31
+ if hd.to_i == 0
32
+ download_url = ":#{vimeo_id}/#{request_signature}/#{request_signature_expires}"
33
+ else
34
+ download_url = ":#{vimeo_id}/#{request_signature}/#{request_signature_expires}/?q=hd"
35
+ end
36
+
37
+ @filename = title.delete("\"'").gsub(/[^0-9A-Za-z]/, '_') + ".flv"
38
+ reply = remote_query("#{hostname}#{download_url}")
39
+ @download_url = reply.response['location']
40
+ end
41
+
42
+ def download
43
+ Download.new(@download_url, @location)
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module Cherrypicker
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
data/lib/cherrypicker.rb CHANGED
@@ -1,5 +1,6 @@
1
- require 'cherrypicker/rapidshare'
2
- require 'cherrypicker/hotfile'
3
1
  require 'cherrypicker/download'
4
2
  require 'cherrypicker/linkchecker'
5
- require 'cherrypicker/functions'
3
+ require 'cherrypicker/functions'
4
+ require "cherrypicker/plugins/vimeo"
5
+ require "cherrypicker/plugins/rapidshare"
6
+ require "cherrypicker/plugins/hotfile"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cherrypicker
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.6
5
+ version: 0.2.7
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-04-19 00:00:00 +01:00
13
+ date: 2011-04-20 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -42,9 +42,10 @@ files:
42
42
  - lib/cherrypicker.rb
43
43
  - lib/cherrypicker/download.rb
44
44
  - lib/cherrypicker/functions.rb
45
- - lib/cherrypicker/hotfile.rb
46
45
  - lib/cherrypicker/linkchecker.rb
47
- - lib/cherrypicker/rapidshare.rb
46
+ - lib/cherrypicker/plugins/hotfile.rb
47
+ - lib/cherrypicker/plugins/rapidshare.rb
48
+ - lib/cherrypicker/plugins/vimeo.rb
48
49
  - lib/cherrypicker/version.rb
49
50
  - test/test_helper.rb
50
51
  - test/unit/hostfile_test.rb