cherrypicker 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,7 +2,7 @@ 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, Hotfile and Vimeo
5
+ is a Ruby Gem that lets you download from; Rapidshare, Hotfile, Youtube and Vimeo
6
6
  You can also utilise the LinkChecker to see if your files are
7
7
  alive on Rapidshare and Hotfile
8
8
 
@@ -35,6 +35,8 @@ Examples
35
35
  test3.download
36
36
 
37
37
  Vimeo.new("http://www.vimeo.com/2119458", :location => "/Volumes/Storage/Desktop/cherrytest/").download
38
+ Youtube.new("http://www.youtube.com/watch?v=SF6I5VSZVqc", :location => "/Volumes/Storage/Desktop/cherrytest/").download
39
+ Megavideo.new("http://www.megavideo.com/?v=2PEKD0YS", :location => "/Volumes/Storage/Desktop/cherrytest/").download
38
40
 
39
41
  Download.new("http://download.thinkbroadband.com/10MB.zip", :location => "/location/tosave/file/")
40
42
  Download.new("http://download.thinkbroadband.com/10MB.zip", :location => "/location/tosave/file/", :size => 10485760)
data/cherrypicker.gemspec CHANGED
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency('progressbar', '~> 0.9')
22
+ s.add_dependency('progressbar', '~> 0.9')
23
23
  end
@@ -29,18 +29,20 @@ class Download
29
29
  end
30
30
 
31
31
  def download_file
32
- p uri = URI.parse(@link.to_s)
32
+ uri = URI.parse(@link.to_s)
33
33
  http = Net::HTTP.new(uri.host, uri.port)
34
34
  http.use_ssl = true if uri.scheme == "https"
35
35
  request = Net::HTTP::Get.new(uri.request_uri)
36
36
  request.initialize_http_header({"User-Agent" => random_agent})
37
- head = http.request_head(URI.escape(uri.path))
38
- case head
39
- when Net::HTTPForbidden
40
- @size = nil #no content-length no progress bar
41
- else
42
- @size = head['content-length'] if @size.nil? && head['content-length'].to_i > 1024
43
- end
37
+ unless (uri.host.include? 'youtube.com') && (uri.request_uri.include? 'videoplayback') #youtube throws EOFError
38
+ head = http.request_head(URI.escape(uri.path))
39
+ case head
40
+ when Net::HTTPForbidden
41
+ @size = nil #no content-length no progress bar
42
+ else
43
+ @size = head['content-length'] if @size.nil? && head['content-length'].to_i > 1024
44
+ end
45
+ end
44
46
  http.request(request) do |response|
45
47
  bar = ProgressBar.new((@filename ||= File.basename(uri.path)), @size.to_i) unless @size.nil?
46
48
  File.open(@location + (@filename ||= File.basename(uri.path)), "wb") do |file|
