mplayer.rb 0.0.1

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.
Files changed (3) hide show
  1. data/lib/mplayer.rb +108 -0
  2. data/lib/mplayer_commands.rb +120 -0
  3. metadata +54 -0
data/lib/mplayer.rb ADDED
@@ -0,0 +1,108 @@
1
+ require_relative "./mplayer_commands"
2
+
3
+ class MPlayer
4
+ include MPlayerCommands
5
+ attr_accessor :player_pid,:logfile
6
+
7
+ # returns an instance of MPlayer. The fifo-file to control the related mplayer-process is created. Also
8
+ # an mplayer-instance gests startet.
9
+ #
10
+ # Some Options can be used to describe different asspects of the object.
11
+ # They can be set in the options-hash. Following options are avaiable:
12
+ # * fifo: path to the fifo-file which will be created
13
+ # * logfile: path to a file, where all the std-out and std-err gets stored
14
+ #
15
+ # @param options [Hash] Specifies some options for the mplayer-instance.
16
+ # @return [MPlayer] New MPlayer-object
17
+ def initialize options={fifo: "/tmp/mplayer_rb_#{$$}_fifo",logfile: "/tmp/mplayer_rb_log"}
18
+ @options = options
19
+ self.logfile = File.new(@options[:logfile],"w")
20
+ create_fifo
21
+ start_mplayer
22
+ end
23
+
24
+ # sends a command to the FIFO-file, which controlls the related mplayer-instance.
25
+ # Example:
26
+ # mp = MPlayer.new
27
+ # mp.run("pause) <--send pause-command to mplayer
28
+ #
29
+ # @params cmd [String] The command which should be sent to mplayer
30
+ # @return nil at the moment @TODO:it should return the output of mplayer for the sent command
31
+ def run(cmd)
32
+ File.open(@options[:fifo],"w+") do |f|
33
+ f.puts cmd
34
+ end
35
+ end
36
+
37
+ # override respond_to_missing?, so when a method is called, whichs name is a mplayer-command,
38
+ # the object should respond to it.
39
+ # When not, the standard-behaviour is executed. {Object#respond_to?}
40
+ def respond_to_missing? method,priv
41
+ if COMMANDS.include? method
42
+ return true
43
+ else
44
+ super method,priv
45
+ end
46
+ end
47
+
48
+ # dynamically creates and calls methods when the missing method is a mplayer-command (see COMMANDS)
49
+ def method_missing name,*args
50
+ if COMMANDS.include? name
51
+ with_args = Proc.new do |params|
52
+ if params.is_a? Array
53
+ params = params.map do |param|
54
+ if param.start_with? "/"
55
+ param = "'" + param + "'"
56
+ end
57
+ end
58
+ params = params.join " "
59
+ end
60
+ run "#{name.to_s} #{params}"
61
+ end
62
+ argless = Proc.new do
63
+ run "#{name.to_s}"
64
+ end
65
+ if args.empty?
66
+ self.class.send :define_method, name, &argless
67
+ self.send name
68
+ else
69
+ self.class.send :define_method, name, &with_args
70
+ self.send name, args
71
+ end
72
+ else
73
+ super name,args
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ # creates the fifo-file which will be used to controll the mplayer-instance. It used the path which was
80
+ # specified in the options in #new
81
+ #
82
+ # @return [Fixnum] The process-id of the mkfifo-command
83
+ def create_fifo
84
+ spawn "mkfifo #{@options[:fifo]}", out: self.logfile, err: self.logfile
85
+ end
86
+
87
+ # kill_mplayer kills the related mplayer-instance and deletes all created files.
88
+ #
89
+ # @return [Boolean] True if the mplayer-instance-kill-command succeeded
90
+ def kill_mplayer
91
+ self.logfile.close
92
+ [@options[:logfile],@options[:fifo]].each do |file|
93
+ File.delete(file) if File.exists? file
94
+ end
95
+ system "kill -9 #{self.player_pid.to_s}"
96
+ end
97
+
98
+ # starts the related mplayer-instance and stores the pid of it in the player_pid-attribute
99
+ #
100
+ # @return [Fixnum] The pid of the related mplayer-instance
101
+ def start_mplayer
102
+ at_exit do
103
+ kill_mplayer
104
+ end
105
+
106
+ self.player_pid = spawn("mplayer -slave -idle -quiet -input file=#{@options[:fifo]}", out: self.logfile, err: self.logfile)
107
+ end
108
+ end
@@ -0,0 +1,120 @@
1
+ module MPlayerCommands
2
+ COMMANDS = [
3
+ :af_add,
4
+ :af_clr,
5
+ :af_cmdline,
6
+ :af_del,
7
+ :af_switch,
8
+ :alt_src_step,
9
+ :audio_delay,
10
+ :brightness,
11
+ :contrast,
12
+ :gamma,
13
+ :hue,
14
+ :saturation,
15
+ :capturing,
16
+ :change_rectangle,
17
+ :dvb_set_channel,
18
+ :dvdnav,
19
+ :edl_loadfile,
20
+ :edl_mark,
21
+ :frame_drop,
22
+ :get_audio_bitrate,
23
+ :get_audio_codec,
24
+ :get_audio_samples,
25
+ :get_file_name,
26
+ :get_meta_album,
27
+ :get_meta_artist,
28
+ :get_meta_comment,
29
+ :get_meta_genre,
30
+ :get_meta_title,
31
+ :get_meta_track,
32
+ :get_meta_year,
33
+ :get_percent_pos,
34
+ :get_property,
35
+ :get_sub_visibility,
36
+ :get_time_length,
37
+ :get_time_pos,
38
+ :get_vo_fullscreen,
39
+ :get_video_bitrate,
40
+ :get_video_codec,
41
+ :get_video_resolution,
42
+ :gui,
43
+ :screenshot,
44
+ :key_down_event,
45
+ :loadfile,
46
+ :loadlist,
47
+ :loop,
48
+ :menu,
49
+ :set_menu,
50
+ :mute,
51
+ :osd,
52
+ :osd_show_progression,
53
+ :osd_show_property_text,
54
+ :osd_show_text,
55
+ :panscan,
56
+ :pause,
57
+ :frame_step,
58
+ :pt_step,
59
+ :pt_up_step,
60
+ :quit,
61
+ :radio_set_channel,
62
+ :radio_set_freq,
63
+ :radio_step_channel,
64
+ :radio_step_freq,
65
+ :seek,
66
+ :seek_chapter,
67
+ :switch_angle,
68
+ :set_mouse_pos,
69
+ :set_property,
70
+ :speed_incr,
71
+ :speed_mult,
72
+ :speed_set,
73
+ :step_property,
74
+ :stop,
75
+ :sub_alignment,
76
+ :sub_delay,
77
+ :sub_load,
78
+ :sub_log,
79
+ :sub_pos,
80
+ :sub_remove,
81
+ :sub_select,
82
+ :sub_source,
83
+ :sub_file,
84
+ :sub_vob,
85
+ :sub_demux,
86
+ :sub_scale,
87
+ :vobsub_lang,
88
+ :sub_step,
89
+ :sub_visibility,
90
+ :forced_subs_only,
91
+ :switch_audio,
92
+ :switch_angle,
93
+ :switch_ratio,
94
+ :switch_title,
95
+ :switch_vsync,
96
+ :teletext_add_digit,
97
+ :teletext_go_link,
98
+ :tv_start_scan,
99
+ :tv_step_channel,
100
+ :tv_step_norm,
101
+ :tv_step_chanlist,
102
+ :tv_set_channel,
103
+ :tv_last_channel,
104
+ :tv_set_freq,
105
+ :tv_step_freq,
106
+ :tv_set_norm,
107
+ :tv_set_brightness,
108
+ :tv_set_contrast,
109
+ :tv_set_hue,
110
+ :tv_set_saturation,
111
+ :use_master,
112
+ :vo_border,
113
+ :vo_fullscreen,
114
+ :vo_onstop,
115
+ :vo_rootwin,
116
+ :volume,
117
+ :overlay_add,
118
+ :overlay_remove
119
+ ]
120
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mplayer.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Siegfried Dünkel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-15 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'Just create a new MPlayer-object with something like mp=MPlayer.new.
15
+ An mplayer-instance and a fifo-file, which controlls it will be created.
16
+
17
+ Now you can run mplayer-commands simply by running their names as methods of this
18
+ object or you can call the run-method.
19
+
20
+ For forther description see http://github.com/chaosprinz/mplayer.rb'
21
+ email: chaosprinz76@googlemail.com
22
+ executables: []
23
+ extensions: []
24
+ extra_rdoc_files: []
25
+ files:
26
+ - lib/mplayer.rb
27
+ - lib/mplayer_commands.rb
28
+ homepage: http://github.com/chaosprinz/mplayer.rb
29
+ licenses:
30
+ - MIT
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.23
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Ruby-library for the great mplayer using its slave-protocol
53
+ test_files: []
54
+ has_rdoc: