Class: Peerflixrb::Commands
- Inherits:
-
Object
- Object
- Peerflixrb::Commands
- Defined in:
- lib/peerflixrb/commands.rb
Instance Method Summary collapse
- #check_requirements ⇒ Object
- #choose_video_and_subtitles(search_result, options) ⇒ Object
-
#initialize ⇒ Commands
constructor
A new instance of Commands.
- #node_installed? ⇒ Boolean
- #webtorrent ⇒ Object
- #webtorrent_installed? ⇒ Boolean
Constructor Details
#initialize ⇒ Commands
Returns a new instance of Commands.
8 9 10 |
# File 'lib/peerflixrb/commands.rb', line 8 def initialize HighLine.colorize_strings end |
Instance Method Details
#check_requirements ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/peerflixrb/commands.rb', line 12 def check_requirements unless node_installed? say 'Nodejs is required to make it work.'.red exit end unless webtorrent_installed? say 'webtorrent is required. Type "npm install -g webtorrent-cli" in your shell to install it.'.red exit end end |
#choose_video_and_subtitles(search_result, options) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/peerflixrb/commands.rb', line 38 def choose_video_and_subtitles(search_result, ) # Proactively declare them because they would be lost in the block scope link = nil links = search_result.links.sort.reverse sub_file = nil loop do # Choose file link = [:auto_select] ? links.first : select_link(links) # Subtitle search sub_file = if [:find_subtitles] # TODO say "Searching subtitles for #{link.title.blue}".yellow find_subtitles(link, ) elsif [:subtitles] [:subtitles] end # Was there a problem with the subtitle? if [:find_subtitles] && sub_file.nil? continue = agree "Could not find subtitles. Do you want to continue? #{'[y/n]'.yellow}".blue unless continue # If :auto_select, exit program # If video chosen, choose video again if [:auto_select] exit else system 'clear' next end end end # If the loop got here then it found subtitles break end [link, sub_file] end |
#node_installed? ⇒ Boolean
30 31 32 |
# File 'lib/peerflixrb/commands.rb', line 30 def node_installed? system('node --version > /dev/null 2>&1') end |
#webtorrent ⇒ Object
24 25 26 27 28 |
# File 'lib/peerflixrb/commands.rb', line 24 def webtorrent return 'webtorrent' if webtorrent_installed? return "#{BINARY_PATH}/webtorrent-cli-#{os}" if os check_requirements end |
#webtorrent_installed? ⇒ Boolean
34 35 36 |
# File 'lib/peerflixrb/commands.rb', line 34 def webtorrent_installed? system('webtorrent --version > /dev/null 2>&1') end |