@@ -0,0 +1,95 @@
1
+ # Class that can download from Vimeo
2
+ # Megavideo.new("http://www.megavideo.com/?v=2PEKD0YS", :location => "/Volumes/Storage/Desktop/cherrytest/").download
3
+
4
+ require 'open-uri'
5
+
6
+ class Megavideo
7
+ attr_accessor :link, :filename, :location, :download_url
8
+
9
+ def initialize(link, opts={})
10
+ o = {
11
+ :location => nil,
12
+ }.merge(opts)
13
+
14
+ @link = link
15
+ @filename = ""
16
+ @location = o[:location]
17
+ @download_url = ""
18
+ @size = 0
19
+
20
+ video_id = @link[/v[\/=](\w*)&?/, 1]
21
+
22
+ #credit http://stackoverflow.com/questions/5748876/build-array-of-flashvars-using-hpricot
23
+ html = open("http://megavideo.com/?v=#{video_id}").read
24
+ flashvars = Hash[ html.scan( /flashvars\.(\w+)\s*=\s*["']?(.+?)["']?;/ ) ]
25
+
26
+ key_s = flashvars["s"]
27
+ key_un = flashvars["un"]
28
+ key_k1 = flashvars["k1"]
29
+ key_k2 = flashvars["k2"]
30
+
31
+ title = flashvars["title"]
32
+ @size = flashvars["size"].to_i * 1024 * 1024
33
+
34
+ @download_url = "http://www#{key_s}.megavideo.com/files/#{decrypt(key_un,key_k1,key_k2)}/#{title}.flv"
35
+ @filename = title + ".flv"
36
+ end
37
+
38
+ def decrypt(un,k1,k2) #credit http://userscripts.org/scripts/review/42944
39
+ k1 = k1.to_i
40
+ k2 = k2.to_i
41
+
42
+ #convert the hex "un" to binary
43
+ location1 = Array.new
44
+ un.each_char do |char|
45
+ #puts "#{char} => #{char.to_i(16).to_s(2)}"
46
+ location1 << ("000" + char.to_i(16).to_s(2))[-4,4]
47
+ end
48
+
49
+ location1 = location1.join("").split("")
50
+
51
+ location6 = Array.new
52
+ 0.upto(383) do |n|
53
+ k1 = (k1 * 11 + 77213) % 81371
54
+ k2 = (k2 * 17 + 92717) % 192811
55
+ location6[n] = (k1 + k2) % 128
56
+ end
57
+
58
+ location3 = Array.new
59
+ location4 = Array.new
60
+ location5 = Array.new
61
+ location8 = Array.new
62
+
63
+ 256.downto(0) do |n|
64
+ location5 = location6[n]
65
+ location4 = n % 128
66
+ location8 = location1[location5]
67
+ location1[location5] = location1[location4]
68
+ location1[location4] = location8
69
+ end
70
+
71
+ 0.upto(127) do |n|
72
+ location1[n] = location1[n].to_i ^ location6[n+256] & 1
73
+ end
74
+
75
+ location12 = location1.join("")
76
+ location7 = Array.new
77
+
78
+ n = 0
79
+ while (n < location12.length) do
80
+ location9 = location12[n,4]
81
+ location7 << location9
82
+ n+=4
83
+ end
84
+
85
+ result = ""
86
+ location7.each do |bin|
87
+ result = result + bin.to_i(2).to_s(16)
88
+ end
89
+ result
90
+ end
91
+
92
+ def download
93
+ Download.new(@download_url, :location => @location, :size => @size)
94
+ end
95
+ end
@@ -0,0 +1,67 @@
1
+ # Class that can download from Vimeo
2
+ # Youtube.new("http://www.youtube.com/watch?v=SF6I5VSZVqc", :location => "/Volumes/Storage/Desktop/cherrytest/").download
3
+
4
+ require "cgi"
5
+
6
+ class Youtube
7
+ attr_accessor :link, :filename, :location, :download_url
8
+
9
+ def initialize(link, opts={})
10
+
11
+ o = {
12
+ :location => nil,
13
+ }.merge(opts)
14
+
15
+ @link = link
16
+ @filename = ""
17
+ @location = o[:location]
18
+ @download_url = ""
19
+
20
+ video_id = @link[/v[\/=](.*)/,1]
21
+ video_info = remote_query("http://www.youtube.com/get_video_info?video_id=#{video_id}").body
22
+
23
+ #converting the huge infostring into a hash. simply by splitting it at the & and then splitting it into key and value arround the =
24
+ #credit https://github.com/rb2k/viddl-rb/blob/master/plugins/youtube.rb
25
+ video_info_hash = Hash[*video_info.split("&").collect { |v|
26
+ key, value = v.split "="
27
+ value = CGI::unescape(value) if value
28
+ if key =~ /_map/
29
+ value = value.split(",")
30
+ value = if key == "fmt_map"
31
+ Hash[*value.collect{ |v|
32
+ k2, *v2 = v.split("/")
33
+ [k2, v2]
34
+ }.flatten(1)]
35
+ elsif key == "fmt_url_map" || key == "fmt_stream_map"
36
+ Hash[*value.collect { |v| v.split("|")}.flatten]
37
+ end
38
+ end
39
+ [key, value]
40
+ }.flatten]
41
+
42
+ #Standard = 34 <- flv
43
+ #Medium = 18 <- mp4
44
+ #High = 35 <- flv
45
+ #720p = 22 <- mp4
46
+ #1080p = 37 <- mp4
47
+ #mobile = 17 <- 3gp
48
+ # --> 37 > 22 > 35 > 18 > 34 > 17
49
+ formats = video_info_hash["fmt_map"].keys
50
+
51
+ format_ext = {}
52
+ format_ext["37"] = ["mp4", "MP4 Highest Quality 1920x1080"]
53
+ format_ext["22"] = ["mp4", "MP4 1280x720"]
54
+ format_ext["35"] = ["flv", "FLV 854x480"]
55
+ format_ext["34"] = ["flv", "FLV 640x360"]
56
+ format_ext["18"] = ["mp4", "MP4 480x270"]
57
+ format_ext["17"] = ["3gp", "3gp"]
58
+ format_ext["5"] = ["flv", "old default?"]
59
+
60
+ @download_url = video_info_hash["fmt_url_map"][formats.first]
61
+ @filename = video_info_hash["title"].delete("\"'").gsub(/[^0-9A-Za-z]/, '_') + "." + format_ext[formats.first].first
62
+ end
63
+
64
+ def download
65
+ Download.new(@download_url, :location => @location, :filename => @filename)
66
+ end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module Cherrypicker
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/cherrypicker.rb CHANGED
@@ -4,3 +4,5 @@ require 'cherrypicker/helpers'
4
4
  require "cherrypicker/plugins/vimeo"
5
5
  require "cherrypicker/plugins/rapidshare"
6
6
  require "cherrypicker/plugins/hotfile"
7
+ require "cherrypicker/plugins/youtube"
8
+ require "cherrypicker/plugins/megavideo"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cherrypicker
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.3.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Karl Entwistle
@@ -44,8 +44,10 @@ files:
44
44
  - lib/cherrypicker/helpers.rb
45
45
  - lib/cherrypicker/linkchecker.rb
46
46
  - lib/cherrypicker/plugins/hotfile.rb
47
+ - lib/cherrypicker/plugins/megavideo.rb
47
48
  - lib/cherrypicker/plugins/rapidshare.rb
48
49
  - lib/cherrypicker/plugins/vimeo.rb
50
+ - lib/cherrypicker/plugins/youtube.rb
49
51
  - lib/cherrypicker/version.rb
50
52
  - test/test_helper.rb
51
53
  - test/unit/hostfile_test.rb