Sha256: a88a6936e8b70abd87c8aae93bd399c36b885987e280624ff0e4340163520397
Contents?: true
Size: 1.43 KB
Versions: 1
Compression:
Stored size: 1.43 KB
Contents
#!/usr/bin/env ruby -w # coding: utf-8 require 'tpb_search' require 'fileutils' require 'highline' require 'optparse' options = { auto: false } optparse = OptionParser.new do |opts| opts.banner = 'Usage: tpb_search [options] <search>' opts.on('-y', '--auto-download', 'Auto-select first link') do options[:auto] = true end opts.on('-v', '--version', 'Print version and exit') do puts "tpb_search v#{TpbSearch::VERSION}" exit end opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end end.parse! # Join arguments to create the search term options[:search] = optparse.join(' ') # main program begin cli = HighLine.new HighLine.colorize_strings # Monkey patch String for cli colors # Valid search? if options[:search].empty? cli.say 'Please type a search'.red exit end # Search subtitle search = TpbSearch::Search.new(options[:search]) # Results found? unless search.results_found? cli.say 'No results found'.red exit end # Choose if options[:auto] torrent = search.links.first else cli.say "Search results for #{options[:search]}:" torrent = cli.choose(*search.links) do |menu| menu.default = '1' menu.select_by = :index end end # Print magnet link for selected file cli.say torrent.magnet rescue Interrupt, EOFError cli.say 'Interrupted!'.red rescue SocketError cli.say "Couldn't perform action. Are you online?".red end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tpb_search-0.1.0 | exe/tpb_search |