xunlei 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -0
- data/bin/xunlei +24 -2
- data/lib/xunlei/search.rb +30 -24
- data/lib/xunlei/version.rb +1 -1
- metadata +16 -16
data/README.md
CHANGED
@@ -43,6 +43,10 @@ Download files according to pattern in file names
|
|
43
43
|
Add ed2k or magnet link as new task
|
44
44
|
|
45
45
|
xunlei add ed2k_or_magment_link
|
46
|
+
|
47
|
+
Add all ed2k or magnet links on given web page as new tasks
|
48
|
+
|
49
|
+
xunlei add_page http://page_with_a_chunk_load_of_links/
|
46
50
|
|
47
51
|
Google for ed2k and magnet links
|
48
52
|
|
data/bin/xunlei
CHANGED
@@ -44,10 +44,10 @@ def execute_dump_action(args, options)
|
|
44
44
|
engine.stop
|
45
45
|
end
|
46
46
|
|
47
|
-
def do_dump_cookies(c)
|
47
|
+
def do_dump_cookies(c, &block)
|
48
48
|
c.option "--driver DRIVER", String, "use a different webdriver (e.g. firefox). default is chrome"
|
49
49
|
c.action do |args, options|
|
50
|
-
execute_dump_action(args, options)
|
50
|
+
execute_dump_action(args, options, &block)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -336,6 +336,28 @@ command :lucky do |c|
|
|
336
336
|
end
|
337
337
|
end
|
338
338
|
|
339
|
+
command :add_page do |c|
|
340
|
+
c.syntax = "add_page URL"
|
341
|
+
c.description = "add all ed2k and magnet links as new tasks on given web page :)"
|
342
|
+
c.option "--only PATTERN", String, "only add links which names include PATTERN"
|
343
|
+
c.option "--except PATTERN", String, "do not add links which names include PATTERN"
|
344
|
+
c.action do |args, options|
|
345
|
+
options.default :only => nil, :except => nil
|
346
|
+
puts "Adding page '#{args.first}'..."
|
347
|
+
puts
|
348
|
+
search = Xunlei::Search.new
|
349
|
+
links = search.add_page(args.first, options)
|
350
|
+
puts
|
351
|
+
puts "#{links.count} links found."
|
352
|
+
|
353
|
+
execute_dump_action(args, options) do |engine, args|
|
354
|
+
links.each do |link|
|
355
|
+
engine.add_task(link)
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
339
361
|
alias_command :down, :download
|
340
362
|
alias_command :dump, :dump_tasks
|
341
363
|
alias_command :search, :google
|
data/lib/xunlei/search.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
require "watir-webdriver"
|
2
1
|
require "Nokogiri"
|
3
2
|
require "uri"
|
3
|
+
require "open-uri"
|
4
4
|
|
5
5
|
module Xunlei
|
6
6
|
class Search
|
7
7
|
def initialize(driver = :chrome)
|
8
|
-
@browser = Watir::Browser.new driver
|
9
8
|
end
|
10
9
|
|
11
10
|
def google(keywords, options)
|
@@ -16,40 +15,47 @@ module Xunlei
|
|
16
15
|
do_google(keywords, options, "http://www.google.com/search?q=site:simplecd.org+", 1)
|
17
16
|
end
|
18
17
|
|
18
|
+
def add_page(page_url, options)
|
19
|
+
doc = Nokogiri::HTML(open(page_url) { |page| page.read })
|
20
|
+
links = []
|
21
|
+
|
22
|
+
doc.css("a").select do |a|
|
23
|
+
!a['href'].nil? && a['href'] =~ /ed2k:|magnet:/
|
24
|
+
end.map do |a|
|
25
|
+
a['href']
|
26
|
+
end.uniq.each do |link|
|
27
|
+
if !options.only.nil?
|
28
|
+
links << link if link =~ /#{options.only}/i
|
29
|
+
elsif !options.except.nil?
|
30
|
+
links << link unless link =~ /#{options.except}/i
|
31
|
+
else
|
32
|
+
links << link
|
33
|
+
end
|
34
|
+
end
|
35
|
+
links.each { |link| puts link }
|
36
|
+
links
|
37
|
+
end
|
38
|
+
|
19
39
|
private
|
20
40
|
|
21
41
|
def do_google(keywords, options, prefix, limit)
|
22
42
|
q = [keywords, options.with, "ed2k"].flatten.join("+")
|
23
43
|
q += "+-" + options.without unless options.without.nil?
|
24
44
|
|
25
|
-
|
26
|
-
|
27
|
-
@browser.div(:id => "ires").wait_until_present
|
28
|
-
|
29
|
-
page_links = []
|
30
|
-
@browser.lis(:class => "g").each { |li| page_links << li.as.first.href }
|
45
|
+
search_result = Nokogiri::HTML(open("#{prefix}#{q}") { |page| page.read })
|
46
|
+
page_links = search_result.css(".g h3 a").map { |a| a['href'] }[0, limit]
|
31
47
|
|
32
48
|
ed2k_links = []
|
33
49
|
|
34
50
|
page_links.each do |page_link|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
if href =~ /ed2k:|magnet:/ && !ed2k_links.include?(href)
|
42
|
-
puts href
|
43
|
-
ed2k_links << href
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
limit -= 1
|
48
|
-
break unless limit > 1
|
51
|
+
doc = Nokogiri::HTML(open(page_link) { |page| page.read })
|
52
|
+
ed2k_links += doc.css("a").select do |a|
|
53
|
+
!a['href'].nil? && a['href'] =~ /ed2k:|magnet:/
|
54
|
+
end.map do |a|
|
55
|
+
a['href'].tap { |a| puts a }
|
56
|
+
end.uniq
|
49
57
|
end
|
50
58
|
|
51
|
-
@browser.close
|
52
|
-
|
53
59
|
ed2k_links
|
54
60
|
end
|
55
61
|
end
|
data/lib/xunlei/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xunlei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70151191992140 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70151191992140
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70151191991700 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70151191991700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: simplecov
|
38
|
-
requirement: &
|
38
|
+
requirement: &70151191991240 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70151191991240
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: watir-webdriver
|
49
|
-
requirement: &
|
49
|
+
requirement: &70151191990800 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70151191990800
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: commander
|
60
|
-
requirement: &
|
60
|
+
requirement: &70151191990360 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70151191990360
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: nokogiri
|
71
|
-
requirement: &
|
71
|
+
requirement: &70151191989900 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70151191989900
|
80
80
|
description: A browser script to access lixian.vip.xunlei.com tasks automatically
|
81
81
|
email:
|
82
82
|
- afu@forresty.com
|
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: '0'
|
116
116
|
segments:
|
117
117
|
- 0
|
118
|
-
hash:
|
118
|
+
hash: -893131726371942937
|
119
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
120
|
none: false
|
121
121
|
requirements:
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
segments:
|
126
126
|
- 0
|
127
|
-
hash:
|
127
|
+
hash: -893131726371942937
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project: xunlei
|
130
130
|
rubygems_version: 1.8.11
|