Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seek with mouse #1

Merged
merged 5 commits into from Apr 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
Gemfile.lock
3 changes: 3 additions & 0 deletions Gemfile
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gemspec
13 changes: 9 additions & 4 deletions lib/viera_play/player.rb
@@ -1,4 +1,5 @@
require "curses"
require "streamio-ffmpeg"

module VieraPlay
class Player
Expand All @@ -21,6 +22,10 @@ def exit
super
end

def video_duration
@video_duration ||= TimeStamp.new(FFMPEG::Movie.new(file_path).duration.ceil)
end

def trap_interrupt
trap 'INT' do
trap 'INT', 'DEFAULT'
Expand All @@ -36,12 +41,12 @@ def redraw
win.clear
win.box('|', '-', '+')
win.setpos(1,1)
win << '#' * (@width * info.position.to_i/(info.duration.to_i + 0.0001))
win << '#' * (@width * info.position.to_i/(video_duration.to_i + 0.0001))
win.setpos(2,1)
win.addstr("%s of %s - %20s" % [info.position, info.duration, info.track])
win.addstr("%s of %s - %20s" % [info.position, video_duration, info.track])
win.refresh

exit if info.duration.to_i.zero?
exit if video_duration.to_i.zero?
end

def play_and_wait
Expand All @@ -68,7 +73,7 @@ def play_and_wait
exit
when Curses::KEY_MOUSE
if m = Curses.getmouse
v = (m.x - 2).to_f / (@width) * tv.get_position_info.duration.to_i
v = (m.x - 2).to_f / (@width) * video_duration.to_i
tv.seek_to(v)
end
when nil
Expand Down
2 changes: 1 addition & 1 deletion lib/viera_play/time_stamp.rb
@@ -1,6 +1,6 @@
class TimeStamp
def self.parse(string)
if /\A(-?)([0-9]{2}):([0-9]{2}):([0-9]{2})\Z/.match(string)
if /\A(-?)([0-9]{1,2}):([0-9]{2}):([0-9]{2})\Z/.match(string)
negative, parts = $1, [$2, $3, $4]
parts = parts.map(&:to_i)
val = parts[0] * 60**2 + parts[1] * 60 + parts[2]
Expand Down
13 changes: 7 additions & 6 deletions lib/viera_play/tv.rb
Expand Up @@ -51,17 +51,18 @@ def position
TimeStamp.parse @doc.css('RelTime').first.content
end

def duration
TimeStamp.parse @doc.css('TrackDuration').first.content
end

def track
sub_doc = @doc.css('TrackMetaData').first.content
parsed_subdoc = Nokogiri::XML(sub_doc)
parsed_subdoc.xpath(
titles = parsed_subdoc.xpath(
'//dc:title',
'dc' => 'http://purl.org/dc/elements/1.1/'
).first.content
)
if titles.empty?
""
else
first.content
end
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/time_stamp_spec.rb
Expand Up @@ -19,6 +19,13 @@
TimeStamp.parse('-00:01:01').to_i.should eq(-61)
TimeStamp.parse('-01:01:01').to_i.should eq(-3_661)
end

it "parses timestamps with a single hour digit" do
TimeStamp.parse('0:00:00').to_i.should eq 0
TimeStamp.parse('0:00:01').to_i.should eq 1
TimeStamp.parse('0:01:01').to_i.should eq 61
TimeStamp.parse('1:01:01').to_i.should eq 3_661
end
end

describe "#to_s" do
Expand Down
5 changes: 5 additions & 0 deletions viera_play.gemspec
Expand Up @@ -17,4 +17,9 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
gem.executables << "viera_play"

gem.add_runtime_dependency("nokogiri")
gem.add_runtime_dependency("streamio-ffmpeg")

gem.add_development_dependency("rspec")
end