mplayer-ruby 0.1.0 → 0.2.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e9ad024a90484d39f8b1efac03b369665c742977
4
+ data.tar.gz: 8740c2eca2d6800d8d51ae13759b066e04b3d688
5
+ SHA512:
6
+ metadata.gz: b5179590bd43f0759dc993d7eeda0a45a7de9ec21b71eeed7d7a32a8f784a82564134db3dc314daab2010ae7d19066c28b4df2fb584c2a70b9cf904d32fca605
7
+ data.tar.gz: 5627fdd4bdbd058d368811e60750f31eadfbb78db7988fe8ba11d68a115bd80f0a93f4fe86c769eb05f67cb92e27b4a8ac19e11660ee6a6807d89bebc5263c58
data/.gitignore CHANGED
@@ -17,5 +17,6 @@ tmtags
17
17
  coverage
18
18
  rdoc
19
19
  pkg
20
+ Gemfile.lock
20
21
 
21
22
  ## PROJECT::SPECIFIC
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - ruby-head
7
+ script: bundle exec rake
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: 1.8.7
11
+ - rvm: ruby-head
@@ -0,0 +1,31 @@
1
+ # Change Log
2
+
3
+ ## [Unreleased](https://github.com/petems/mplayer-ruby/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/petems/mplayer-ruby/compare/v0.1.0...HEAD)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Merge pull requests 8 and 9 [\#10](https://github.com/petems/mplayer-ruby/pull/10) ([arirusso](https://github.com/arirusso))
10
+
11
+ - Enable passing arbitrary command-line options on startup [\#9](https://github.com/petems/mplayer-ruby/pull/9) ([arirusso](https://github.com/arirusso))
12
+
13
+ - Add option to start in fullscreen [\#8](https://github.com/petems/mplayer-ruby/pull/8) ([arirusso](https://github.com/arirusso))
14
+
15
+ - Quote filename for load\_file and load\_list commands [\#6](https://github.com/petems/mplayer-ruby/pull/6) ([dfyx](https://github.com/dfyx))
16
+
17
+ - Let operating system find mplayer [\#5](https://github.com/petems/mplayer-ruby/pull/5) ([dfyx](https://github.com/dfyx))
18
+
19
+ - Fix HTTP leading to "Invalid File" error [\#4](https://github.com/petems/mplayer-ruby/pull/4) ([dfyx](https://github.com/dfyx))
20
+
21
+ - Allow media file names with spaces in them \(Second try, now with working tests\) [\#3](https://github.com/petems/mplayer-ruby/pull/3) ([cmol](https://github.com/cmol))
22
+
23
+ - Merging in @freenerd's URI support stuff, looks good... [\#1](https://github.com/petems/mplayer-ruby/pull/1) ([petems](https://github.com/petems))
24
+
25
+ - Edit: Add quotes around the media file parameter for mplayer [\#2](https://github.com/petems/mplayer-ruby/pull/2) ([cmol](https://github.com/cmol))
26
+
27
+ ## [v0.1.0](https://github.com/petems/mplayer-ruby/tree/v0.1.0) (2010-02-01)
28
+
29
+
30
+
31
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -1,51 +1,39 @@
1
- = mplayer-ruby
1
+ # mplayer-ruby [![Build Status](https://travis-ci.org/petems/mplayer-ruby.svg?branch=master)](https://travis-ci.org/petems/mplayer-ruby)
2
2
 
3
3
  A Ruby Wrapper for MPlayer. Controls MPlayer via the Slave Protocol.
4
4
 
5
+ See [RDOC](http://mplayer-ruby.rubyforge.org/mplayer-ruby/index.html) for additional information.
5
6
 
6
- See examples/ for usage.
7
+ See [examples/](http://github.com/petems/mplayer-ruby/tree/master/examples/) for usage.
7
8
 
8
9
 
9
- == Installation
10
+ ## Installation
10
11
 
11
12
 
12
- === MPlayer
13
+ ### MPlayer
13
14
 
14
- ==== Linux
15
+ #### Linux
15
16
 
16
17
  $ sudo apt-get install mplayer
17
-
18
- ==== Mac OS X
19
18
 
20
- ===== via Homebrew
19
+ #### Mac OS X
21
20
 
22
- $ brew install mplayer
23
-
24
- ===== via download
25
-
26
- download (Mac OS X Extended)[http://www.mplayerhq.hu/homepage/design7/news.html].
27
-
28
- then create a symbolic link for mplayer.
29
-
30
- $ sudo ln -s "/Applications/MPlayer OSX Extended.app/Contents/Resources/External_Binaries/mplayer.app/Contents/MacOS/mplayer" /usr/bin/mplayer
31
-
32
- === MPlayer-ruby
21
+ ##### via Homebrew
33
22
 
34
- It's hosted on gemcutter.org
35
-
36
- $ sudo gem install mplayer-ruby
23
+ $ brew install mplayer
37
24
 
25
+ ### MPlayer-ruby
38
26
 
27
+ $ gem install mplayer-ruby
39
28
 
40
- == TODO
41
- * Complete Slave Protocol
42
- * Complete Other Functionalities
29
+ ## TODO
30
+ * Complete Slave Protocol
31
+ * Complete Other Functionalities
43
32
  * Create a Better README
44
- * RDoc?
45
33
  * Example Usages
46
34
 
47
- == Note on Patches/Pull Requests
48
-
35
+ ## Note on Patches/Pull Requests
36
+
49
37
  * Fork the project.
50
38
  * Make your feature addition or bug fix.
51
39
  * Add tests for it. This is important so I don't break it in a
@@ -54,6 +42,6 @@ It's hosted on gemcutter.org
54
42
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
55
43
  * Send me a pull request. Bonus points for topic branches.
56
44
 
57
- == Copyright
45
+ ## Copyright
58
46
 
59
47
  Copyright (c) 2010 Arthur Chiu. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,24 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "mplayer-ruby"
8
- gem.summary = %Q{Ruby wrapper for MPlayer}
9
- gem.description = %Q{A Ruby wrapper for MPlayer}
10
- gem.email = "mr.arthur.chiu@gmail.com"
11
- gem.homepage = "http://github.com/achiu/mplayer-ruby"
12
- gem.authors = ["Arthur Chiu"]
13
- gem.add_development_dependency "riot", ">= 0.10.11"
14
- gem.add_development_dependency "rr", ">=0.10.5"
15
- gem.add_dependency "open4", ">=1.0.1"
16
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
- end
3
+ require 'bundler/gem_tasks'
22
4
 
23
5
  require 'rake/testtask'
24
6
  Rake::TestTask.new(:test) do |test|
@@ -40,8 +22,6 @@ rescue LoadError
40
22
  end
41
23
  end
42
24
 
43
- task :test => :check_dependencies
44
-
45
25
  begin
46
26
  require 'reek/adapters/rake_task'
47
27
  Reek::RakeTask.new do |t|
@@ -57,7 +37,7 @@ end
57
37
 
58
38
  task :default => :test
59
39
 
60
- require 'rake/rdoctask'
40
+ require 'rdoc/task'
61
41
  Rake::RDocTask.new do |rdoc|
62
42
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
63
43
 
data/TODO CHANGED
@@ -1,44 +1,10 @@
1
1
 
2
2
  Slave Commands:
3
-
4
- balance Float
5
- tv_start_scan
6
- tv_step_channel Integer
7
- tv_step_norm
8
- tv_step_chanlist
9
- tv_set_channel String
10
- tv_last_channel
11
- tv_set_freq Float
12
- tv_step_freq Float
13
- tv_set_norm String
14
- tv_set_brightness Integer [Integer]
15
- tv_set_contrast Integer [Integer]
16
- tv_set_hue Integer [Integer]
17
- tv_set_saturation Integer [Integer]
18
- forced_subs_only [Integer]
19
- switch_ratio [Float]
20
- vo_fullscreen [Integer]
21
- vo_ontop [Integer]
22
3
  file_filter Integer
23
- vo_rootwin [Integer]
24
- vo_border [Integer]
25
- screenshot [Integer]
26
- panscan Float [Integer]
27
- switch_vsync [Integer]
28
- loadfile String [Integer]
29
- loadlist String [Integer]
30
4
  run String
31
- change_rectangle Integer Integer
32
- dvdnav String
33
- get_vo_fullscreen
34
- get_sub_visibility
35
5
  key_down_event Integer
36
- set_property String String
37
- get_property String
38
- step_property String [Float] [Integer]
39
- seek_chapter Integer [Integer]
40
6
  set_mouse_pos Integer Integer
41
- vobsub_lang [Integer]
7
+ vobsub_lang [Integer] - stub linked
42
8
  sub_log
43
9
 
44
10
  Player Options
@@ -1,60 +1,60 @@
1
1
  require File.join(File.dirname(__FILE__),'..','lib','mplayer-ruby')
2
2
 
3
- $player = MPlayer::Slave.new '/Volumes/Storage/Music/segundo.ogg', :path => '/usr/bin/mplayer' #defauults to /usr/bin/mplayer
3
+ @player = MPlayer::Slave.new '/Volumes/Storage/Music/segundo.ogg', :path => '/usr/bin/mplayer' #defauults to /usr/bin/mplayer
4
4
 
5
- puts $player.volume :up
5
+ puts @player.volume :up
6
6
  sleep 5
7
- puts $player.volume :down
7
+ puts @player.volume :down
8
8
  sleep 5
9
- puts $player.volume :set, 60
9
+ puts @player.volume :set, 60
10
10
  sleep 5
11
- load file and play immediately
12
- puts $player.load_file "/Volumes/Storage/Music/primero.ogg", :no_append
11
+ # load file and play immediately
12
+ puts @player.load_file "/Volumes/Storage/Music/primero.ogg", :no_append
13
13
 
14
14
  sleep 10
15
15
 
16
16
  # load file and queue
17
17
  # load_file(file) defaults to :append
18
- puts $player.load_file "/Volumes/Storage/Music/segundo.ogg", :append
18
+ puts @player.load_file "/Volumes/Storage/Music/segundo.ogg", :append
19
19
 
20
20
  sleep 10
21
21
  # step forward
22
- puts $player.next 1
22
+ puts @player.next 1
23
23
  sleep 10
24
24
  # step backward
25
- puts $player.back 1
25
+ puts @player.back 1
26
26
 
27
27
  sleep 10
28
28
 
29
29
  # returns information on the file
30
- $player.get :meta_artist
31
- $player.get :meta_album
32
- $player.get :meta_track
30
+ @player.get :meta_artist
31
+ @player.get :meta_album
32
+ @player.get :meta_track
33
33
  %w[time_pos time_length file_name video_codec video_bitrate video_resolution
34
34
  audio_codec audio_bitrate audio_samples meta_title meta_artist meta_album
35
35
  meta_year meta_comment meta_track meta_genre].each do |line|
36
- puts $player.get line
36
+ puts @player.get line
37
37
  end
38
38
 
39
39
  # time_position. fields can also be called as methods
40
- puts $player.time_position
41
- puts $player.year
40
+ puts @player.time_position
41
+ puts @player.year
42
42
 
43
43
  # mute
44
- puts $player.mute :on
44
+ puts @player.mute :on
45
45
  sleep 10
46
- puts $player.mute # toggles back to off
46
+ puts @player.mute # toggles back to off
47
47
  # seek to position in song
48
- puts $player.seek 2
49
- puts $player.seek 10, :percent
50
- puts $player.seek 20, :absolute
48
+ puts @player.seek 2
49
+ puts @player.seek 10, :percent
50
+ puts @player.seek 20, :absolute
51
51
 
52
52
  # sets the speed of playback
53
- puts ($player.speed 2,:increment)
54
- puts $player.speed 2,:multiply
55
- puts $player.speed 1
53
+ puts @player.speed 2,:increment
54
+ puts @player.speed 2,:multiply
55
+ puts @player.speed 1
56
56
 
57
57
  # quits MPlayer
58
- puts $player.quit
58
+ puts @player.quit
59
59
 
60
60
 
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'open4'
3
- require 'active_support/core_ext/hash'
4
3
  require File.dirname(__FILE__) + '/mplayer-ruby/slave_commands'
5
4
  require File.dirname(__FILE__) + '/mplayer-ruby/slave_video_commands'
6
- Dir[File.dirname(__FILE__) + '/mplayer-ruby/**/*.rb'].each { |lib| require lib }
5
+ require File.dirname(__FILE__) + '/mplayer-ruby/slave_tv_commands'
6
+ require File.dirname(__FILE__) + '/mplayer-ruby/slave_sub_commands'
7
+ require File.dirname(__FILE__) + '/mplayer-ruby/slave'
@@ -4,25 +4,32 @@ module MPlayer
4
4
  attr_reader :pid,:stdout,:stderr,:file
5
5
  include MPlayer::SlaveCommands
6
6
  include MPlayer::SlaveVideoCommands
7
-
7
+ include MPlayer::SlaveTvCommands
8
+ include MPlayer::SlaveSubCommands
9
+ require 'uri'
8
10
 
9
11
  # Initializes a new instance of MPlayer.
10
12
  # set :path to point to the location of mplayer
11
13
  # defaults to '/usr/bin/mplayer'
12
- def initialize(file = "",options ={:path => '/usr/bin/mplayer'})
13
- raise ArgumentError,"Invalid File" unless File.exists?(file)
14
+ def initialize(file = "",options ={})
15
+ unless File.exists?(file) || URI::regexp.match(file)
16
+ raise ArgumentError,"Invalid File"
17
+ end
18
+ options[:path] ||= 'mplayer'
14
19
  @file = file
15
- mplayer = "#{options[:path]} -slave -quiet #{@file}"
20
+
21
+ mplayer = invocation(options)
22
+
16
23
  @pid,@stdin,@stdout,@stderr = Open4.popen4(mplayer)
17
24
  until @stdout.gets.inspect =~ /playback/ do
18
- end #fast forward to the desired output
25
+ end #fast forward past mplayer's initial output
19
26
  end
20
27
 
21
- # sends command to mplayer stdin and retrieves stdout.
28
+ # commands command to mplayer stdin and retrieves stdout.
22
29
  # If match is provided, fast-forwards stdout to matching response.
23
- def send(cmd,match = //)
30
+ def command(cmd,match = //)
24
31
  @stdin.puts(cmd)
25
- response = @stdout.gets
32
+ response = ""
26
33
  until response =~ match
27
34
  response = @stdout.gets
28
35
  end
@@ -31,13 +38,29 @@ module MPlayer
31
38
 
32
39
  private
33
40
 
41
+ # Command line string to invoke mplayer
42
+ # @param [Hash] options
43
+ # @option options [Boolean] :fullscreen Whether to start in fullscreen
44
+ # @option options [String] :options Arbitrary command line options
45
+ # @option options [Boolean] :screenshot Whether to enable screenshots
46
+ # @return [String]
47
+ def invocation(options = {})
48
+ path = options[:path] || "mplayer"
49
+ command = "#{path} -slave -quiet "
50
+ command += "-fs " if options[:fullscreen]
51
+ command += "-vf screenshot " if options[:screenshot]
52
+ command += "#{options[:options]} " unless options[:options].nil?
53
+ command += "\"#{@file}\""
54
+ command
55
+ end
56
+
34
57
  def select_cycle(command,value,match = //)
35
58
  switch = case value
36
59
  when :off then -1
37
60
  when :cycle then -2
38
61
  else value
39
62
  end
40
- send "#{command} #{switch}",match
63
+ command "#{command} #{switch}",match
41
64
  end
42
65
 
43
66
  def toggle(command,value,match = //)
@@ -46,17 +69,17 @@ module MPlayer
46
69
  when :off then "#{command} 0"
47
70
  else "#{command}"
48
71
  end
49
- send cmd,match
72
+ command cmd,match
50
73
  end
51
74
 
52
75
  def setting(command,value,type, match = //)
53
76
  raise(ArgumentError,"Value out of Range -100..100") unless (-100..100).include?(value)
54
- adjust_set command, value, type
77
+ adjust_set command, value, type, match
55
78
  end
56
79
 
57
80
  def adjust_set(command,value,type = :relative, match = //)
58
81
  switch = ( type == :relative ? 0 : 1 )
59
- send "#{command} #{value} #{switch}",match
82
+ command "#{command} #{value} #{switch}",match
60
83
  end
61
84
 
62
85
  end
@@ -12,7 +12,7 @@ module MPlayer
12
12
  when :set then "volume #{value} 1"
13
13
  else return false
14
14
  end
15
- resp = send cmd, /Volume/
15
+ resp = command cmd, /Volume/
16
16
  resp.gsub("Volume: ","").gsub(" %\n","")
17
17
  end
18
18
 
@@ -26,7 +26,7 @@ module MPlayer
26
26
  when :absolute then "seek #{value} 2"
27
27
  else "seek #{value} 0"
28
28
  end
29
- resp = send command, /Position/
29
+ resp = command command, /Position/
30
30
  resp.gsub("Position: ","").gsub(" %\n","")
31
31
  end
32
32
 
@@ -47,19 +47,19 @@ module MPlayer
47
47
  # :forever means loop forever.(default)
48
48
  # :set sets the amount of times to loop. defaults to one loop.
49
49
  def loop(action = :forever,value = 1)
50
- send case action
50
+ command case action
51
51
  when :none then "loop -1"
52
52
  when :set then "loop #{value}"
53
53
  else "loop 0"
54
54
  end
55
55
  end
56
56
 
57
- # Go to the next/previous entry in the playtree.
58
- #T he sign of <value> tells the direction.
57
+ # Go to the next/previous entry in the playtree.
58
+ #T he sign of <value> tells the direction.
59
59
  # If no entry is available in the given direction it will do
60
60
  # nothing unless :force
61
61
  def pt_step(value,force = :no_force)
62
- send(force == :force ? "pt_step #{value} 1" : "pt_step #{value} 0")
62
+ command(force == :force ? "pt_step #{value} 1" : "pt_step #{value} 0")
63
63
  end
64
64
 
65
65
  # goes to the next entry in the playlist denoted by value.
@@ -67,22 +67,21 @@ module MPlayer
67
67
  def next(value,force = :no_force)
68
68
  pt_step value.abs, force
69
69
  end
70
-
70
+
71
71
  # goes to the previous entry in the playlist denoted by value.
72
72
  # No action will occur unless :force is specified
73
73
  def back(value,force = :no_force)
74
- v = "-" + value.to_s.gsub("-","")
75
- pt_step v, force
74
+ pt_step -value.abs, force
76
75
  end
77
76
 
78
77
  # Similar to pt_step but jumps to the next/previous entry in the parent list.
79
78
  # Useful to break out of the inner loop in the playtree.
80
79
  def pt_up_step(value,force = :no_force)
81
- send(force == :force ? "pt_up_step #{value} 1" : "pt_up_step #{value} 0")
80
+ command(force == :force ? "pt_up_step #{value} 1" : "pt_up_step #{value} 0")
82
81
  end
83
82
 
84
83
  # Switch volume control between master and PCM.
85
- def use_master; send("use_master"); end
84
+ def use_master; command("use_master"); end
86
85
 
87
86
  # Toggle sound output muting or set it to [value] when [value] >= 0
88
87
  # (1 == on, 0 == off).
@@ -97,14 +96,14 @@ module MPlayer
97
96
  # audio_codec audio_bitrate audio_samples meta_title meta_artist meta_album
98
97
  # meta_year meta_comment meta_track meta_genre
99
98
  def get(value)
100
- match = case value.to_s
99
+ field = value.to_s
100
+ match = case field
101
101
  when "time_pos" then "ANS_TIME_POSITION"
102
102
  when "time_length" then "ANS_LENGTH"
103
103
  when "file_name" then "ANS_FILENAME"
104
- else "ANS_#{value.to_s.upcase}"
104
+ else "ANS_#{field.upcase}"
105
105
  end
106
- resp = send "get_#{value}",/#{match}/
107
- resp.gsub("#{match}=","").gsub("'","")
106
+ command("get_#{value}",/#{match}/).gsub("#{match}=","").gsub("'","")
108
107
  end
109
108
 
110
109
  # This gives methods for each of the fields that data can be extract on.
@@ -128,23 +127,27 @@ module MPlayer
128
127
  # :append loads the file and appends it to the current playlist
129
128
  # :no_append will stop playback and play new loaded file
130
129
  def load_file(file,append = :no_append)
131
- raise ArgumentError,"Invalid File" unless File.exists? file
130
+ unless File.exists?(file) || URI::regexp.match(file)
131
+ raise ArgumentError,"Invalid File"
132
+ end
132
133
  switch = (append == :append ? 1 : 0)
133
- send "loadfile #{file} #{switch}"
134
+ command "loadfile \"#{file}\" #{switch}"
134
135
  end
135
136
 
136
137
  # Loads the playlist into MPlayer
137
138
  # :append loads the playlist and appends it to the current playlist
138
139
  # :no_append will stop playback and play new loaded playlist
139
140
  def load_list(file,append = :no_append)
140
- raise ArgumentError,"Invalid File" unless File.exists? file
141
+ unless File.exists?(file) || URI::regexp.match(file)
142
+ raise ArgumentError,"Invalid File"
143
+ end
141
144
  switch = (append == :append ? 1 : 0)
142
- send "loadlist #{file} #{switch}"
145
+ command "loadlist \"#{file}\" #{switch}"
143
146
  end
144
147
 
145
148
  # When more than one source is available it selects the next/previous one.
146
149
  # ASX Playlist ONLY
147
- def alt_src_step(value); send("alt_src_step #{value}"); end
150
+ def alt_src_step(value); command("alt_src_step #{value}"); end
148
151
 
149
152
  # Add <value> to the current playback speed.
150
153
  def speed_incr(value)
@@ -162,26 +165,31 @@ module MPlayer
162
165
  speed_setting :speed_set, value
163
166
  end
164
167
 
168
+ #set balance to <value>
169
+ def balance(value)
170
+ command("balance #{value}")
171
+ end
172
+
165
173
  # Play one frame, then pause again.
166
- def frame_step; send("frame_step"); end
174
+ def frame_step; command("frame_step"); end
167
175
 
168
176
  # Write the current position into the EDL file.
169
- def edl_mark; send("edl_mark"); end
177
+ def edl_mark; command("edl_mark"); end
170
178
 
171
179
  # Pauses/Unpauses the file.
172
- def pause; send("pause") ; end
180
+ def pause; command("pause") ; end
173
181
 
174
182
  # Quits MPlayer
175
183
  def quit
176
- send('quit')
184
+ command('quit')
177
185
  @stdin.close
178
186
  end
179
187
 
180
188
  private
181
-
189
+
182
190
  def speed_setting(command,value)
183
191
  raise ArgumentError,"Value must be less than 6" unless value <= 5
184
- send("#{command} #{value}",/Speed/).gsub("Speed: x ","")
192
+ command("#{command} #{value}",/Speed/).gsub("Speed: x ","")
185
193
  end
186
194
 
187
195
  end