torrent_rss 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -25,10 +25,31 @@ new entries to download to a specific folder. By default, it will look for a co
25
25
  `~/.torrent_rss`. This configuration file is written using [TOML](https://github.com/mojombo/toml), and
26
26
  includes the destination directory and the array of RSS feeds to query.
27
27
 
28
- TorrentRSS also supports command-line flags that override anything set in `~/.torrent_rss`. Options:
28
+ Example:
29
+
30
+ ``` toml
31
+ directory = "/opt/torrents"
32
+ feeds = [
33
+ "http://example.com/torrent.rss",
34
+ "http://example2.com/doesnt/need/rss/extension"
35
+ ]
36
+ ```
37
+
38
+ TorrentRSS also supports command-line flags that override anything set in its configuration file. By
39
+ default, that file is located at `~/.torrent_rss`, but can be overridden with the `--config` flag.
40
+
41
+ Options:
29
42
  -f, [--feeds=one two three] # Array of Feed URLs to parse and download from
30
43
  -d, [--directory=DIRECTORY] # Directory to download torrent files from
44
+ -c, [--config=CONFIG] # Specify the configuration file for TorrentRSS.
45
+ # Default: ~/.torrent_rss
31
46
 
32
47
  Downloaded items have their IDs MD5'd and logged in `~/.torrent_rss_log` to prevent redownloading.
33
48
 
49
+ *torrent_rss monitor*
50
+
51
+ Do you want to continuously monitor RSS feeds instead of periodically running `torrent_rss fetch`? Then
52
+ you want the `torrent_rss monitor` utility. The monitor will check every 60 seconds if new torrents are
53
+ ready for download. When passed the -d option, it will fork and detach as a daemon.
54
+
34
55
  Questions? Issues? Want to contribute? Pull requests and issues welcome.
@@ -7,14 +7,47 @@ module TorrentRSS
7
7
  desc 'fetch', 'parses RSS feeds and downloads any new torrent files'
8
8
  method_option :feeds, aliases: '-f', type: :array, desc: 'Array of Feed URLs to parse and download from'
9
9
  method_option :directory, aliases: '-d', desc: 'Directory to download torrent files from'
10
+ method_option :config, aliases: '-c', desc: 'Specify the configuration file.', default: '~/.torrent_rss'
11
+ method_option :verbose, type: :boolean, aliases: '-v', desc: 'Output verbosely'
10
12
  def fetch
13
+ Config.config_file = options[:config]
11
14
  feed_urls = options[:feeds] || Config.feeds || []
12
15
  directory = options[:directory] || Config.directory || '.'
13
16
 
14
17
  feed_urls.each do |url|
15
18
  feed = Feed.new url
16
- feed.fetch! directory: directory
19
+ verbose "Fetching for url #{url}"
20
+ feed.fetch! directory: directory, verbose: options[:verbose]
17
21
  end
18
22
  end
23
+
24
+ desc 'monitor', 'continually monitors RSS feeds for changes to downloads'
25
+ method_option :daemonize, aliases: '-d', type: :boolean, default: false, banner: 'Daemonize the monitoring process'
26
+ def monitor
27
+ Signal.trap('INT') { puts 'shutting down' ; exit }
28
+
29
+ if options[:daemonize]
30
+ pid = fork do
31
+ looped_fetch
32
+ end
33
+
34
+ Process.detach pid
35
+ else
36
+ looped_fetch
37
+ end
38
+ end
39
+
40
+ private
41
+ def looped_fetch
42
+ loop do
43
+ invoke :fetch
44
+ verbose "sleeping 60s until next fetch..."
45
+ sleep 60
46
+ end
47
+ end
48
+
49
+ def verbose message
50
+ puts message if options[:verbose]
51
+ end
19
52
  end
20
53
  end
@@ -3,6 +3,7 @@ require 'toml'
3
3
  module TorrentRSS
4
4
  class Config
5
5
  class << self
6
+ attr_accessor :config_file
6
7
  def directory
7
8
  config_data['directory']
8
9
  end
@@ -16,16 +17,12 @@ module TorrentRSS
16
17
  end
17
18
 
18
19
  def read_config
19
- if File.exists? config_path
20
- TOML.load_file config_path
20
+ if File.exists? config_file
21
+ TOML.load_file config_file
21
22
  else
22
23
  {}
23
24
  end
24
25
  end
25
-
26
- def config_path
27
- File.expand_path "~/.torrent_rss"
28
- end
29
26
  end
30
27
  end
31
28
  end
@@ -8,10 +8,16 @@ module TorrentRSS
8
8
  def fetch! options = {}
9
9
  @directory = options[:directory]
10
10
  parsed_feed.entries.each do |entry|
11
+ puts "Parsing #{entry.entry_id}" if options[:verbose]
11
12
  if new_entry? entry
13
+ puts "Entry #{entry.entry_id} is new! Downloading..." if options[:verbose]
12
14
  torrent = Torrent.from_entry entry
13
- torrent.download @directory
14
- EntryLog.add entry.entry_id
15
+ if torrent.download @directory
16
+ puts "Entry #{entry.entry_id} downloaded to #{@directory}!" if options[:verbose]
17
+ EntryLog.add entry.entry_id
18
+ else
19
+ puts "Entry #{entry.entry_id} could not be downloaded" if options[:verbose]
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -23,5 +29,9 @@ module TorrentRSS
23
29
  def parsed_feed
24
30
  @feed ||= Feedzirra::Feed.fetch_and_parse @url
25
31
  end
32
+
33
+ def verbose message
34
+ puts message if options[:verbose]
35
+ end
26
36
  end
27
37
  end
@@ -1,3 +1,3 @@
1
1
  module TorrentRSS
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torrent_rss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-01 00:00:00.000000000 Z
12
+ date: 2013-05-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday