bin/sensible-cinema-cli in sensible-cinema-0.26.0 vs bin/sensible-cinema-cli in sensible-cinema-0.26.1

- old
+ new

@@ -1,154 +1,159 @@ -#!/usr/bin/ruby -=begin -Copyright 2010, Roger Pack -This file is part of Sensible Cinema. - - Sensible Cinema is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Sensible Cinema is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Sensible Cinema. If not, see <http://www.gnu.org/licenses/>. -=end - -require File.dirname(__FILE__) + "/../lib/add_any_bundled_gems_to_load_path.rb" -require 'sane' - -for file in ['overlayer', 'keyboard_input', 'screen_tracker', 'mouse', 'file_chooser', 'ocr', 'vlc_programmer', 'edl_parser', 'auto_window_finder'] - require_relative '../lib/' + file -end - -def go_sc(args) - - $VERBOSE = 1 if args.delete('-v') - $DEBUG = 1 if args.delete('-d') - if args.delete('--clear-cache') - OCR.clear_cache! - puts 'cleared cache' - end - - $stderr.puts 'warning: currently windows only for certain parts currently' unless ENV['OS'] == 'Windows_NT' - - if args.detect{|arg| arg == '-h' || arg == '--help'} - - puts <<-END - - syntax: [player_description.yml] [delete_list.txt|test] [-t, -v, --clear-cache] (or just nothing at all--it will prompt for all things it needs) - +#!/usr/bin/ruby +=begin +Copyright 2010, Roger Pack +This file is part of Sensible Cinema. + + Sensible Cinema is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Sensible Cinema is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Sensible Cinema. If not, see <http://www.gnu.org/licenses/>. +=end + +require File.dirname(__FILE__) + "/../lib/add_any_bundled_gems_to_load_path.rb" +require 'sane' + +for file in ['overlayer', 'keyboard_input', 'screen_tracker', 'mouse', 'ocr', 'vlc_programmer', 'edl_parser', 'auto_window_finder', 'swing_helpers'] + require_relative '../lib/' + file +end + + +def choose_file title, dir + SwingHelpers::FileDialog.new_previously_existing_file_selector_and_go title, dir +end + +def go_sc(args) + + $VERBOSE = 1 if args.delete('-v') + $DEBUG = 1 if args.delete('-d') + if args.delete('--clear-cache') + OCR.clear_cache! + puts 'cleared cache' + end + + $stderr.puts 'warning: currently windows only for certain parts currently' unless ENV['OS'] == 'Windows_NT' + + if args.detect{|arg| arg == '-h' || arg == '--help'} + + puts <<-END + + syntax: [player_description.yml] [delete_list.txt|test] [-t, -v, --clear-cache] (or just nothing at all--it will prompt for all things it needs) + If you specify "test" for the edit list, it will pause 2s, take a single snapshot of the selected player, then exit. Useful for debugging your screen capture of the current player. - You can also specify -v or -t if you want to enable more verbose (chatty) output. - - END - - for file in Dir[__DIR__ + '../zamples/mute*/*'] - puts "\n", "Example file:", file + "\n\n", File.read(file) - end - - exit 1 - end - - players_root_dir = __DIR__ + "/../zamples/players" - # allow for command line filenames - player_description = args.shift - unless player_description - player_description = AutoWindowFinder.search_for_player_and_url_match(players_root_dir) - if player_description - p 'auto selected player ' + player_description - else - player_description = '' - end - end - - if !File.exist?(player_description) - puts 'Please Select Computer Player' - player_description = FileChooser.choose_file(" SELECT COMPUTER PLAYER", players_root_dir) - raise unless player_description - end - - edit_decision_list = args.shift.to_s - - if edit_decision_list == 'test' - overlay = nil - p 'got test...just doing screen dump' - $VERBOSE=true # adds some extra output - elsif File.exist? edit_decision_list - # accept it from the command line - else - # assume they want an online player, right? LODO player can tell us... - auto_found = AutoWindowFinder.search_for_single_url_match - if auto_found - p 'auto-discovered open window for player x EDL, using it ' + auto_found - edit_decision_list = auto_found - else - puts 'Select Edit Decision List to use' - edit_decision_list = FileChooser.choose_file(" SELECT EDIT DECISION LIST", __DIR__ + "/../zamples/edit_decision_lists") - end - settings = EdlParser.parse_file auto_found - - if !edit_decision_list - puts "error: have to specify a scene descriptions file\n or specify \"test\" on the command line if you just want to snapshot your player" - exit 1 - end - - puts 'Selected scene descriptions file ' + File.basename(edit_decision_list) + "\n\t(full path: #{edit_decision_list})" - Blanker.startup - # todo start it late as it has an annoying startup blip - end - overlay = OverLayer.new(edit_decision_list) if edit_decision_list - - if File.exist? player_description.to_s - puts 'Selected player ' + File.basename(player_description) + "\n\t(full path: #{player_description})" - # this one doesn't use any updates, so just pass in file contents, not filename - screen_tracker = ScreenTracker.new_from_yaml File.binread(player_description), overlay - does_not_need_mouse_jerk = YAML.load_file(player_description)["does_not_need_mouse_movement"] - unless does_not_need_mouse_jerk - p 'yes using mouse jitter' if $VERBOSE or $DEBUG - Mouse.jitter_forever_in_own_thread # when this ends you know a snapshot was taken... - else - p 'not using mouse jitter' if $VERBOSE or $DEBUG - end - - # exit early if we just wanted a screen dump...a little kludgey... - unless overlay - puts 'warning--only doing screen dump in t-minus 2s...' - sleep 2 - puts 'snap!' - screen_tracker.dump_bmps - exit 1 - end - screen_tracker.process_forever_in_thread - else - puts 'warning--not using any screen tracking...' - end - - OCR.unserialize_cache_from_disk # do this every time so we don't delete it if they don't have one... - - p 'moving mouse to align it for muting down 10' - Mouse.move_mouse_relative 0, 10 # LODO - puts "Opening the curtains... (please play in your other video player now)" - overlay.start_thread true - key_input = KeyboardInput.new overlay - key_input.start_thread # status thread - at_exit { - Blanker.shutdown # lodo move this and the 'q' key to within overlayer - OCR.serialize_cache_to_disk - } - begin - key_input.handle_keystrokes_forever # blocking... - ensure - puts "syntax from command line: \"#{player_description}\" \"#{edit_decision_list}\"" - end - -end - -if __FILE__ == $0 - puts 'Welcome to Sensible Cinema...' - go_sc ARGV + You can also specify -v or -t if you want to enable more verbose (chatty) output. + + END + + for file in Dir[__DIR__ + '../zamples/mute*/*'] + puts "\n", "Example file:", file + "\n\n", File.read(file) + end + + exit 1 + end + + players_root_dir = __DIR__ + "/../zamples/players" + # allow for command line filenames + player_description = args.shift + unless player_description + player_description = AutoWindowFinder.search_for_player_and_url_match(players_root_dir) + if player_description + p 'auto selected player ' + player_description + else + player_description = '' + end + end + + if !File.exist?(player_description) + puts 'Please Select Computer Player' + player_description = choose_file(" SELECT COMPUTER PLAYER", players_root_dir) + raise unless player_description + end + + edit_decision_list = args.shift.to_s + + if edit_decision_list == 'test' + overlay = nil + p 'got test...just doing screen dump' + $VERBOSE=true # adds some extra output + elsif File.exist? edit_decision_list + # accept it from the command line + else + # assume they want an online player, right? LODO player can tell us... + auto_found = AutoWindowFinder.search_for_single_url_match + if auto_found + p 'auto-discovered open window for player x EDL, using it ' + auto_found + edit_decision_list = auto_found + else + puts 'Select Edit Decision List to use' + edit_decision_list = choose_file(" SELECT EDIT DECISION LIST", __DIR__ + "/../zamples/edit_decision_lists") + end + settings = EdlParser.parse_file edit_decision_list + + if !edit_decision_list + puts "error: have to specify a scene descriptions file\n or specify \"test\" on the command line if you just want to snapshot your player" + exit 1 + end + + puts 'Selected scene descriptions file ' + File.basename(edit_decision_list) + "\n\t(full path: #{edit_decision_list})" + Blanker.startup + # todo start it late as it has an annoying startup blip + end + overlay = OverLayer.new(edit_decision_list) if edit_decision_list + + if File.exist? player_description.to_s + puts 'Selected player ' + File.basename(player_description) + "\n\t(full path: #{player_description})" + # this one doesn't use any updates, so just pass in file contents, not filename + screen_tracker = ScreenTracker.new_from_yaml File.binread(player_description), overlay + does_not_need_mouse_jerk = YAML.load_file(player_description)["does_not_need_mouse_movement"] + unless does_not_need_mouse_jerk + p 'yes using mouse jitter' if $VERBOSE or $DEBUG + Mouse.jitter_forever_in_own_thread # when this ends you know a snapshot was taken... + else + p 'not using mouse jitter' if $VERBOSE or $DEBUG + end + + # exit early if we just wanted a screen dump...a little kludgey... + unless overlay + puts 'warning--only doing screen dump in t-minus 2s...' + sleep 2 + puts 'snap!' + screen_tracker.dump_bmps + exit 1 + end + screen_tracker.process_forever_in_thread + else + puts 'warning--not using any screen tracking...' + end + + OCR.unserialize_cache_from_disk # do this every time so we don't delete it if they don't have one... + + p 'moving mouse to align it for muting down 10' + Mouse.move_mouse_relative 0, 10 # LODO + puts "Opening the curtains... (please play in your other video player now)" + overlay.start_thread true + key_input = KeyboardInput.new overlay + key_input.start_thread # status thread + at_exit { + Blanker.shutdown # lodo move this and the 'q' key to within overlayer + OCR.serialize_cache_to_disk + } + begin + key_input.handle_keystrokes_forever # blocking... + ensure + puts "syntax from command line: \"#{player_description}\" \"#{edit_decision_list}\"" + end + +end + +if __FILE__ == $0 + puts 'Welcome to Sensible Cinema...' + go_sc ARGV end \ No newline at end of file