prss 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/bin/prss +11 -0
- data/lib/prss.rb +7 -0
- data/lib/prss/cli.rb +21 -0
- data/lib/prss/downloader.rb +43 -0
- data/lib/prss/fetcher.rb +24 -0
- data/lib/prss/parser.rb +24 -0
- data/lib/prss/version.rb +3 -0
- data/prss.gemspec +20 -0
- metadata +80 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/bin/prss
ADDED
data/lib/prss.rb
ADDED
data/lib/prss/cli.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module PRSS
|
4
|
+
class CLI
|
5
|
+
def initialize passkey, output_dir
|
6
|
+
@passkey = passkey
|
7
|
+
@output_dir = Pathname.new(output_dir)
|
8
|
+
raise 'no passkey' unless passkey
|
9
|
+
raise 'no output dir' unless output_dir
|
10
|
+
end
|
11
|
+
|
12
|
+
def run!
|
13
|
+
output = Fetcher.new(@passkey).output
|
14
|
+
links = Parser.new(output)
|
15
|
+
downloaded = Downloader.new(links).download_to(@output_dir)
|
16
|
+
|
17
|
+
puts "Downloaded #{downloaded.count} files to #{@output_dir}."
|
18
|
+
puts "Files:", *downloaded unless downloaded.empty?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module PRSS
|
5
|
+
class Downloader
|
6
|
+
def initialize(links)
|
7
|
+
@links = links
|
8
|
+
@hydra = Typhoeus::Hydra.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def download_to(output_path)
|
12
|
+
output = Pathname.new(output_path).expand_path
|
13
|
+
raise 'output path is not directory' unless output.directory?
|
14
|
+
|
15
|
+
@files = []
|
16
|
+
@links.each do |link|
|
17
|
+
request = Typhoeus::Request.new(link, :follow_location => true)
|
18
|
+
|
19
|
+
request.on_complete do |response|
|
20
|
+
@files << save_file(response, output)
|
21
|
+
end
|
22
|
+
|
23
|
+
@hydra.queue request
|
24
|
+
end
|
25
|
+
|
26
|
+
@hydra.run
|
27
|
+
|
28
|
+
@files
|
29
|
+
end
|
30
|
+
|
31
|
+
def save_file response, output
|
32
|
+
filename = response.headers_hash['Content-Disposition'][/filename="(.+)"$/ ,1]
|
33
|
+
file = output.join(filename)
|
34
|
+
|
35
|
+
open(file, 'wb') do |file|
|
36
|
+
file.write(response.body)
|
37
|
+
end
|
38
|
+
|
39
|
+
filename
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/prss/fetcher.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
|
3
|
+
module PRSS
|
4
|
+
class Fetcher
|
5
|
+
PERSONAL_FEED_URL = "https://hdbits.org/rss/my"
|
6
|
+
|
7
|
+
attr_reader :uri
|
8
|
+
|
9
|
+
def initialize(passkey)
|
10
|
+
#@passkey = passkey
|
11
|
+
@uri = URI(PERSONAL_FEED_URL)
|
12
|
+
@uri.query = "passkey=#{passkey}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def response
|
16
|
+
@response ||= Typhoeus::Request.get(@uri.to_s)
|
17
|
+
end
|
18
|
+
|
19
|
+
def output
|
20
|
+
response.body
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/prss/parser.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module PRSS
|
4
|
+
class Parser
|
5
|
+
def initialize(xml)
|
6
|
+
@xml = xml
|
7
|
+
end
|
8
|
+
|
9
|
+
def channel
|
10
|
+
@channel ||= Nokogiri::XML.parse(@xml).xpath('//channel')
|
11
|
+
end
|
12
|
+
|
13
|
+
def links
|
14
|
+
channel.xpath('//item/link')
|
15
|
+
end
|
16
|
+
|
17
|
+
def each(&block)
|
18
|
+
links.each do |link|
|
19
|
+
yield link.content
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/prss/version.rb
ADDED
data/prss.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/prss/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Michal Cichra"]
|
6
|
+
gem.email = ["michal@o2h.cz"]
|
7
|
+
gem.description = %q{Simple fetcher of HDbits private RSS stream}
|
8
|
+
gem.summary = %q{Parses HDbits private RSS stream, downloads and saves all files to specified directory}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "prss"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = PRSS::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'nokogiri', '>= 1.5.0'
|
19
|
+
gem.add_dependency 'typhoeus', '>= 0.3.2'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prss
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michal Cichra
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-14 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: &70323141645560 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.5.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70323141645560
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: typhoeus
|
27
|
+
requirement: &70323141643580 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.3.2
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70323141643580
|
36
|
+
description: Simple fetcher of HDbits private RSS stream
|
37
|
+
email:
|
38
|
+
- michal@o2h.cz
|
39
|
+
executables:
|
40
|
+
- prss
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- Rakefile
|
47
|
+
- bin/prss
|
48
|
+
- lib/prss.rb
|
49
|
+
- lib/prss/cli.rb
|
50
|
+
- lib/prss/downloader.rb
|
51
|
+
- lib/prss/fetcher.rb
|
52
|
+
- lib/prss/parser.rb
|
53
|
+
- lib/prss/version.rb
|
54
|
+
- prss.gemspec
|
55
|
+
homepage: ''
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.10
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Parses HDbits private RSS stream, downloads and saves all files to specified
|
79
|
+
directory
|
80
|
+
test_files: []
|