Class: MyShows::CLI

Inherits:
Object
  • Object
show all
Extended by:
Auth
Defined in:
lib/my_shows.rb

Class Method Summary collapse

Methods included from Auth

ask, ask_for_and_save_credentials, ask_for_credentials, ask_for_password, check, credentials, delete_credentials, echo_off, echo_on, host, netrc, read_credentials, with_tty, write_credentials

Class Method Details

.configure_clientObject



26
27
28
# File 'lib/my_shows.rb', line 26

def configure_client
  MyShows::Show.client = SidereelClient.new(*self.credentials)
end

.enque_to_download(links) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/my_shows.rb', line 44

def enque_to_download(links)
  links.each do |link|
    sleep 5
    uri = URI(link).to_s
    logger.info "Enque #{uri}"
    Launchy::Application::General.new.open([uri])
  end
end

.loggerObject



22
23
24
# File 'lib/my_shows.rb', line 22

def logger
  MyShows.logger
end


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/my_shows.rb', line 30

def lookup_magnet_links(shows)
  shows.pmap do |show|
    link = show.episode.torrent_link!

    if link
      logger.debug "Found #{link[0...10]} for #{show.name}!"
    else
      logger.debug "Not Found any links for #{show.name}!"
    end

    link
  end.compact
end


70
71
72
73
74
75
76
# File 'lib/my_shows.rb', line 70

def print_episodes episodes
  puts 'Next episodes:'
  episodes.each do |show|
    episode = show.episode
    puts "#{episode} [#{episode.magnet_link ? ''.colorize(:green) : ''.colorize(:red)}]"
  end
end


78
79
80
# File 'lib/my_shows.rb', line 78

def print_footer
  puts 'Bye!'
end


66
67
68
# File 'lib/my_shows.rb', line 66

def print_header
  puts "MyShows #{MyShows::VERSION}".colorize(:light_white)
end

.start(*args) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/my_shows.rb', line 53

def start(*args)
  print_header
  configure_client

  #TODO: Episode.next_unwatched.with_links.peach { |episode| print_episode episode; enquee_to_download episode; }

  shows = Show.next_episodes
  links = lookup_magnet_links(shows)
  print_episodes shows
  enque_to_download links
  print_footer
end