my-lib 0.0.1.1 → 0.0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +9 -0
- data/TAGS +66 -0
- data/VERSION +1 -1
- data/lib/1.rb +4 -0
- data/lib/lib/anisoku.rb +292 -0
- data/lib/lib/job.rb +212 -0
- data/lib/lib/machine.rb +43 -0
- data/lib/lib/myat.rb +53 -0
- data/lib/lib/myconfig.rb +41 -0
- data/lib/lib/mydb.rb +57 -0
- data/lib/lib/mygcal.rb +76 -0
- data/lib/lib/mylogger.rb +39 -0
- data/lib/lib/myobject.rb +13 -0
- data/lib/lib/mypusher.rb +85 -0
- data/lib/lib/runpersec.rb +67 -0
- data/lib/my-lib.rb +35 -433
- data/my-lib.gemspec +21 -5
- data/spec/my-lib_spec.rb +24 -0
- data/spec/spec_helper.rb +29 -0
- metadata +54 -22
- data/lib/dev.rb +0 -363
- data/lib/opt-parse.rb +0 -0
- data/spec/opt-parse_spec.rb +0 -15
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -4,6 +4,11 @@ GEM
|
|
4
4
|
diff-lcs (1.1.3)
|
5
5
|
eventmachine (0.12.10)
|
6
6
|
git (1.2.5)
|
7
|
+
guard (0.6.3)
|
8
|
+
thor (~> 0.14.6)
|
9
|
+
guard-spork (0.2.1)
|
10
|
+
guard (>= 0.2.2)
|
11
|
+
spork (>= 0.8.4)
|
7
12
|
jeweler (1.6.4)
|
8
13
|
bundler (~> 1.0)
|
9
14
|
git (>= 1.2.5)
|
@@ -26,7 +31,9 @@ GEM
|
|
26
31
|
rspec-expectations (2.6.0)
|
27
32
|
diff-lcs (~> 1.1.2)
|
28
33
|
rspec-mocks (2.6.0)
|
34
|
+
spork (0.8.5)
|
29
35
|
term-ansicolor (1.0.6)
|
36
|
+
thor (0.14.6)
|
30
37
|
webrobots (0.0.11)
|
31
38
|
nokogiri (>= 1.4.4)
|
32
39
|
yard (0.7.2)
|
@@ -37,6 +44,8 @@ PLATFORMS
|
|
37
44
|
DEPENDENCIES
|
38
45
|
bundler (> 1.0.0)
|
39
46
|
eventmachine
|
47
|
+
guard
|
48
|
+
guard-spork
|
40
49
|
jeweler
|
41
50
|
mechanize
|
42
51
|
rcov
|
data/TAGS
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
(null),18
|
3
|
+
def hogehoge2,6
|
4
|
+
|
5
|
+
lib/dev.rb,1335
|
6
|
+
class MyObjectMyObject24,488
|
7
|
+
def self.myrequiremyrequire25,503
|
8
|
+
class MyConfigMyConfig33,665
|
9
|
+
def self.getget35,718
|
10
|
+
def self.readread42,795
|
11
|
+
module RunPerSecModuleRunPerSecModule63,1245
|
12
|
+
def run(sec)run71,1556
|
13
|
+
def init_run_per_sec_moduleinit_run_per_sec_module86,1798
|
14
|
+
def stop_runstop_run91,1885
|
15
|
+
def before_run_loopbefore_run_loop96,2014
|
16
|
+
def loop_hook_preloop_hook_pre100,2103
|
17
|
+
def main_loopmain_loop104,2181
|
18
|
+
def loop_hook_postloop_hook_post108,2269
|
19
|
+
def after_run_loopafter_run_loop112,2373
|
20
|
+
module MyDBModuleMyDBModule139,2874
|
21
|
+
def set_my_dbset_my_db147,2981
|
22
|
+
def insert_DB(key='test_app',value='')insert_DB168,3575
|
23
|
+
module MyPusherModuleMyPusherModule195,4206
|
24
|
+
def set_my_pusherset_my_pusher201,4330
|
25
|
+
def push_pusher(app_name='test_app',data='test')push_pusher216,4701
|
26
|
+
module MyGCalModuleMyGCalModule246,5321
|
27
|
+
def gcal_readgcal_read249,5403
|
28
|
+
def gcal_write(eventdata)gcal_write256,5509
|
29
|
+
def gcal_parse_2_jobsgcal_parse_2_jobs269,5858
|
30
|
+
def gcal_checkout(event)gcal_checkout290,6403
|
31
|
+
def serviceservice297,6540
|
32
|
+
module MyAtModuleMyAtModule323,7102
|
33
|
+
def initializeinitialize324,7120
|
34
|
+
def gcaljobs_2_atgcaljobs_2_at328,7180
|
35
|
+
def jobs2at(job)jobs2at333,7266
|
36
|
+
def _at_scriptpath(job)_at_scriptpath346,7600
|
37
|
+
def _at_command(job)_at_command350,7716
|
38
|
+
|
39
|
+
lib/my-lib.rb,924
|
40
|
+
class StringString6,89
|
41
|
+
class MyLoggerMyLogger16,267
|
42
|
+
def self.ln(message)ln22,367
|
43
|
+
def self.lw(message)lw30,540
|
44
|
+
def self.beforebefore38,717
|
45
|
+
def self.afterafter44,843
|
46
|
+
class MyJobAnisokuMyJobAnisoku66,1426
|
47
|
+
def initialize(args = { })initialize70,1471
|
48
|
+
def tokkakaritokkakari84,1872
|
49
|
+
def secondsecond103,2321
|
50
|
+
def thirdthird124,2884
|
51
|
+
def kobetukobetu143,3352
|
52
|
+
def videovideo240,5755
|
53
|
+
def runrun302,7444
|
54
|
+
module MyMachineMyMachine325,7804
|
55
|
+
def initializeinitialize331,7871
|
56
|
+
def setupsetup336,7941
|
57
|
+
def gogo341,7991
|
58
|
+
def retry(job)retry345,8048
|
59
|
+
def setupjobssetupjobs351,8103
|
60
|
+
def setupmachinesetupmachine355,8177
|
61
|
+
class MyMachineAnisokuMyMachineAnisoku369,8438
|
62
|
+
def initialize(args={ })initialize381,8764
|
63
|
+
def gogo397,9115
|
64
|
+
def finalize_filesfinalize_files414,9443
|
65
|
+
def setupjobssetupjobs428,9813
|
66
|
+
def should_stop_machine?should_stop_machine?436,9948
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.1.
|
1
|
+
0.0.1.3
|
data/lib/1.rb
ADDED
data/lib/lib/anisoku.rb
ADDED
@@ -0,0 +1,292 @@
|
|
1
|
+
#-*- coding:utf-8 -*-
|
2
|
+
|
3
|
+
#
|
4
|
+
# Job Class for Fetch Anisoku
|
5
|
+
# Function:
|
6
|
+
# access "youtubeanisoku1.blog106.fc2.com" and crawl web site.
|
7
|
+
# find a link to "say-move.org" and access "say-move.org".
|
8
|
+
# finary find video link of Animetion,then fetch video file to your local.
|
9
|
+
# save video directory is supplied by machine.
|
10
|
+
# Notice:
|
11
|
+
# job is automatically generated on after another.
|
12
|
+
# This Class Needs to be handle by Machine Class
|
13
|
+
# @example
|
14
|
+
# # inside machine class
|
15
|
+
# job = MyJobAnisoku.new(
|
16
|
+
# :machine => self
|
17
|
+
# )
|
18
|
+
# job.run
|
19
|
+
#
|
20
|
+
|
21
|
+
class MyJobAnisoku
|
22
|
+
|
23
|
+
Version = "0.0.2"
|
24
|
+
|
25
|
+
def initialize(args = { })
|
26
|
+
require 'rubygems'
|
27
|
+
require 'kconv'
|
28
|
+
require 'mechanize'
|
29
|
+
require 'net/http'
|
30
|
+
@a = args
|
31
|
+
@a[:url] ||= 'http://youtubeanisoku1.blog106.fc2.com/'
|
32
|
+
@a[:url] = URI.parse @a[:url] unless @a[:url].class == URI::HTTP
|
33
|
+
@agent = Mechanize.new
|
34
|
+
@a[:status] ||= :new
|
35
|
+
raise "job have no machine error" unless @a[:machine]
|
36
|
+
end
|
37
|
+
|
38
|
+
# check kousin page
|
39
|
+
def tokkakari
|
40
|
+
print "Tokkakari".yellow
|
41
|
+
@agent.get @a[:url]
|
42
|
+
links_kousins = @agent.page.links_with(:text => /#{"更新状況".toutf8}/)
|
43
|
+
targs = []
|
44
|
+
links_kousins.each do |link|
|
45
|
+
targs << link.uri
|
46
|
+
end
|
47
|
+
targs.each_with_index do |link,i|
|
48
|
+
break if i > 6
|
49
|
+
job = MyJobAnisoku.new(
|
50
|
+
:url => link,
|
51
|
+
:status => :second,
|
52
|
+
:machine => @a[:machine]
|
53
|
+
)
|
54
|
+
@a[:machine].retry job
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
# check shoukai page
|
60
|
+
def second
|
61
|
+
print "Second".yellow
|
62
|
+
@agent.get @a[:url]
|
63
|
+
links_kousin = @agent.page/"/html/body/table/tr[2]/td/table/tr/td[2]/div[4]/ul/li/a/@href"
|
64
|
+
# links_kobetu
|
65
|
+
links_kobetu = []
|
66
|
+
links_kousin.each do |link|
|
67
|
+
links_kobetu << $1 if link.value =~ /(http:\/\/youtubeanisoku.*)/
|
68
|
+
end
|
69
|
+
|
70
|
+
# make job for each links_kobetu
|
71
|
+
links_kobetu.each do |link|
|
72
|
+
job = MyJobAnisoku.new(
|
73
|
+
:url => link,
|
74
|
+
:status => :kobetu,
|
75
|
+
:machine => @a[:machine]
|
76
|
+
)
|
77
|
+
@a[:machine].retry job
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
#access say-move and make video job
|
82
|
+
def kobetu
|
83
|
+
print "Kobetu".yellow
|
84
|
+
@agent.get @a[:url]
|
85
|
+
_tt = @agent.page.title.gsub(' ★ You Tube アニ速 ★','')
|
86
|
+
limit = 5
|
87
|
+
urls = []
|
88
|
+
# acume url
|
89
|
+
nodeset_vs = @agent.page/"/html/body/table/tr[2]/td/table/tr/td[2]/div[4]/div[2]/a/@href"
|
90
|
+
_dd = []
|
91
|
+
|
92
|
+
nodeset_vs.each do |va|
|
93
|
+
_dd << $1 if va.value =~ /(http:\/\/say-move\.org\/comeplay\.php.*)/
|
94
|
+
end
|
95
|
+
_dd.reverse!
|
96
|
+
|
97
|
+
#hard coding for adjust fetch limit
|
98
|
+
_dd.each_with_index do |url,i|
|
99
|
+
break if i > limit
|
100
|
+
urls << url
|
101
|
+
end
|
102
|
+
|
103
|
+
urls.each_with_index do |url,i|
|
104
|
+
job = MyJobAnisoku.new(
|
105
|
+
:url => url,
|
106
|
+
:title => _tt,
|
107
|
+
:status => :third,
|
108
|
+
:machine => @a[:machine]
|
109
|
+
)
|
110
|
+
@a[:machine].retry job
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
#access say-move and make video job
|
115
|
+
def third
|
116
|
+
print "Third".yellow
|
117
|
+
#sm has title and url
|
118
|
+
|
119
|
+
sm = { :title => @a[:title],:url => @a[:url]}
|
120
|
+
# debug fc2 video sm[:url] = "http://say-move.org/comeplay.php?comeid=217953"
|
121
|
+
@agent.get(sm[:url])
|
122
|
+
sm[:title] += @agent.page.title.gsub!('FC2 SayMove!','')
|
123
|
+
set = @agent.page/"/html/body/div/div[2]/div[7]/div[2]/input/@value"
|
124
|
+
if !set.empty?
|
125
|
+
sm[:videourl] = set[0].value
|
126
|
+
else
|
127
|
+
set = @agent.page/"/html/body/div/div[2]/div[3]/object/param[5]/@value"
|
128
|
+
fc2 = set[0].value.split('&')[1].split('=')[1]
|
129
|
+
unless fc2.nil?
|
130
|
+
job = MyJobAnisoku.new(
|
131
|
+
:url => sm[:url],
|
132
|
+
:fc2 => fc2,
|
133
|
+
:title => sm[:title],
|
134
|
+
:status => :fc2,
|
135
|
+
:machine => @a[:machine]
|
136
|
+
)
|
137
|
+
@a[:machine].retry job
|
138
|
+
return
|
139
|
+
else
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
job = MyJobAnisoku.new(
|
144
|
+
:url => sm[:videourl],
|
145
|
+
:title => sm[:title],
|
146
|
+
:status => :video,
|
147
|
+
:machine => @a[:machine]
|
148
|
+
)
|
149
|
+
@a[:machine].retry job
|
150
|
+
end
|
151
|
+
|
152
|
+
def fc2
|
153
|
+
print "fc2".yellow
|
154
|
+
require 'digest'
|
155
|
+
# make md5 with magicword '_gGddgPfeaf_gzyr'
|
156
|
+
url = "http://video.fc2.com/ginfo.php?mimi=#{Digest::MD5.hexdigest(@a[:fc2] + '_gGddgPfeaf_gzyr')}&v=#{@a[:fc2]}&upid=#{@a[:fc2]}&otag=1"
|
157
|
+
url = `curl -# -L -R "#{url}"`
|
158
|
+
url = url.split('&')[0].split('=')[1] + '?' + url.split('&')[1]
|
159
|
+
puts url.red.bold
|
160
|
+
job = MyJobAnisoku.new(
|
161
|
+
:url => url,
|
162
|
+
:title => @a[:title],
|
163
|
+
:status => :video,
|
164
|
+
:machine => @a[:machine]
|
165
|
+
)
|
166
|
+
@a[:machine].retry job
|
167
|
+
end
|
168
|
+
|
169
|
+
#fetch video
|
170
|
+
def video
|
171
|
+
print "video".yellow
|
172
|
+
# save video directory is supplied by machine.
|
173
|
+
savedir = @a[:machine].savedir
|
174
|
+
Dir.chdir savedir
|
175
|
+
filename = "#{@a[:title]}.mp4"
|
176
|
+
savepath = "#{savedir}/#{filename}"
|
177
|
+
# check fetch candidate had been already saved?
|
178
|
+
if File.exist?(savepath) && File.size(savepath) > 1024 * 1024 * 3
|
179
|
+
puts "File Already Saved ".yellow.bold + savepath
|
180
|
+
return
|
181
|
+
else
|
182
|
+
puts "Fetching ".green.bold + savepath
|
183
|
+
MyLogger.ln "Fetch Attempt Start ".green.bold + savepath
|
184
|
+
end
|
185
|
+
|
186
|
+
# use curl command
|
187
|
+
# no need UA...
|
188
|
+
# command = "curl -# -L -R -o '#{filename}' 'http://#{@a[:url].host}#{@a[:url].path}?#{@a[:url].query}' --user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:9.0a1) Gecko/20110901 Firefox/9.0a1'"
|
189
|
+
command = "curl -# -L -R -o '#{filename}' 'http://#{@a[:url].host}#{@a[:url].path}?#{@a[:url].query}' "
|
190
|
+
|
191
|
+
p command
|
192
|
+
system command
|
193
|
+
end
|
194
|
+
|
195
|
+
# run in thread
|
196
|
+
def run
|
197
|
+
t = Thread.new do
|
198
|
+
case @a[:status]
|
199
|
+
when :new then
|
200
|
+
tokkakari
|
201
|
+
when :second then
|
202
|
+
second
|
203
|
+
when :kobetu then
|
204
|
+
kobetu
|
205
|
+
when :third then
|
206
|
+
third
|
207
|
+
when :fc2 then
|
208
|
+
fc2
|
209
|
+
when :video then
|
210
|
+
video
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
#
|
220
|
+
# Class of Machine by EventMachine.
|
221
|
+
# this class controll jobs for Anisoku
|
222
|
+
# @example
|
223
|
+
# machine = MyMachineAnisoku.new("YourVideoSaveDir")
|
224
|
+
# machine.setup
|
225
|
+
# machine.go
|
226
|
+
#
|
227
|
+
class MyMachineAnisoku
|
228
|
+
include MyMachine
|
229
|
+
|
230
|
+
Version = "0.0.1"
|
231
|
+
|
232
|
+
# directory of save video files default "#{ENV['HOME']}/Desktop/video"
|
233
|
+
attr_accessor :savedir
|
234
|
+
|
235
|
+
# set video save dir
|
236
|
+
# @param [Hash] args
|
237
|
+
# @option args [String] :savedir save dir
|
238
|
+
# default "#{ENV['HOME']}/Desktop/video"
|
239
|
+
def initialize(args={ })
|
240
|
+
super()
|
241
|
+
args[:savedir] ||= "#{ENV['HOME']}/Desktop/video2"
|
242
|
+
@savedir = args[:savedir]
|
243
|
+
begin
|
244
|
+
Dir::mkdir(@savedir, 0777)
|
245
|
+
rescue => ex
|
246
|
+
warn ex
|
247
|
+
end
|
248
|
+
require 'rubygems'
|
249
|
+
require 'eventmachine'
|
250
|
+
# @gaman controll eventmachine end
|
251
|
+
@gaman = 0
|
252
|
+
end
|
253
|
+
|
254
|
+
# machine go to run eventmachine
|
255
|
+
def go
|
256
|
+
EM.run do
|
257
|
+
EM.add_periodic_timer(0.00001) do
|
258
|
+
# print "loop".green
|
259
|
+
if should_stop_machine?
|
260
|
+
finalize_files
|
261
|
+
EM.stop
|
262
|
+
end
|
263
|
+
@queue.pop.run unless @queue.empty?
|
264
|
+
end
|
265
|
+
end
|
266
|
+
puts "End of fetch".green.bold
|
267
|
+
end
|
268
|
+
|
269
|
+
|
270
|
+
# delete tiny fail files
|
271
|
+
def finalize_files
|
272
|
+
command = "find #{@savedir} -size -1000k -type f -print0| xargs -0 rm -v "
|
273
|
+
exec(command)
|
274
|
+
end
|
275
|
+
|
276
|
+
private
|
277
|
+
|
278
|
+
# setup jobs
|
279
|
+
def setupjobs
|
280
|
+
ajob = MyJobAnisoku.new(
|
281
|
+
:machine => self
|
282
|
+
)
|
283
|
+
@queue.push ajob
|
284
|
+
end
|
285
|
+
|
286
|
+
# should stop machine or not
|
287
|
+
def should_stop_machine?
|
288
|
+
@gaman += 1 if @queue.empty?
|
289
|
+
print @gaman
|
290
|
+
return @queue.empty? && @gaman > 1500
|
291
|
+
end
|
292
|
+
end
|
data/lib/lib/job.rb
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
#-*- coding:utf-8 -*-
|
2
|
+
# Job Class for Fetch Anisoku
|
3
|
+
# Function:
|
4
|
+
# access "youtubeanisoku1.blog106.fc2.com" and crawl web site.
|
5
|
+
# find a link to "say-move.org" and access "say-move.org".
|
6
|
+
# finary find video link of Animetion,then fetch video file to your local.
|
7
|
+
# save video directory is supplied by machine.
|
8
|
+
# Notice:
|
9
|
+
# job is automatically generated on after another.
|
10
|
+
# This Class Needs to be handle by Machine Class
|
11
|
+
# @example
|
12
|
+
# # inside machine class
|
13
|
+
# job = MyJobAnisoku.new(
|
14
|
+
# :machine => self
|
15
|
+
# )
|
16
|
+
# job.run
|
17
|
+
#
|
18
|
+
class MyJobAnisoku
|
19
|
+
|
20
|
+
Version = "0.0.2"
|
21
|
+
|
22
|
+
def initialize(args = { })
|
23
|
+
require 'rubygems'
|
24
|
+
require 'kconv'
|
25
|
+
require 'mechanize'
|
26
|
+
require 'net/http'
|
27
|
+
@a = args
|
28
|
+
@a[:url] ||= 'http://youtubeanisoku1.blog106.fc2.com/'
|
29
|
+
@a[:url] = URI.parse @a[:url] unless @a[:url].class == URI::HTTP
|
30
|
+
@agent = Mechanize.new
|
31
|
+
@a[:status] ||= :new
|
32
|
+
raise "job have no machine error" unless @a[:machine]
|
33
|
+
end
|
34
|
+
|
35
|
+
# check kousin page
|
36
|
+
def tokkakari
|
37
|
+
print "Tokkakari".yellow
|
38
|
+
@agent.get @a[:url]
|
39
|
+
links_kousins = @agent.page.links_with(:text => /#{"更新状況".toutf8}/)
|
40
|
+
targs = []
|
41
|
+
links_kousins.each do |link|
|
42
|
+
targs << link.uri
|
43
|
+
end
|
44
|
+
targs.each_with_index do |link,i|
|
45
|
+
break if i > 6
|
46
|
+
job = MyJobAnisoku.new(
|
47
|
+
:url => link,
|
48
|
+
:status => :second,
|
49
|
+
:machine => @a[:machine]
|
50
|
+
)
|
51
|
+
@a[:machine].retry job
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
# check shoukai page
|
57
|
+
def second
|
58
|
+
print "Second".yellow
|
59
|
+
@agent.get @a[:url]
|
60
|
+
links_kousin = @agent.page/"/html/body/table/tr[2]/td/table/tr/td[2]/div[4]/ul/li/a/@href"
|
61
|
+
# links_kobetu
|
62
|
+
links_kobetu = []
|
63
|
+
links_kousin.each do |link|
|
64
|
+
links_kobetu << $1 if link.value =~ /(http:\/\/youtubeanisoku.*)/
|
65
|
+
end
|
66
|
+
|
67
|
+
# make job for each links_kobetu
|
68
|
+
links_kobetu.each do |link|
|
69
|
+
job = MyJobAnisoku.new(
|
70
|
+
:url => link,
|
71
|
+
:status => :kobetu,
|
72
|
+
:machine => @a[:machine]
|
73
|
+
)
|
74
|
+
@a[:machine].retry job
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
#access say-move and make video job
|
79
|
+
def kobetu
|
80
|
+
print "Kobetu".yellow
|
81
|
+
@agent.get @a[:url]
|
82
|
+
_tt = @agent.page.title.gsub(' ★ You Tube アニ速 ★','')
|
83
|
+
limit = 5
|
84
|
+
urls = []
|
85
|
+
# acume url
|
86
|
+
nodeset_vs = @agent.page/"/html/body/table/tr[2]/td/table/tr/td[2]/div[4]/div[2]/a/@href"
|
87
|
+
_dd = []
|
88
|
+
|
89
|
+
nodeset_vs.each do |va|
|
90
|
+
_dd << $1 if va.value =~ /(http:\/\/say-move\.org\/comeplay\.php.*)/
|
91
|
+
end
|
92
|
+
_dd.reverse!
|
93
|
+
|
94
|
+
#hard coding for adjust fetch limit
|
95
|
+
_dd.each_with_index do |url,i|
|
96
|
+
break if i > limit
|
97
|
+
urls << url
|
98
|
+
end
|
99
|
+
|
100
|
+
urls.each_with_index do |url,i|
|
101
|
+
job = MyJobAnisoku.new(
|
102
|
+
:url => url,
|
103
|
+
:title => _tt,
|
104
|
+
:status => :third,
|
105
|
+
:machine => @a[:machine]
|
106
|
+
)
|
107
|
+
@a[:machine].retry job
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
#access say-move and make video job
|
112
|
+
def third
|
113
|
+
print "Third".yellow
|
114
|
+
#sm has title and url
|
115
|
+
|
116
|
+
sm = { :title => @a[:title],:url => @a[:url]}
|
117
|
+
# debug fc2 video sm[:url] = "http://say-move.org/comeplay.php?comeid=217953"
|
118
|
+
@agent.get(sm[:url])
|
119
|
+
sm[:title] += @agent.page.title.gsub!('FC2 SayMove!','')
|
120
|
+
set = @agent.page/"/html/body/div/div[2]/div[7]/div[2]/input/@value"
|
121
|
+
if !set.empty?
|
122
|
+
sm[:videourl] = set[0].value
|
123
|
+
else
|
124
|
+
set = @agent.page/"/html/body/div/div[2]/div[3]/object/param[5]/@value"
|
125
|
+
fc2 = set[0].value.split('&')[1].split('=')[1]
|
126
|
+
unless fc2.nil?
|
127
|
+
job = MyJobAnisoku.new(
|
128
|
+
:url => sm[:url],
|
129
|
+
:fc2 => fc2,
|
130
|
+
:title => sm[:title],
|
131
|
+
:status => :fc2,
|
132
|
+
:machine => @a[:machine]
|
133
|
+
)
|
134
|
+
@a[:machine].retry job
|
135
|
+
return
|
136
|
+
else
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
job = MyJobAnisoku.new(
|
141
|
+
:url => sm[:videourl],
|
142
|
+
:title => sm[:title],
|
143
|
+
:status => :video,
|
144
|
+
:machine => @a[:machine]
|
145
|
+
)
|
146
|
+
@a[:machine].retry job
|
147
|
+
end
|
148
|
+
|
149
|
+
def fc2
|
150
|
+
print "fc2".yellow
|
151
|
+
require 'digest'
|
152
|
+
# make md5 with magicword '_gGddgPfeaf_gzyr'
|
153
|
+
url = "http://video.fc2.com/ginfo.php?mimi=#{Digest::MD5.hexdigest(@a[:fc2] + '_gGddgPfeaf_gzyr')}&v=#{@a[:fc2]}&upid=#{@a[:fc2]}&otag=1"
|
154
|
+
url = `curl -# -L -R "#{url}"`
|
155
|
+
url = url.split('&')[0].split('=')[1] + '?' + url.split('&')[1]
|
156
|
+
puts url.red.bold
|
157
|
+
job = MyJobAnisoku.new(
|
158
|
+
:url => url,
|
159
|
+
:title => @a[:title],
|
160
|
+
:status => :video,
|
161
|
+
:machine => @a[:machine]
|
162
|
+
)
|
163
|
+
@a[:machine].retry job
|
164
|
+
end
|
165
|
+
|
166
|
+
#fetch video
|
167
|
+
def video
|
168
|
+
print "video".yellow
|
169
|
+
# save video directory is supplied by machine.
|
170
|
+
savedir = @a[:machine].savedir
|
171
|
+
Dir.chdir savedir
|
172
|
+
filename = "#{@a[:title]}.mp4"
|
173
|
+
savepath = "#{savedir}/#{filename}"
|
174
|
+
# check fetch candidate had been already saved?
|
175
|
+
if File.exist?(savepath) && File.size(savepath) > 1024 * 1024 * 3
|
176
|
+
puts "File Already Saved ".yellow.bold + savepath
|
177
|
+
return
|
178
|
+
else
|
179
|
+
puts "Fetching ".green.bold + savepath
|
180
|
+
MyLogger.ln "Fetch Attempt Start ".green.bold + savepath
|
181
|
+
end
|
182
|
+
|
183
|
+
# use curl command
|
184
|
+
# no need UA...
|
185
|
+
# command = "curl -# -L -R -o '#{filename}' 'http://#{@a[:url].host}#{@a[:url].path}?#{@a[:url].query}' --user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:9.0a1) Gecko/20110901 Firefox/9.0a1'"
|
186
|
+
command = "curl -# -L -R -o '#{filename}' 'http://#{@a[:url].host}#{@a[:url].path}?#{@a[:url].query}' "
|
187
|
+
|
188
|
+
p command
|
189
|
+
system command
|
190
|
+
end
|
191
|
+
|
192
|
+
# run in thread
|
193
|
+
def run
|
194
|
+
t = Thread.new do
|
195
|
+
case @a[:status]
|
196
|
+
when :new then
|
197
|
+
tokkakari
|
198
|
+
when :second then
|
199
|
+
second
|
200
|
+
when :kobetu then
|
201
|
+
kobetu
|
202
|
+
when :third then
|
203
|
+
third
|
204
|
+
when :fc2 then
|
205
|
+
fc2
|
206
|
+
when :video then
|
207
|
+
video
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|