Class: Aniview::Interface::Subscription

Inherits:
Bridge
  • Object
show all
Includes:
Observable
Defined in:
lib/aniview/interface/subscription/subscription.rb

Instance Method Summary collapse

Methods inherited from Bridge

#make_hash

Constructor Details

#initialize(pref, schedule, delugec, client) ⇒ Subscription

Returns a new instance of Subscription.



13
14
15
16
17
18
19
20
# File 'lib/aniview/interface/subscription/subscription.rb', line 13

def initialize pref, schedule, delugec, client
   @c = client
	@pref = pref
   @schedule = schedule
   @delugec = delugec
   #SimpleRSS.feed_tags << :"torrent:magnetURI"
   #&lt;![CDATA[
end

Instance Method Details

#checkDaemonObject



26
27
28
29
30
31
32
# File 'lib/aniview/interface/subscription/subscription.rb', line 26

def checkDaemon
  if @c.server?
    "daemon up"
  else
    "daemon down"
  end
end

#editItem(loc, newval) ⇒ Object



114
115
116
117
118
119
# File 'lib/aniview/interface/subscription/subscription.rb', line 114

def editItem loc, newval
  @schedule.schedule[loc].setRegexp newval
  @schedule.save
  changed
  notify_observers
end

#feedObject



56
57
58
# File 'lib/aniview/interface/subscription/subscription.rb', line 56

def feed
  @rss
end

#forceMatchObject



103
104
105
106
107
108
# File 'lib/aniview/interface/subscription/subscription.rb', line 103

def forceMatch
  @mthread = Thread.new do
    updateFeed
    matchAll
  end
end

#getLastCheckedObject



34
35
36
# File 'lib/aniview/interface/subscription/subscription.rb', line 34

def getLastChecked
  @c.lastchecked
end

#getNextCheckObject



38
39
40
# File 'lib/aniview/interface/subscription/subscription.rb', line 38

def getNextCheck
  @c.sendMsg "nextcheck"
end

#itemsObject



110
111
112
# File 'lib/aniview/interface/subscription/subscription.rb', line 110

def items
  @schedule.items
end

#log(s) ⇒ Object



22
23
24
# File 'lib/aniview/interface/subscription/subscription.rb', line 22

def log s
  puts "#{Time.now.to_s} [subscription] " + s
end

#match(regexp, verbose = false) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/aniview/interface/subscription/subscription.rb', line 60

def match regexp, verbose=false
   re = Regexp.new regexp
   matches = []
	@rss.items.each{ |item|
     #log "-> checking against #{item[:title]}" if verbose
     re.match item[:title] { matches << item }
	}
   return matches
end

#matchAll(verbose: false) ⇒ Object



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
# File 'lib/aniview/interface/subscription/subscription.rb', line 70

def matchAll (verbose: false)
  updateFeed if @rss == nil
  return [] if @rss == nil
    
  log "matching all" if verbose
    
  total_matches = 0
  @schedule.schedule.each { |subs|
    log "matching #{subs.attributes["r"]}" if verbose
    matches = match subs.attributes["r"], verbose
    log "found #{matches.length} matches"  if verbose
    #log "#{matches}"  if verbose
    
    if matches.length >= 1
    
      downloaddir = @pref.parseDir(subs.attributes["p"]) + "/"
      newfile = downloaddir + matches[0][:title]
    
      next if File.exist? newfile
      log "attempting to downloading file" if verbose
      log "set download dir to #{newfile}" if verbose
      log "#{matches[0].link}" if verbose
      s = @delugec.addTorrent matches[0].link, @pref.parseDir(subs.attributes["p"]), verbose: true
      log "adding torrent, status #{s}" if verbose
      subs.setSeen if s
      @schedule.save
      total_matches+=1
    end
  }
  log "match complete, #{total_matches} found" if verbose
  return total_matches
end

#syncMatchesObject



42
43
44
# File 'lib/aniview/interface/subscription/subscription.rb', line 42

def syncMatches
  @schedule.mergeItems @c.getItems
end

#updateFeedObject



46
47
48
49
50
51
52
53
54
# File 'lib/aniview/interface/subscription/subscription.rb', line 46

def updateFeed
   begin
     SimpleRSS.item_tags << :"torrent:magnetURI"
	  @rss = SimpleRSS.parse open(@pref.get("rss_feed")["url"])
    
   rescue SocketError
     @rss = nil
   end
end