module Yamazaki

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

  1. 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

  1. 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

  1. 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

  1. 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

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

Constants

DEFAULT_TRACK_FILE
DEFAULT_WATCH_DIR
VERSION

Public Class Methods

download_torrent(name, link, force = false) click to toggle source
# File lib/yamazaki/yamazaki.rb, line 47
def download_torrent(name, link, force = false)
        name.gsub! '/'.freeze, '-'.freeze

        watch_dir = defined?(WATCH_DIR) == 'constant'.freeze ? WATCH_DIR : DEFAULT_WATCH_DIR
        filename  = "#{watch_dir}/#{name}.torrent"

        if force != true && torrent_downloaded?(filename)
                false
        else
                download(filename, link)
        end
end
list(n) click to toggle source
Calls superclass method Yamazaki::Core#list
# File lib/yamazaki/yamazaki.rb, line 22
def list(n)
        n = 5 if n.to_i == 0

        items = super(n)

        puts "Last #{n} torrents on Nyaa (#{Time.now.hour}:#{Time.now.min})\n\n".cyan.bold
        return if items.empty?

        items.each { |item| puts item.to_s }
        prompt_download items
end
load_database() click to toggle source
# File lib/yamazaki/yamazaki.rb, line 42
def load_database
        track_file = defined?(TRACK_FILE) == 'constant'.freeze ? TRACK_FILE : DEFAULT_TRACK_FILE
        @db = Database.new(track_file)
end

Protected Class Methods

download(filename, link) click to toggle source
# File lib/yamazaki/yamazaki.rb, line 66
def download(filename, link)
        File.open(filename, 'wb'.freeze) do |torrent_file|
                torrent_file.write(open(link).read)
        end

        (@db ||= load_database) << filename
end
torrent_downloaded?(filename) click to toggle source
# File lib/yamazaki/yamazaki.rb, line 62
def torrent_downloaded?(filename)
        (@db ||= load_database).include?(filename)
end

Private Class Methods

prompt() click to toggle source
# File lib/yamazaki/yamazaki.rb, line 81
def prompt
        print '>> '.freeze
        STDIN.gets.to_i - 1
end
prompt_download(ary) click to toggle source
# File lib/yamazaki/yamazaki.rb, line 76
def prompt_download(ary)
        num = prompt
        download_torrent(ary[num].title, ary[num].link) if num >= 0 && num <= ary.length
end