Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
mycard
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
syntax_j
mycard
Commits
e783bb9d
Commit
e783bb9d
authored
Sep 16, 2013
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
9b40d56c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
13 deletions
+24
-13
main.rb
main.rb
+24
-13
No files found.
main.rb
View file @
e783bb9d
...
...
@@ -213,12 +213,12 @@ begin
def
batch_download
(
main_url
,
files
,
content_type
=
nil
)
connections
=
{}
retried
=
[
0
]
#pass by reference
[
1
*
100
,
files
.
size
].
min
.
times
{
do_download
(
main_url
,
files
,
content_type
,
retried
,
connections
)
}
count
=
{
total:
files
.
size
,
error:
0
}
[
1
0
*
100
,
files
.
size
].
min
.
times
{
do_download
(
main_url
,
files
,
content_type
,
count
,
connections
)
}
end
def
do_download
(
main_url
,
files
,
content_type
,
retried
,
connections
)
if
connections
.
size
<
1
def
do_download
(
main_url
,
files
,
content_type
,
count
,
connections
)
if
connections
.
size
<
1
0
connection
=
EventMachine
::
HttpRequest
.
new
(
main_url
)
connections
[
connection
]
=
0
else
...
...
@@ -232,15 +232,13 @@ begin
remote_path
,
local_path
=
files
.
shift
connections
[
connection
]
+=
1
connection
.
get
(
path:
remote_path
,
keepalive:
connections
[
connection
]
!=
100
).
callback
{
|
http
|
puts
local_path
retried
[
0
]
=
0
puts
File
.
basename
local_path
count
[
:error
]
=
0
count
[
:total
]
-=
1
if
http
.
response_header
[
'CONNECTION'
]
!=
'keep-alive'
connection
.
close
connections
.
delete
(
connection
)
do_download
(
main_url
,
files
,
content_type
,
retried
,
connections
)
while
!
files
.
empty?
and
(
connections
.
size
<
1
or
connections
.
values
.
min
<
100
)
elsif
files
.
empty?
connection
.
close
connections
.
delete
(
connection
)
do_download
(
main_url
,
files
,
content_type
,
count
,
connections
)
while
!
files
.
empty?
and
(
connections
.
size
<
10
or
connections
.
values
.
min
<
100
)
end
if
http
.
response_header
.
status
==
200
and
(
!
content_type
or
http
.
response_header
[
'CONTENT_TYPE'
]
==
content_type
)
...
...
@@ -248,18 +246,31 @@ begin
else
puts
http
.
response_header
.
http_status
end
if
count
[
:total
].
zero?
connections
.
each_key
{
|
connection
|
connection
.
close
}
connections
.
clear
puts
'all done'
EM
.
stop
end
}.
errback
{
|
http
|
puts
http
.
error
connection
.
close
connections
.
delete
(
connection
)
files
[
remote_path
]
=
local_path
retried
[
0
]
+=
1
if
retried
[
0
]
<=
10
*
100
do_download
(
main_url
,
files
,
content_type
,
retried
,
connections
)
while
!
files
.
empty?
and
(
connections
.
size
<
1
or
connections
.
values
.
min
<
100
)
count
[
:error
]
+=
1
if
count
[
:error
]
<=
10
*
100
do_download
(
main_url
,
files
,
content_type
,
count
,
connections
)
while
!
files
.
empty?
and
(
connections
.
size
<
10
or
connections
.
values
.
min
<
100
)
else
connections
.
each_key
{
|
connection
|
connection
.
close
}
connections
.
clear
puts
'network error'
EM
.
stop
end
}
end
def
load_system_conf
system_conf
=
{}
conf_path
=
File
.
join
(
File
.
dirname
(
Config
[
'ygopro'
][
'path'
]),
'system.conf'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment