Skip to content

Commit

Permalink
vendorize imagemagick et al
Browse files Browse the repository at this point in the history
  • Loading branch information
rdp committed May 6, 2014
1 parent cacb4dd commit 65bf048
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 36 deletions.
19 changes: 0 additions & 19 deletions lib/mouse_jitter_forever.rb

This file was deleted.

10 changes: 4 additions & 6 deletions lib/ocr.rb
Expand Up @@ -17,10 +17,10 @@
=end
require 'sane' # gem
require 'whichr' # gem
require 'mini_magick'

# not a dependency anymore, so I don't have to bundle it...
# im_path = File.expand_path(File.dirname(__FILE__) + "/../vendor/cache/imagemagick") # convert.exe wants to only be chosen from here...
# ENV['PATH'] = im_path.gsub('/', "\\") + ';' + ENV['PATH']
im_path = File.expand_path(File.dirname(__FILE__) + "/../vendor/") # convert.exe/identify.exe want to only be chosen first from here...
ENV['PATH'] = im_path.gsub('/', "\\") + ';' + ENV['PATH']

if RubyWhich.new.which('identify').length == 0 || RubyWhich.new.which('convert').length == 0
puts 'appears you do not have imagemagick installed (or not in your path) -- please download and install it first! http://www.imagemagick.org/script/binary-releases.php for windows, for instance'
Expand All @@ -41,8 +41,7 @@ module OCR

# options are :might_be_colon, :should_invert
def identify_digit memory_bitmap, options = {}
require 'mini_magick' # here because of installation woe, but actually not a big slowdown

# spawning a process is [on windows at least] actually pretty expensive--last time I looked at least
if CACHE.has_key?(memory_bitmap)
return CACHE[memory_bitmap] unless (defined?($OCR_NO_CACHE) && $OCR_NO_CACHE)
else
Expand All @@ -59,7 +58,6 @@ def identify_digit memory_bitmap, options = {}
end
end
image = MiniMagick::Image.read(memory_bitmap)
p 'SUCCESS imagemagick read from mem\n*'*100
# any operation on image is expensive, requires convert.exe in path...
if options[:should_invert]
# hulu wants negate
Expand Down
7 changes: 5 additions & 2 deletions lib/online_movie_players.rb
Expand Up @@ -59,7 +59,7 @@ def go_online just_screen_snapshot = false, url = nil, player_description_path =
end
if url
overlay = OverLayer.new(url)
Blanker.warmup
Blanker.warmup
end

puts 'Selected player ' + File.basename(player_description_path) + "\n\t(full path: #{player_description_path})"
Expand Down Expand Up @@ -94,8 +94,11 @@ def go_online just_screen_snapshot = false, url = nil, player_description_path =

puts "Opening the curtains, all systems started... (please play in your other video player now)"

at_exit { # lodo at end of window close [?]
at_exit { # lodo at end of a window close [?]
Blanker.shutdown
screen_tracker.shutdown
OCR.serialize_cache_to_disk
MouseControl.shutdown
overlay.shutdown
}
end
20 changes: 13 additions & 7 deletions lib/screen_tracker.rb
Expand Up @@ -75,9 +75,9 @@ def initialize name_or_regex, x, y, width, height, use_class_name=nil, digits=ni

def get_hwnd_loop_forever
if @name_or_regex.to_s.downcase == 'desktop'
# full screen option
assert !@use_class_name # not an option
@hwnd = hwnd = Win32::Screenshot::BitmapMaker.desktop_window
# full screen 'use the desktop' option
assert !@use_class_name # window "class name" and desktop is not an option
@hwnd = Win32::Screenshot::BitmapMaker.desktop_window
return
else
raise if OS.mac?
Expand Down Expand Up @@ -195,7 +195,7 @@ def wait_till_next_change
if got_implies_able_to_still_ocr
return got_implies_able_to_still_ocr
else
p 'warning--unable to track screen time for some reason [perhaps screen obscured or it\'s not playing yet?] ' + @hwnd.to_s
p 'warning--unable to track screen time for some reason [perhaps screen obscured or it\'s not playing yet?] @hwnd:' + @hwnd.to_s
@previously_displayed_warning = true
# also reget window hwnd, just in case that's the problem...(can be with VLC moving from title to title)
get_hwnd_loop_forever
Expand Down Expand Up @@ -259,13 +259,19 @@ def attempt_to_get_time_from_screen start_time
return out, Time.now-start_time
end

@keep_going = true

def shutdown
@keep_going = false
end

def process_forever_in_thread
Thread.new {
loop {
p 'screen tracker thread'
while(@keep_going)
p 'screen tracker thread'
out_time, delta = wait_till_next_change
@callback.timestamp_changed out_time, delta
}
end
}
end

Expand Down
3 changes: 1 addition & 2 deletions lib/status_line.rb
Expand Up @@ -28,15 +28,14 @@ def initialize fella
def start_thread
Thread.new {
loop {
p 'status line thread'
print get_line_printout
sleep 0.1
}
}
end

def get_line_printout
status = @fella.status
status = "status line:" + @fella.status
# some scary hard coded values here...XXXX
" " * 20 + "\b"*150 + status
end
Expand Down
Binary file added vendor/identify.exe
Binary file not shown.
Binary file added vendor/mogrify.exe
Binary file not shown.
25 changes: 25 additions & 0 deletions zamples/players/amazon/total_length_over_an_hour.txt
@@ -0,0 +1,25 @@
name: desktop
x: 8
y: -17
width: 45
height: 13
digits:
:hours:
- 15
- 7
:minute_tens:
- 24
- 7
:minute_ones:
- 31
- 6
:second_tens:
- 40
- 6
:second_ones:
- 46
- 7
:should_invert: true
:levels:
- 100

0 comments on commit 65bf048

Please sign in to comment.