Class: Cherrypicker::Megavideo

Inherits:
PluginBase show all
Defined in:
lib/cherrypicker/plugins/megavideo.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PluginBase

inherited

Constructor Details

#initialize(link, opts = {}) ⇒ Megavideo

Returns a new instance of Megavideo.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cherrypicker/plugins/megavideo.rb', line 13

def initialize(link, opts={})
  o = {
    :location => nil,
  }.merge(opts)

  @link         = link
  @filename     = ""
  @location     = o[:location]
  @download_url = ""
  @size         = 0

  video_id = @link[/v[\/=](\w*)&?/, 1]

  #credit http://stackoverflow.com/questions/5748876/build-array-of-flashvars-using-hpricot
  html = open("http://megavideo.com/?v=#{video_id}").read
  flashvars = Hash[ html.scan( /flashvars\.(\w+)\s*=\s*["']?(.+?)["']?;/ ) ]

  key_s =  flashvars["s"]
  key_un = flashvars["un"]
  key_k1 = flashvars["k1"]
  key_k2 = flashvars["k2"]

title = flashvars["title"]
@size = flashvars["size"].to_i * 1024 * 1024

@download_url = "http://www#{key_s}.megavideo.com/files/#{decrypt(key_un,key_k1,key_k2)}/#{title}.flv"
@filename = title + ".flv"
end

Instance Attribute Details

#download_urlObject

Returns the value of attribute download_url.



7
8
9
# File 'lib/cherrypicker/plugins/megavideo.rb', line 7

def download_url
  @download_url
end

#filenameObject

Returns the value of attribute filename.



7
8
9
# File 'lib/cherrypicker/plugins/megavideo.rb', line 7

def filename
  @filename
end

Returns the value of attribute link.



7
8
9
# File 'lib/cherrypicker/plugins/megavideo.rb', line 7

def link
  @link
end

#locationObject

Returns the value of attribute location.



7
8
9
# File 'lib/cherrypicker/plugins/megavideo.rb', line 7

def location
  @location
end

Class Method Details

.matches_provider?(url) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/cherrypicker/plugins/megavideo.rb', line 9

def self.matches_provider?(url)
  url.include?("megavideo.com")
end

Instance Method Details

#decrypt(un, k1, k2) ⇒ Object



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
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cherrypicker/plugins/megavideo.rb', line 42

def decrypt(un,k1,k2) #credit http://userscripts.org/scripts/review/42944
  k1 = k1.to_i
  k2 = k2.to_i

  #convert the hex "un" to binary
  location1 = Array.new
  un.each_char do |char|
    #puts "#{char} => #{char.to_i(16).to_s(2)}"
    location1 << ("000" + char.to_i(16).to_s(2))[-4,4]
  end

  location1 = location1.join("").split("")

  location6 = Array.new
  0.upto(383) do |n|
    k1 = (k1 * 11 + 77213) % 81371
    k2 = (k2 * 17 + 92717) % 192811
    location6[n] = (k1 + k2) % 128
  end

  location3 = Array.new
  location4 = Array.new
  location5 = Array.new
  location8 = Array.new

  256.downto(0) do |n|
    location5 = location6[n]
    location4 = n % 128		
    location8 = location1[location5]
    location1[location5] = location1[location4]
    location1[location4] = location8
  end

  0.upto(127) do |n|
    location1[n] = location1[n].to_i ^ location6[n+256] & 1
  end

  location12 = location1.join("")
  location7 = Array.new

  n = 0
  while (n < location12.length) do
    location9 = location12[n,4]
    location7 << location9
    n+=4
  end

  result = ""
  location7.each do |bin|
    result = result + bin.to_i(2).to_s(16)
  end
  result
end

#downloadObject



96
97
98
# File 'lib/cherrypicker/plugins/megavideo.rb', line 96

def download
  Cherrypicker::download_file(@download_url, :location => @location, :size => @size)
end