Class: Cherrypicker::LinkChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/cherrypicker/linkchecker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(links) ⇒ LinkChecker

Returns a new instance of LinkChecker.



13
14
15
16
17
18
19
20
# File 'lib/cherrypicker/linkchecker.rb', line 13

def initialize(links)
  @links = links
  if links[0] =~ /^http(s|):\/\/(www.|)rapidshare.com/
    @status = rapidshare
  else
    @status = hotfile
  end
end

Instance Attribute Details

Returns the value of attribute links.



11
12
13
# File 'lib/cherrypicker/linkchecker.rb', line 11

def links
  @links
end

#statusObject

Returns the value of attribute status.



11
12
13
# File 'lib/cherrypicker/linkchecker.rb', line 11

def status
  @status
end

Instance Method Details

#hotfileObject



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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/cherrypicker/linkchecker.rb', line 62

def hotfile
  links = self.links
  ids = Array.new 
  keys = Array.new
  singlelinks = Array.new

  links.each do |link|
    link[/http\:\/\/hotfile\.com\/dl\/([^\/]+)\/([^\/]+)\/([^\/]+)/]
    ids << Regexp.last_match(1)
    keys << Regexp.last_match(2)
  end

  Cherrypicker::query = "http://api.hotfile.com/?action=checklinks&" + 
  hash_to_url({
    :links  =>   links.join(","),
    :id  =>      ids.join(","),
    :keys  =>    keys.join(","),
    :files  =>  "id,status,size"
  })

  check = Cherrypicker::remote_query(query).body.split("\n")

  unless check.size == 0
    #"111044909,1,Playaz-Sub_Zero-PLAYAZ015-WEB-2011-EGM.rar "  
    check.each_with_index do |c, index|
      c[/([^,]+)\,([^,]+)\,([^,]+)/]
      name = Regexp.last_match(3)
      size = Regexp.last_match(1)
      if Regexp.last_match(2) == "1"
        status = "Alive"
      else
        status = "Dead"
      end
      singlelinks << Cherrypicker::SingleLink.new(links[index], "#{status}", size)
    end
  else
    links.each do |link|
      singlelinks << Cherrypicker::SingleLink.new(link, "Dead", nil)
    end
  end

  links = {}
  singlelinks.each do |a|
    links[a.status] ||= []
    links[a.status] << [a.link, a.size]
  end
  return links
end

#rapidshareObject



22
23
24
25
26
27
28
29
30
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
# File 'lib/cherrypicker/linkchecker.rb', line 22

def rapidshare
  links = self.links
  files = Array.new 
  filenames = Array.new
  singlelinks = Array.new

  self.links.each do |link|
    files << link[/files\/(\d*)\//, 1]
    filenames << link[/files\/\d*\/(.*)/, 1]
  end

  query = "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=checkfiles&" + 
  Cherrypicker::hash_to_url({
    :files  =>      files.join(","),
    :filenames  =>  filenames.join(","),
    :incmd5  =>     '0'
  })

  check = Cherrypicker::remote_query(query).body.split("\n")

  #"452966383,ROT007-WEB-2011.rar,23635847,23,1,tl2,0"  
  check.each_with_index do |c, index|
    c[/([^,]+)\,([^,]+)\,([^,]+)\,([^,]+)\,([^,]+)\,([^,]+)\,([^,]+)/]
    size = Regexp.last_match(3)
    if Regexp.last_match(5) == "1"
      status = "Alive" 
    else 
      status = "Dead"
    end
    singlelinks << Cherrypicker::SingleLink.new(links[index], "#{status}", size)
  end

  links = {}
  singlelinks.each do |a|
    links[a.status] ||= []
    links[a.status] << [a.link, a.size]
  end
  return links   
end