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
-
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
-
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
-
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
-
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
-
You just DO WHAT THE FUCK YOU WANT TO.
Constants
- DEFAULT_TRACK_FILE
- DEFAULT_WATCH_DIR
- VERSION
Public Class Methods
# 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
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
# 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
Yamazaki::Core#search
# File lib/yamazaki/yamazaki.rb, line 34 def search(key) items = super(key) return if items.empty? items.each { |item| puts "#{item.to_s}\t#{item.description}" } prompt_download items end
Protected Class Methods
# 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
# File lib/yamazaki/yamazaki.rb, line 62 def torrent_downloaded?(filename) (@db ||= load_database).include?(filename) end
Private Class Methods
# File lib/yamazaki/yamazaki.rb, line 81 def prompt print '>> '.freeze STDIN.gets.to_i - 1 end
# 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