forked from id774/automaticruby
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathchan_toru.rb
More file actions
57 lines (49 loc) · 1.41 KB
/
chan_toru.rb
File metadata and controls
57 lines (49 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
# Name:: Automatic::Plugin::Subscription::ChanToru
# Author:: soramugi <http://soramugi.net>
# Created:: Jun 28, 2013
# Updated:: Jan 15, 2014
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
require File.expand_path(File.dirname(__FILE__) + '/g_guide')
module Automatic::Plugin
class SubscriptionChanToru
def initialize(config, pipeline=[])
@config = config
@pipeline = pipeline
end
def g_guide_pipeline
SubscriptionGGuide.new(@config, @pipeline).run
end
def run
retries = 0
retry_max = @config['retry'].to_i || 0
begin
pipeline = g_guide_pipeline
pipeline.each {|feeds|
feeds.items.each {|feed|
feed = link_change(feed)
}
}
@pipeline = pipeline
rescue
retries += 1
Automatic::Log.puts("error", "ErrorCount: #{retries}, Fault in parsing: #{retries}")
sleep ||= @config['interval'].to_i
retry if retries <= retry_max
end
@pipeline
end
def link_change(feed)
feed.link.gsub(/([0-9]+)/) do |pid|
if pid != ''
feed.link = "https://tv.so-net.ne.jp/chan-toru/intent" +
"?cat=1&area=23&pid=#{pid}&from=tw"
else
feed.link = nil
end
end
feed
end
end
end