Class: Aniview::Interface::Subscription
- Includes:
- Observable
- Defined in:
- lib/aniview/interface/subscription/subscription.rb
Instance Method Summary collapse
- #checkDaemon ⇒ Object
- #editItem(loc, newval) ⇒ Object
- #feed ⇒ Object
- #forceMatch ⇒ Object
- #getLastChecked ⇒ Object
- #getNextCheck ⇒ Object
-
#initialize(pref, schedule, delugec, client) ⇒ Subscription
constructor
A new instance of Subscription.
- #items ⇒ Object
- #log(s) ⇒ Object
- #match(regexp, verbose = false) ⇒ Object
- #matchAll(verbose: false) ⇒ Object
- #syncMatches ⇒ Object
- #updateFeed ⇒ Object
Methods inherited from Bridge
Constructor Details
#initialize(pref, schedule, delugec, client) ⇒ 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" #<![CDATA[ end |
Instance Method Details
#checkDaemon ⇒ Object
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
118 119 120 121 122 123 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 118 def editItem loc, newval @schedule.schedule[loc].setRegexp newval @schedule.save changed notify_observers end |
#feed ⇒ Object
60 61 62 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 60 def feed @rss end |
#forceMatch ⇒ Object
107 108 109 110 111 112 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 107 def forceMatch @mthread = Thread.new do updateFeed matchAll end end |
#getLastChecked ⇒ Object
34 35 36 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 34 def getLastChecked @c.lastchecked end |
#getNextCheck ⇒ Object
38 39 40 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 38 def getNextCheck @c.sendMsg "nextcheck" end |
#items ⇒ Object
114 115 116 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 114 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
64 65 66 67 68 69 70 71 72 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 64 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
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 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 74 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 |
#syncMatches ⇒ Object
42 43 44 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 42 def syncMatches @schedule.mergeItems @c.getItems end |
#updateFeed ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/aniview/interface/subscription/subscription.rb', line 46 def updateFeed begin SimpleRSS. << :"torrent:magnetURI" @rss = SimpleRSS.parse open(@pref.get("rss_feed")["url"]) rescue SocketError @rss = nil #rescue # @rss = nil end end |