Class: Aniview::Interface::Subscription
- Inherits:
-
Object
- Object
- Aniview::Interface::Subscription
- Defined in:
- lib/aniview/interface/subscription/subscription.rb
Instance Method Summary collapse
- #checkDaemon ⇒ Object
- #editItem(loc, newval) ⇒ Object
- #feed ⇒ Object
- #forceMatch ⇒ Object
- #getAll ⇒ Object
- #getLastChecked ⇒ Object
-
#initialize(pref, schedule, delugec, client) ⇒ Subscription
constructor
A new instance of Subscription.
- #log(s) ⇒ Object
- #makeHash(arr) ⇒ Object
- #match(regexp, verbose = false) ⇒ Object
- #matchAll(verbose: false) ⇒ Object
- #syncMatches ⇒ Object
- #updateFeed ⇒ Object
Constructor Details
#initialize(pref, schedule, delugec, client) ⇒ Subscription
Returns a new instance of Subscription.
9 10 11 12 13 14 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 9 def initialize pref, schedule, delugec, client @c = client @pref = pref @schedule = schedule @delugec = delugec end |
Instance Method Details
#checkDaemon ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 20 def checkDaemon if @c.server? "daemon up" else "daemon down" end end |
#editItem(loc, newval) ⇒ Object
105 106 107 108 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 105 def editItem loc, newval @schedule.getAll[loc].setRegexp newval @schedule.save end |
#feed ⇒ Object
49 50 51 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 49 def feed @rss end |
#forceMatch ⇒ Object
94 95 96 97 98 99 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 94 def forceMatch @mthread = Thread.new do updateFeed matchAll end end |
#getAll ⇒ Object
101 102 103 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 101 def getAll @schedule.getAll end |
#getLastChecked ⇒ Object
28 29 30 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 28 def getLastChecked @c.lastchecked end |
#log(s) ⇒ Object
16 17 18 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 16 def log s puts "#{Time.now.to_s} [subscription] " + s end |
#makeHash(arr) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 110 def makeHash(arr) ret = {} arr.each{ |subs| ret.merge!(subs => subs) } return ret end |
#match(regexp, verbose = false) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 53 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
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 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 63 def matchAll (verbose: false) updateFeed if @rss == nil return [] if @rss == nil log "matching all" if verbose total_matches = 0 getAll.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 "set download dir to #{newfile}" 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 |
#syncMatches ⇒ Object
32 33 34 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 32 def syncMatches @schedule.mergeItems @c.getItems end |
#updateFeed ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 36 def updateFeed begin @rss = SimpleRSS.parse open(@pref.get("rss_feed")["url"]) rescue SocketError @rss = nil #rescue # @rss = nil end end |