easy_mplayer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ rdoc
2
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Brent Sanders
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = NAME
2
+
3
+ Easy MPlayer - A wrapper for easy control of mplayer.
4
+
5
+ = DESCRIPTION
6
+
7
+ == Install
8
+
9
+ gem install easy_mplayer
10
+
11
+ == Usage
12
+
13
+ See the scripts in the examples/ directory.
14
+
15
+ = COPYRIGHT
16
+
17
+ Copyright (c) 2010 Brent Sanders. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "easy_mplayer"
8
+ gem.summary = "Wrapper to launch and control MPlayer"
9
+ gem.description = "A wrapper to manage mplayer, that supports callbacks to easyily support event-driven GUIs"
10
+ gem.email = "gem-mplayer@thoughtnoise.net"
11
+ gem.homepage = "http://github.com/pdkl95/easy_mplayer"
12
+ gem.authors = ["Brent Sanders"]
13
+ gem.add_runtime_dependency "color_debug_messages", ">= 1.1.2"
14
+ gem.add_runtime_dependency "facets", ">= 2.8.0"
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/rdoctask'
22
+ Rake::RDocTask.new do |rdoc|
23
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
24
+
25
+ rdoc.rdoc_dir = 'rdoc'
26
+ rdoc.title = "easy_mplayer #{version}"
27
+ rdoc.rdoc_files.include('README*')
28
+ rdoc.rdoc_files.include('lib/**/*.rb')
29
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{easy_mplayer}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Brent Sanders"]
12
+ s.date = %q{2010-01-05}
13
+ s.description = %q{A wrapper to manage mplayer, that supports callbacks to easyily support event-driven GUIs}
14
+ s.email = %q{gem-mplayer@thoughtnoise.net}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "easy_mplayer.gemspec",
27
+ "examples/basic.rb",
28
+ "examples/callbacks.rb",
29
+ "examples/inherit_class.rb",
30
+ "examples/minimal.rb",
31
+ "lib/easy_mplayer.rb",
32
+ "lib/easy_mplayer/callback.rb",
33
+ "lib/easy_mplayer/commands.rb",
34
+ "lib/easy_mplayer/errors.rb",
35
+ "lib/easy_mplayer/helpers.rb",
36
+ "lib/easy_mplayer/main.rb",
37
+ "lib/easy_mplayer/worker.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/pdkl95/easy_mplayer}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.5}
43
+ s.summary = %q{Wrapper to launch and control MPlayer}
44
+ s.test_files = [
45
+ "examples/minimal.rb",
46
+ "examples/basic.rb",
47
+ "examples/inherit_class.rb",
48
+ "examples/callbacks.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_runtime_dependency(%q<color_debug_messages>, [">= 1.1.2"])
57
+ s.add_runtime_dependency(%q<facets>, [">= 2.8.0"])
58
+ else
59
+ s.add_dependency(%q<color_debug_messages>, [">= 1.1.2"])
60
+ s.add_dependency(%q<facets>, [">= 2.8.0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<color_debug_messages>, [">= 1.1.2"])
64
+ s.add_dependency(%q<facets>, [">= 2.8.0"])
65
+ end
66
+ end
67
+
data/examples/basic.rb ADDED
@@ -0,0 +1,66 @@
1
+ #!/bin/env ruby
2
+
3
+ require 'pathname'
4
+ $LOAD_PATH << File.join(File.dirname(Pathname.new(__FILE__).realpath),'../lib')
5
+ require 'easy_mplayer'
6
+
7
+ # play a file from the command line
8
+ raise "usage: #{$0} <file>" if ARGV.length != 1
9
+ $file = ARGV[0]
10
+
11
+ #
12
+ # This walks through some of the basic commands to
13
+ # control already-playing media
14
+ #
15
+
16
+ def show(msg)
17
+ puts 'EXAMPLE<basic> ' + msg
18
+ end
19
+
20
+ def command(msg)
21
+ show "2"
22
+ sleep 1
23
+ show "1"
24
+ sleep 1
25
+ show "Command( #{msg} )"
26
+ yield
27
+ end
28
+
29
+ show "Create the player object for: #{$file}"
30
+ mplayer = MPlayer.new( :path => $file )
31
+
32
+ show "Spawning the mplayer process!"
33
+ mplayer.play
34
+
35
+ # set this true to see various basic commands
36
+ # set it false to see the basic "wait until the file is done" check
37
+ show_basic_commands = true
38
+
39
+ if show_basic_commands
40
+ command "pause" do
41
+ mplayer.pause
42
+ end
43
+
44
+ command "pause (again, to resume)" do
45
+ mplayer.unpause
46
+ end
47
+
48
+ command "seek to 25%" do
49
+ mplayer.seek_to_percent 25.0
50
+ end
51
+
52
+ command "seek back to 10%" do
53
+ mplayer.seek_to_percent 10.0
54
+ end
55
+
56
+ command "stop" do
57
+ mplayer.stop
58
+ end
59
+
60
+ else
61
+ show "Waiting for the file to finish..."
62
+ sleep 1 while mplayer.playing?
63
+ end
64
+
65
+
66
+ show "All done!"
@@ -0,0 +1,98 @@
1
+ #!/bin/env ruby
2
+
3
+ require 'pathname'
4
+ $LOAD_PATH << File.join(File.dirname(Pathname.new(__FILE__).realpath),'../lib')
5
+ require 'easy_mplayer'
6
+
7
+ #
8
+ # a more full-featured script, that gives basic pause/ff/rw support,
9
+ # and reports various statistics by the callback mechanism
10
+ #
11
+
12
+ class MyApp
13
+ def show(msg)
14
+ puts 'EXAMPLE<callbacks> ' + msg
15
+ end
16
+
17
+ def process_key(key)
18
+ case key
19
+ when 'q', 'Q' then @mplayer.stop
20
+ when " " then @mplayer.pause_or_unpause
21
+ when "\e[A" then @mplayer.seek_forward(60) # UP arrow
22
+ when "\e[B" then @mplayer.seek_reverse(60) # DOWN arrow
23
+ when "\e[C" then @mplayer.seek_forward # RIGHT arrow
24
+ when "\e[D" then @mplayer.seek_reverse # LEFT arrow
25
+ end
26
+ end
27
+
28
+ def read_keys
29
+ x = IO.select([$stdin], nil, nil, 0.1)
30
+ return if !x or x.empty?
31
+ @key ||= ''
32
+ @key << $stdin.read(1)
33
+ if @key[0,1] != "\e" or @key.length >= 3
34
+ process_key(@key)
35
+ @key = ''
36
+ end
37
+ end
38
+
39
+ def run!
40
+ begin
41
+ @mplayer.play
42
+
43
+ tty_state = `stty -g`
44
+ system "stty cbreak -echo"
45
+ read_keys while @mplayer.running?
46
+ ensure
47
+ system "stty #{tty_state}"
48
+ end
49
+ end
50
+
51
+ def initialize(file)
52
+ @mplayer = MPlayer.new( :path => file )
53
+
54
+ @mplayer.callback :audio_stats do
55
+ show "Audio is: "
56
+ show " -> sample_rate: #{@mplayer.stats[:audio_sample_rate]} Hz"
57
+ show " -> audio_channels: #{@mplayer.stats[:audio_channels]}"
58
+ show " -> audio_format: #{@mplayer.stats[:audio_format]}"
59
+ show " -> data_rate: #{@mplayer.stats[:audio_data_rate]} kb/s"
60
+ end
61
+
62
+ @mplayer.callback :video_stats do
63
+ show "Video is: "
64
+ show " -> fourCC: #{@mplayer.stats[:video_fourcc]}"
65
+ show " -> x_size: #{@mplayer.stats[:video_x_size]}"
66
+ show " -> y_size: #{@mplayer.stats[:video_y_size]}"
67
+ show " -> bpp: #{@mplayer.stats[:video_bpp]}"
68
+ show " -> fps: #{@mplayer.stats[:video_fps]}"
69
+ end
70
+
71
+ @mplayer.callback :position do |position|
72
+ show "Song position percent: #{position}%"
73
+ end
74
+
75
+ @mplayer.callback :played_seconds do |val|
76
+ total = @mplayer.stats[:total_time]
77
+ show "song position in seconds: #{val} / #{total}"
78
+ end
79
+
80
+ @mplayer.callback :pause, :unpause do |pause_state|
81
+ show "song state: " + (pause_state ? "PAUSED!" : "RESUMED!")
82
+ end
83
+
84
+ @mplayer.callback :play do
85
+ show "song started!"
86
+ end
87
+
88
+ @mplayer.callback :stop do
89
+ show "song ended!"
90
+ puts "final stats were: #{@mplayer.stats.inspect}"
91
+ end
92
+ end
93
+ end
94
+
95
+ # play a file from the command line
96
+ raise "usage: #{$0} <file>" if ARGV.length != 1
97
+
98
+ MyApp.new(ARGV[0]).run!
@@ -0,0 +1,98 @@
1
+ #!/bin/env ruby
2
+
3
+ require 'pathname'
4
+ $LOAD_PATH << File.join(File.dirname(Pathname.new(__FILE__).realpath),'../lib')
5
+ require 'easy_mplayer'
6
+
7
+ #
8
+ # This version derrives directly from the MPlayer class, which makes
9
+ # the adding of callbacks easier.
10
+ #
11
+
12
+ class MyApp < MPlayer
13
+ def show(msg)
14
+ puts 'EXAMPLE<callbacks> ' + msg
15
+ end
16
+
17
+ def process_key(key)
18
+ case key
19
+ when 'q', 'Q' then stop
20
+ when " " then pause_or_unpause
21
+ when "\e[A" then seek_forward(60) # UP arrow
22
+ when "\e[B" then seek_reverse(60) # DOWN arrow
23
+ when "\e[C" then seek_forward # RIGHT arrow
24
+ when "\e[D" then seek_reverse # LEFT arrow
25
+ end
26
+ end
27
+
28
+ def read_keys
29
+ x = IO.select([$stdin], nil, nil, 0.1)
30
+ return if !x or x.empty?
31
+ @key ||= ''
32
+ @key << $stdin.read(1)
33
+ if @key[0,1] != "\e" or @key.length >= 3
34
+ process_key(@key)
35
+ @key = ''
36
+ end
37
+ end
38
+
39
+ def run!
40
+ begin
41
+ play
42
+
43
+ tty_state = `stty -g`
44
+ system "stty cbreak -echo"
45
+ read_keys while running?
46
+ ensure
47
+ system "stty #{tty_state}"
48
+ end
49
+ end
50
+
51
+ def initialize(file)
52
+ super( :path => file )
53
+ end
54
+
55
+ callback :audio_stats do
56
+ show "Audio is: "
57
+ show " -> sample_rate: #{stats[:audio_sample_rate]} Hz"
58
+ show " -> audio_channels: #{stats[:audio_channels]}"
59
+ show " -> audio_format: #{stats[:audio_format]}"
60
+ show " -> data_rate: #{stats[:audio_data_rate]} kb/s"
61
+ end
62
+
63
+ callback :video_stats do
64
+ show "Video is: "
65
+ show " -> fourCC: #{stats[:video_fourcc]}"
66
+ show " -> x_size: #{stats[:video_x_size]}"
67
+ show " -> y_size: #{stats[:video_y_size]}"
68
+ show " -> bpp: #{stats[:video_bpp]}"
69
+ show " -> fps: #{stats[:video_fps]}"
70
+ end
71
+
72
+ callback :position do |position|
73
+ show "Song position percent: #{position}%"
74
+ end
75
+
76
+ callback :played_seconds do |val|
77
+ total = stats[:total_time]
78
+ show "song position in seconds: #{val} / #{total}"
79
+ end
80
+
81
+ callback :pause, :unpause do |pause_state|
82
+ show "song state: " + (pause_state ? "PAUSED!" : "RESUMED!")
83
+ end
84
+
85
+ callback :play do
86
+ show "song started!"
87
+ end
88
+
89
+ callback :stop do
90
+ show "song ended!"
91
+ puts "final stats were: #{stats.inspect}"
92
+ end
93
+ end
94
+
95
+ # play a file from the command line
96
+ raise "usage: #{$0} <file>" if ARGV.length != 1
97
+
98
+ MyApp.new(ARGV[0]).run!
@@ -0,0 +1,15 @@
1
+ #!/bin/env ruby
2
+
3
+ require 'pathname'
4
+ $LOAD_PATH << File.join(File.dirname(Pathname.new(__FILE__).realpath),'../lib')
5
+ require 'easy_mplayer'
6
+
7
+ # play a file from the command line
8
+ raise "usage: #{$0} <file>" if ARGV.length != 1
9
+
10
+ # the absolute minimal script. Just hand over everything
11
+ # to mplayer, blocking until it's over
12
+ mplayer = MPlayer.new( :path => ARGV[0] )
13
+ mplayer.play_to_end
14
+
15
+ puts "all done!"
@@ -0,0 +1,17 @@
1
+ require 'color_debug_messages'
2
+ require 'open3'
3
+ require 'facets/kernel/returning'
4
+ require 'facets/kernel/meta_class'
5
+ require 'facets/kernel/meta_def'
6
+
7
+ class MPlayer
8
+ include ColorDebugMessages
9
+ end
10
+
11
+ require 'easy_mplayer/errors'
12
+ require 'easy_mplayer/commands'
13
+ require 'easy_mplayer/callback'
14
+ require 'easy_mplayer/worker'
15
+ require 'easy_mplayer/main'
16
+ require 'easy_mplayer/helpers'
17
+