my-lib 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/lib/my-lib.rb +411 -0
- data/my-lib.gemspec +72 -0
- data/spec/my-lib_spec.rb +19 -0
- data/spec/spec_helper.rb +12 -0
- metadata +150 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "term-ansicolor"
|
6
|
+
gem "eventmachine"
|
7
|
+
gem "mechanize"
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "> 2.3.0"
|
12
|
+
gem "yard", "> 0.6.0"
|
13
|
+
gem "bundler", "> 1.0.0"
|
14
|
+
gem "jeweler"
|
15
|
+
gem "rcov", ">= 0"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
eventmachine (0.12.10)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.6.4)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
mechanize (2.0.1)
|
12
|
+
net-http-digest_auth (>= 1.1.1, ~> 1.1)
|
13
|
+
net-http-persistent (~> 1.8)
|
14
|
+
nokogiri (~> 1.4)
|
15
|
+
webrobots (>= 0.0.9, ~> 0.0)
|
16
|
+
net-http-digest_auth (1.1.1)
|
17
|
+
net-http-persistent (1.8.1)
|
18
|
+
nokogiri (1.5.0)
|
19
|
+
rake (0.9.2)
|
20
|
+
rcov (0.9.10)
|
21
|
+
rspec (2.6.0)
|
22
|
+
rspec-core (~> 2.6.0)
|
23
|
+
rspec-expectations (~> 2.6.0)
|
24
|
+
rspec-mocks (~> 2.6.0)
|
25
|
+
rspec-core (2.6.4)
|
26
|
+
rspec-expectations (2.6.0)
|
27
|
+
diff-lcs (~> 1.1.2)
|
28
|
+
rspec-mocks (2.6.0)
|
29
|
+
term-ansicolor (1.0.6)
|
30
|
+
webrobots (0.0.11)
|
31
|
+
nokogiri (>= 1.4.4)
|
32
|
+
yard (0.7.2)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
bundler (> 1.0.0)
|
39
|
+
eventmachine
|
40
|
+
jeweler
|
41
|
+
mechanize
|
42
|
+
rcov
|
43
|
+
rspec (> 2.3.0)
|
44
|
+
term-ansicolor
|
45
|
+
yard (> 0.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 modeverv
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= my-lib
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to my-lib
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 modeverv. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "my-lib"
|
18
|
+
gem.homepage = "http://github.com/modeverv/my-lib"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{one-line summary of your gem}
|
21
|
+
gem.description = %Q{longer description of your gem}
|
22
|
+
gem.email = "modeverv@gmail.com"
|
23
|
+
gem.authors = ["modeverv"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'yard'
|
42
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/lib/my-lib.rb
ADDED
@@ -0,0 +1,411 @@
|
|
1
|
+
#-*- coding:utf-8 -*-
|
2
|
+
|
3
|
+
# make String Colored
|
4
|
+
require 'rubygems'
|
5
|
+
require 'term/ansicolor'
|
6
|
+
class String
|
7
|
+
include Term::ANSIColor
|
8
|
+
end
|
9
|
+
|
10
|
+
# Class For Log to /var/log/system.log
|
11
|
+
# @author modeverv@gmail.com
|
12
|
+
# @example
|
13
|
+
# MyLogger.ln("message")
|
14
|
+
# MyLogger.lw("message")
|
15
|
+
class MyLogger
|
16
|
+
|
17
|
+
# log notice
|
18
|
+
# @param [String] message message for log
|
19
|
+
def self.ln(message)
|
20
|
+
self.before
|
21
|
+
Syslog.log(Syslog::LOG_NOTICE, "%s", message)
|
22
|
+
self.after
|
23
|
+
end
|
24
|
+
|
25
|
+
# log warning
|
26
|
+
# @param [String] message message for log
|
27
|
+
def self.lw(message)
|
28
|
+
self.before
|
29
|
+
Syslog.log(Syslog::LOG_WARNING, "%s", message)
|
30
|
+
self.after
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
# open syslog
|
35
|
+
def self.before
|
36
|
+
require 'syslog'
|
37
|
+
include Syslog::Constants
|
38
|
+
Syslog.open("ruby_syslog.rb")
|
39
|
+
end
|
40
|
+
# close syslog
|
41
|
+
def self.after
|
42
|
+
Syslog.close();
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
# Job Class for Fetch Anisoku
|
48
|
+
# Function:
|
49
|
+
# access "youtubeanisoku1.blog106.fc2.com" and crawl web site.
|
50
|
+
# find a link to "say-move.org" and access "say-move.org".
|
51
|
+
# finary find video link of Animetion,then fetch video file to your local.
|
52
|
+
# save video directory is supplied by machine.
|
53
|
+
# Notice:
|
54
|
+
# job is automatically generated on after another.
|
55
|
+
# This Class Needs to be handle by Machine Class
|
56
|
+
# @example
|
57
|
+
# # inside machine class
|
58
|
+
# job = MyJobAnisoku.new(
|
59
|
+
# :machine => self
|
60
|
+
# )
|
61
|
+
# job.run
|
62
|
+
#
|
63
|
+
class MyJobAnisoku
|
64
|
+
|
65
|
+
def initialize(args = { })
|
66
|
+
require 'rubygems'
|
67
|
+
require 'kconv'
|
68
|
+
require 'mechanize'
|
69
|
+
require 'net/http'
|
70
|
+
@a = args
|
71
|
+
@a[:url] ||= 'http://youtubeanisoku1.blog106.fc2.com/'
|
72
|
+
@a[:url] = URI.parse @a[:url] unless @a[:url].class == URI::HTTP
|
73
|
+
@agent = Mechanize.new
|
74
|
+
@a[:status] ||= :new
|
75
|
+
raise "job have no machine error" unless @a[:machine]
|
76
|
+
end
|
77
|
+
|
78
|
+
# check kousin page
|
79
|
+
def tokkakari
|
80
|
+
@agent.get @a[:url]
|
81
|
+
links_kousins = @agent.page.links_with(:text => /#{"更新状況".toutf8}/)
|
82
|
+
targs = []
|
83
|
+
links_kousins.each do |link|
|
84
|
+
targs << link.uri
|
85
|
+
end
|
86
|
+
targs.each_with_index do |link,i|
|
87
|
+
break if i > 6
|
88
|
+
job = MyJobAnisoku.new(
|
89
|
+
:url => link,
|
90
|
+
:status => :second,
|
91
|
+
:machine => @a[:machine]
|
92
|
+
)
|
93
|
+
@a[:machine].retry job
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# check shoukai page
|
98
|
+
def second
|
99
|
+
@agent.get @a[:url]
|
100
|
+
links_kousin = @agent.page/"/html/body/table/tr[2]/td/table/tr/td[2]/div[4]/ul/li/a/@href"
|
101
|
+
# links_kobetu
|
102
|
+
links_kobetu = []
|
103
|
+
links_kousin.each do |link|
|
104
|
+
links_kobetu << $1 if link.value =~ /(http:\/\/youtubeanisoku.*)/
|
105
|
+
end
|
106
|
+
|
107
|
+
# make job for each links_kobetu
|
108
|
+
links_kobetu.each do |link|
|
109
|
+
job = MyJobAnisoku.new(
|
110
|
+
:url => link,
|
111
|
+
:status => :kobetu,
|
112
|
+
:machine => @a[:machine]
|
113
|
+
)
|
114
|
+
@a[:machine].retry job
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
#access say-move and make video job
|
119
|
+
def third
|
120
|
+
#sm has title and url
|
121
|
+
sm = { :title => @a[:title],:url => @a[:url]}
|
122
|
+
@agent.get(sm[:url])
|
123
|
+
set = @agent.page/"/html/body/div/div[2]/div[7]/div[2]/input/@value"
|
124
|
+
if set[0]
|
125
|
+
sm[:videourl] = set[0].value
|
126
|
+
end
|
127
|
+
|
128
|
+
job = MyJobAnisoku.new(
|
129
|
+
:url => sm[:videourl],
|
130
|
+
:title => sm[:title],
|
131
|
+
:status => :video,
|
132
|
+
:machine => @a[:machine]
|
133
|
+
)
|
134
|
+
@a[:machine].retry job
|
135
|
+
end
|
136
|
+
|
137
|
+
#access say-move and make video job
|
138
|
+
def kobetu
|
139
|
+
@agent.get @a[:url]
|
140
|
+
nodeset = @agent.page/"/html/body/table/tr[2]/td/table/tr/td[2]/div[4]/div[2]"
|
141
|
+
begin
|
142
|
+
titles = nodeset[0].inner_text.gsub(' ','').gsub(' ','').
|
143
|
+
gsub('「Daum」|','').
|
144
|
+
gsub('【Yahoo!】','').
|
145
|
+
gsub('veoh','').
|
146
|
+
gsub('SM|','').
|
147
|
+
gsub('|','').
|
148
|
+
split("\r\n").
|
149
|
+
select{|e| $1 if e=~/(第.*)/ }.
|
150
|
+
map{|k| k =~ /(第(\d{1,2}).*)/; { :episode => $2, :title => $1} }
|
151
|
+
titles.reverse!
|
152
|
+
|
153
|
+
|
154
|
+
_tt = @agent.page.title.gsub(' ★ You Tube アニ速 ★','')
|
155
|
+
|
156
|
+
#hard coding for adjust fetch limit
|
157
|
+
title = _tt + titles.shift[:title].to_s
|
158
|
+
title2 = _tt + titles.shift[:title].to_s
|
159
|
+
title3 = _tt + titles.shift[:title].to_s
|
160
|
+
title4 = _tt + titles.shift[:title].to_s
|
161
|
+
title5 = _tt + titles.shift[:title].to_s
|
162
|
+
|
163
|
+
rescue => ex
|
164
|
+
p ex
|
165
|
+
return
|
166
|
+
end
|
167
|
+
nodeset_vs = @agent.page/"/html/body/table/tr[2]/td/table/tr/td[2]/div[4]/div[2]/a/@href"
|
168
|
+
_dd = []
|
169
|
+
nodeset_vs.each do |va|
|
170
|
+
_dd << $1 if va.value =~ /(http:\/\/say-move\.org\/comeplay\.php.*)/
|
171
|
+
end
|
172
|
+
_dd.reverse!
|
173
|
+
|
174
|
+
#hard coding for adjust fetch limit
|
175
|
+
url = _dd.shift
|
176
|
+
url2 = _dd.shift
|
177
|
+
url3 = _dd.shift
|
178
|
+
url4 = _dd.shift
|
179
|
+
url5 = _dd.shift
|
180
|
+
|
181
|
+
#hard coding for adjust fetch limit
|
182
|
+
unless url.nil?
|
183
|
+
job = MyJobAnisoku.new(
|
184
|
+
:url => url,
|
185
|
+
:title => title,
|
186
|
+
:status => :third,
|
187
|
+
:machine => @a[:machine]
|
188
|
+
)
|
189
|
+
@a[:machine].retry job
|
190
|
+
end
|
191
|
+
|
192
|
+
unless url2.nil?
|
193
|
+
job = MyJobAnisoku.new(
|
194
|
+
:url => url2,
|
195
|
+
:title => title2,
|
196
|
+
:status => :third,
|
197
|
+
:machine => @a[:machine]
|
198
|
+
)
|
199
|
+
@a[:machine].retry job
|
200
|
+
end
|
201
|
+
|
202
|
+
unless url3.nil?
|
203
|
+
job = MyJobAnisoku.new(
|
204
|
+
:url => url3,
|
205
|
+
:title => title3,
|
206
|
+
:status => :third,
|
207
|
+
:machine => @a[:machine]
|
208
|
+
)
|
209
|
+
@a[:machine].retry job
|
210
|
+
end
|
211
|
+
|
212
|
+
unless url4.nil?
|
213
|
+
job = MyJobAnisoku.new(
|
214
|
+
:url => url4,
|
215
|
+
:title => title4,
|
216
|
+
:status => :third,
|
217
|
+
:machine => @a[:machine]
|
218
|
+
)
|
219
|
+
@a[:machine].retry job
|
220
|
+
end
|
221
|
+
|
222
|
+
unless url5.nil?
|
223
|
+
job = MyJobAnisoku.new(
|
224
|
+
:url => url5,
|
225
|
+
:title => title5,
|
226
|
+
:status => :third,
|
227
|
+
:machine => @a[:machine]
|
228
|
+
)
|
229
|
+
@a[:machine].retry job
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
#fetch video
|
235
|
+
def video
|
236
|
+
# save video directory is supplied by machine.
|
237
|
+
savedir = @a[:machine].savedir
|
238
|
+
Dir.chdir savedir
|
239
|
+
filename = "#{@a[:title]}.mp4"
|
240
|
+
savepath = "#{savedir}/#{filename}"
|
241
|
+
|
242
|
+
puts "Fetching ".green.bold + savepath
|
243
|
+
|
244
|
+
if File.exist?(savepath) && File.size(savepath) > 1024 * 1024 * 3
|
245
|
+
puts "File Already Saved ".yellow.bold + savepath
|
246
|
+
return
|
247
|
+
else
|
248
|
+
MyLogger.ln "Fetch Attempt Start ".green.bold + savepath
|
249
|
+
end
|
250
|
+
# use curl command
|
251
|
+
command = "curl -# -L -R -o '#{filename}' '#{@a[:url].host}#{@a[:url].path}'"
|
252
|
+
system command
|
253
|
+
=begin
|
254
|
+
consume too much memory!!!!
|
255
|
+
begin
|
256
|
+
@http = EventMachine::Protocols::HttpClient.request(
|
257
|
+
:host => @a[:url].host,
|
258
|
+
:port => @a[:url].port,
|
259
|
+
:request => @a[:url].path
|
260
|
+
)
|
261
|
+
rescue => ex
|
262
|
+
p ex
|
263
|
+
return
|
264
|
+
end
|
265
|
+
|
266
|
+
@http.callback {|response|
|
267
|
+
if response[:status] == 200
|
268
|
+
puts "# 200".green
|
269
|
+
open(savepath,"wb") do |io|
|
270
|
+
io.write response[:content]
|
271
|
+
end
|
272
|
+
puts "saved:".green.bold + "/Users/seijiro/Desktop/#{@a[:title]}.mp4"
|
273
|
+
elsif response[:status] == 302
|
274
|
+
puts "302".red.bold
|
275
|
+
location = ""
|
276
|
+
response[:headers].each do |elem|
|
277
|
+
p elem
|
278
|
+
location = $1 if elem =~ /Location:\s(.*)/
|
279
|
+
end
|
280
|
+
job = MyJobAnisoku.new(
|
281
|
+
:url => location,
|
282
|
+
:title => @a[:title],
|
283
|
+
:status => :video,
|
284
|
+
:machine => @a[:machine]
|
285
|
+
)
|
286
|
+
@a[:machine].retry job
|
287
|
+
else
|
288
|
+
puts response[:status].to_s.red.bold
|
289
|
+
puts response[:headers].to_s.red.bold
|
290
|
+
# raise "HTTP Status Error"
|
291
|
+
end
|
292
|
+
}
|
293
|
+
=end
|
294
|
+
end
|
295
|
+
|
296
|
+
# run in thread
|
297
|
+
def run
|
298
|
+
t = Thread.new do
|
299
|
+
case @a[:status]
|
300
|
+
when :new then
|
301
|
+
tokkakari
|
302
|
+
when :second then
|
303
|
+
second
|
304
|
+
when :kobetu then
|
305
|
+
kobetu
|
306
|
+
when :third then
|
307
|
+
third
|
308
|
+
when :video then
|
309
|
+
video
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
end
|
315
|
+
|
316
|
+
# Module of Machine
|
317
|
+
# this class has queue of jobs
|
318
|
+
# controll jobs and run jobs
|
319
|
+
module MyMachine
|
320
|
+
attr_accessor :queue
|
321
|
+
|
322
|
+
def initialize
|
323
|
+
require 'thread'
|
324
|
+
@queue = Queue.new
|
325
|
+
end
|
326
|
+
|
327
|
+
def setup
|
328
|
+
setupjobs
|
329
|
+
setupmachine
|
330
|
+
end
|
331
|
+
|
332
|
+
def go
|
333
|
+
puts "You need write the go method!"
|
334
|
+
end
|
335
|
+
|
336
|
+
def retry(job)
|
337
|
+
@queue.push job
|
338
|
+
end
|
339
|
+
|
340
|
+
private
|
341
|
+
|
342
|
+
def setupjobs
|
343
|
+
puts "You need write the setupjobs method!"
|
344
|
+
end
|
345
|
+
|
346
|
+
def setupmachine
|
347
|
+
puts "You need write the setupmachine method!"
|
348
|
+
end
|
349
|
+
|
350
|
+
end
|
351
|
+
|
352
|
+
#
|
353
|
+
# Class of Machine by EventMachine
|
354
|
+
# this class controll jobs for Anisoku
|
355
|
+
# @example
|
356
|
+
# machine = MyMachineAnisoku.new("YourVideoSaveDir")
|
357
|
+
# machine.setup
|
358
|
+
# machine.go
|
359
|
+
#
|
360
|
+
class MyMachineAnisoku
|
361
|
+
include MyMachine
|
362
|
+
attr_accessor :savedir
|
363
|
+
|
364
|
+
# set video save dir
|
365
|
+
# @param [Hash] args
|
366
|
+
# @option args [String] :savedir save dir
|
367
|
+
# default "${ENV['HOME']}/Desktop/video"
|
368
|
+
def initialize(args={ })
|
369
|
+
super()
|
370
|
+
args[:savedir] ||= "${ENV['HOME']}/Desktop/video"
|
371
|
+
@savedir = args[:savedir]
|
372
|
+
begin
|
373
|
+
Dir::mkdir(@savedir, 0777)
|
374
|
+
rescue => ex
|
375
|
+
warn ex
|
376
|
+
end
|
377
|
+
require 'rubygems'
|
378
|
+
require 'eventmachine'
|
379
|
+
# @gaman controll eventmachine end
|
380
|
+
@gaman = 0
|
381
|
+
end
|
382
|
+
|
383
|
+
# macine go!!
|
384
|
+
def go
|
385
|
+
EM.run do
|
386
|
+
EM.add_periodic_timer(0.00001) do
|
387
|
+
# print "loop".green
|
388
|
+
EM.stop if should_stop_machine?
|
389
|
+
@queue.pop.run unless @queue.empty?
|
390
|
+
end
|
391
|
+
end
|
392
|
+
puts "End of fetch".green.bold
|
393
|
+
end
|
394
|
+
|
395
|
+
private
|
396
|
+
|
397
|
+
# setup jobs
|
398
|
+
def setupjobs
|
399
|
+
ajob = MyJobAnisoku.new(
|
400
|
+
:machine => self
|
401
|
+
)
|
402
|
+
@queue.push ajob
|
403
|
+
end
|
404
|
+
|
405
|
+
# should stop machine or not
|
406
|
+
def should_stop_machine?
|
407
|
+
@gaman += 1 if @queue.empty?
|
408
|
+
print @gaman
|
409
|
+
return @queue.empty? && @gaman > 500
|
410
|
+
end
|
411
|
+
end
|
data/my-lib.gemspec
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{my-lib}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{modeverv}]
|
12
|
+
s.date = %q{2011-08-31}
|
13
|
+
s.description = %q{longer description of your gem}
|
14
|
+
s.email = %q{modeverv@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/my-lib.rb",
|
29
|
+
"my-lib.gemspec",
|
30
|
+
"spec/my-lib_spec.rb",
|
31
|
+
"spec/spec_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/modeverv/my-lib}
|
34
|
+
s.licenses = [%q{MIT}]
|
35
|
+
s.require_paths = [%q{lib}]
|
36
|
+
s.rubygems_version = %q{1.8.6}
|
37
|
+
s.summary = %q{one-line summary of your gem}
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<term-ansicolor>, [">= 0"])
|
44
|
+
s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
|
45
|
+
s.add_runtime_dependency(%q<mechanize>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<rspec>, ["> 2.3.0"])
|
47
|
+
s.add_development_dependency(%q<yard>, ["> 0.6.0"])
|
48
|
+
s.add_development_dependency(%q<bundler>, ["> 1.0.0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<term-ansicolor>, [">= 0"])
|
53
|
+
s.add_dependency(%q<eventmachine>, [">= 0"])
|
54
|
+
s.add_dependency(%q<mechanize>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rspec>, ["> 2.3.0"])
|
56
|
+
s.add_dependency(%q<yard>, ["> 0.6.0"])
|
57
|
+
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
59
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<term-ansicolor>, [">= 0"])
|
63
|
+
s.add_dependency(%q<eventmachine>, [">= 0"])
|
64
|
+
s.add_dependency(%q<mechanize>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rspec>, ["> 2.3.0"])
|
66
|
+
s.add_dependency(%q<yard>, ["> 0.6.0"])
|
67
|
+
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
data/spec/my-lib_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "MyLib" do
|
4
|
+
it "fails" do
|
5
|
+
# fail "hey buddy, you should probably rename this file and start specing for real"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "success" do
|
9
|
+
####################################################
|
10
|
+
machine = MyMachineAnisoku.new(:savepath => "/Users/seijiro/Desktop/video")
|
11
|
+
machine.setup
|
12
|
+
# machine.go
|
13
|
+
end
|
14
|
+
|
15
|
+
it "success get syslog" do
|
16
|
+
MyLogger.ln "notice"
|
17
|
+
MyLogger.lw "warn"
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'my-lib'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: my-lib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- modeverv
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-31 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: term-ansicolor
|
16
|
+
requirement: &2154227140 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2154227140
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: eventmachine
|
27
|
+
requirement: &2154226420 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2154226420
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mechanize
|
38
|
+
requirement: &2154225780 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2154225780
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &2154225140 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>'
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.3.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2154225140
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: yard
|
60
|
+
requirement: &2154224460 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>'
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.6.0
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2154224460
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: &2154223800 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>'
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.0.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2154223800
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: jeweler
|
82
|
+
requirement: &2154223100 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2154223100
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rcov
|
93
|
+
requirement: &2154222440 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *2154222440
|
102
|
+
description: longer description of your gem
|
103
|
+
email: modeverv@gmail.com
|
104
|
+
executables: []
|
105
|
+
extensions: []
|
106
|
+
extra_rdoc_files:
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.rdoc
|
109
|
+
files:
|
110
|
+
- .document
|
111
|
+
- .rspec
|
112
|
+
- Gemfile
|
113
|
+
- Gemfile.lock
|
114
|
+
- LICENSE.txt
|
115
|
+
- README.rdoc
|
116
|
+
- Rakefile
|
117
|
+
- VERSION
|
118
|
+
- lib/my-lib.rb
|
119
|
+
- my-lib.gemspec
|
120
|
+
- spec/my-lib_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: http://github.com/modeverv/my-lib
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: -2173036099495571090
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 1.8.6
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: one-line summary of your gem
|
150
|
+
test_files: []
|