module Miyuki

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
        Version 2, December 2004

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
        Version 2, December 2004

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
        Version 2, December 2004

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
        Version 2, December 2004

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
        Version 2, December 2004

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.

Constants

VERSION

Attributes

config[R]
config_file[R]
join_scheduler[RW]

Public Class Methods

config=(config_file) click to toggle source
# File lib/miyuki/miyuki.rb, line 20
def config=(config_file)
  @notifier = Notifier.new

  @config_file = config_file
  @config = load_config

  Thread.new do
    Filewatcher.new(config_file).watch { refresh_config }
  end
end
track!() click to toggle source
# File lib/miyuki/miyuki.rb, line 31
def track!
  raise Exception, 'You have to provide a proper configuration file to start the tracking.' unless @config

  watch_dir = File.expand_path(@config['watchDir'])
  FileUtils.mkdir_p(watch_dir) unless Dir.exists?(watch_dir)

  track_file = File.expand_path(@config['trackFile'] || '~')

  config = DeepClone.clone(@config)
  @tracker = Tracker.new(watch_dir, track_file, config['series']) do |torrent|
    notify_torrents(torrent)
  end

  @tracker.refresh! && run_scheduler!
end

Private Class Methods

load_config() click to toggle source
# File lib/miyuki/miyuki.rb, line 60
def load_config
  YAML.load(File.read(@config_file))
end
notify_configuration() click to toggle source
# File lib/miyuki/miyuki.rb, line 79
def notify_configuration
  if @config['notifications']['enabled']
    @notifier.notify('New configuration loaded in Miyuki', 'Changes detected in configuration file')
  end
end
notify_torrents(torrent) click to toggle source
# File lib/miyuki/miyuki.rb, line 72
def notify_torrents(torrent)
  if @config['notifications']['enabled']
    @notifier.notify(torrent.title, 'New episode released')
    sleep 1.1
  end
end
refresh_config() click to toggle source
# File lib/miyuki/miyuki.rb, line 49
def refresh_config
  new_config = load_config

  if @config != new_config
    notify_configuration

    @config = new_config
    track!
  end
end
run_scheduler!() click to toggle source
# File lib/miyuki/miyuki.rb, line 64
def run_scheduler!
  @scheduled_job.kill if @scheduled_job

  scheduler = Rufus::Scheduler.new
  @scheduled_job = scheduler.schedule_every(@config['refreshEvery']) { @tracker.refresh! }
  scheduler.join if @join_scheduler != false
end