mplayer-ruby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,121 @@
1
+ module MPlayer
2
+ module SlaveSubCommands
3
+
4
+ # Adjust the subtitle delay
5
+ # :relative is adjust by +/- <value> seconds.
6
+ # :absolute is set it to <value>. (default)
7
+ def sub_delay(value,type = :absolute)
8
+ adjust_set :sub_delay, value, type
9
+ end
10
+
11
+ # Step forward in the subtitle list by <value> steps
12
+ # step backwards if <value> is negative
13
+ # can also set type to :backward or :forward and return postive <value>
14
+ def sub_step(value, type = :next)
15
+ val = value.abs
16
+ type = :prev if value < 0
17
+ command(type == :next ? "sub_step #{val}" : "sub_step #{-val}" )
18
+ end
19
+
20
+ # Adjust/set subtitle position.
21
+ # If :relative, modifies parameter by <value>.
22
+ # If :absolute, parameter is set to <value>.
23
+ def sub_pos(value,type = :relative)
24
+ adjust_set :sub_pos, value, type
25
+ end
26
+
27
+ # Toggle/set subtitle alignment. [alignment]
28
+ # :top sets top alignment
29
+ # :center sets center alignment
30
+ # :bottom sets bottom alignment
31
+ def sub_alignment(alignment = nil)
32
+ command case alignment
33
+ when :top then "sub_alignment 0"
34
+ when :center then "sub_alignment 1"
35
+ when :bottom then "sub_alignment 2"
36
+ else "sub_alignment"
37
+ end
38
+ end
39
+
40
+ # Toggle/set subtitle visibility.
41
+ # :on turns on visilibity.
42
+ # :off turns off visilibility.
43
+ # else toggles visibility.
44
+ def sub_visibility(value = nil)
45
+ toggle :sub_visibility, value
46
+ end
47
+
48
+ # Loads subtitles from <file>.
49
+ def sub_load(file)
50
+ raise ArgumentError, "Invalid File" unless File.exists? file
51
+ command("sub_load #{file}")
52
+ end
53
+
54
+ # Removes the selected sub file
55
+ # :all removes all sub files. (Default)
56
+ # <value> removes the sub file at that index.
57
+ def sub_remove(value = :all)
58
+ cmd = (value == :all ? -1 : value)
59
+ command "sub_remove #{cmd}"
60
+ end
61
+
62
+ # Displays subtitle
63
+ # :cycle will cycle through all sub_titles. (Default)
64
+ # <value> will display the sub_title at that index.
65
+ def sub_select(value = :cycle)
66
+ cmd = (value == :cycle ? -2 : value)
67
+ command "sub_select #{cmd}"
68
+ end
69
+
70
+ # Display first subtitle from <value>
71
+ # :sub for SUB_SOURCE_SUBS for file subs
72
+ # :vobsub for SUB_SOURCE_VOBSUB for VOBsub files
73
+ # :demux SUB_SOURCE_DEMUX for subtitle embedded in the media file or DVD subs.
74
+ # :off will turn off subtitle display.
75
+ # :cycle will cycle between the first subtitle of each currently available sources.
76
+ def sub_source(value = :cycle)
77
+ switch = case value
78
+ when :sub then 0
79
+ when :vobsub then 1
80
+ when :demux then 2
81
+ when :off then -1
82
+ else -2
83
+ end
84
+ command "sub_source #{switch}"
85
+ end
86
+
87
+ # Display subtitle specifid by <value> for file subs. corresponding to ID_FILE_SUB_ID
88
+ # :off turns off sub
89
+ # :cycle will cycle all file subs. (Default)
90
+ def sub_vob(value = :cycle)
91
+ select_cycle :sub_vob, value
92
+ end
93
+
94
+ # Display subtitle specifid by <value> for file subs. corresponding to ID_VOBSUB_ID
95
+ # :off turns off sub
96
+ # :cycle will cycle all file subs. (Default)
97
+ def sub_file(value = :cycle)
98
+ select_cycle :sub_file, value
99
+ end
100
+
101
+ # Display subtitle specifid by <value> for file subs. corresponding to ID_SUBTITLE_ID
102
+ # :off turns off sub
103
+ # :cycle will cycle all file subs. (Default)
104
+ def sub_demux(value = :cycle)
105
+ select_cycle :sub_demux, value
106
+ end
107
+
108
+ # Adjust the subtitle size by +/- <value>
109
+ # :set set it to <value>
110
+ # :relative adjusts it by value
111
+ def sub_scale(value,type = :relative)
112
+ adjust_set :sub_scale, value, type
113
+ end
114
+
115
+ # Toggle/set forced subtitles only
116
+ def forced_subs_only(value = nil)
117
+ toggle :forced_subs_only, value
118
+ end
119
+
120
+ end
121
+ end
@@ -0,0 +1,99 @@
1
+ module MPlayer
2
+ module SlaveTvCommands
3
+
4
+ # Start automatic TV channel scanning
5
+ def tv_start_scan
6
+ command("tv_start_scan")
7
+ end
8
+
9
+ # Select the next/previous TV Channel
10
+ # :next selects next channel
11
+ # :prev select previous channel
12
+ def tv_step_channel(action)
13
+ value = action == :prev ? -1 : 1
14
+ command "tv_step_channel #{value}"
15
+ end
16
+
17
+ # next TV channel
18
+ def next_channel
19
+ tv_step_channel :next
20
+ end
21
+
22
+ #previous TV channel
23
+ def prev_channel
24
+ tv_step_channel :prev
25
+ end
26
+
27
+ # Change TV norm
28
+ def tv_step_norm
29
+ command("tv_step_norm")
30
+ end
31
+
32
+ # Change TV Channel list
33
+ def tv_step_chanlist
34
+ command("tv_step_chanlist")
35
+ end
36
+
37
+ # Set TV Channel to <value>
38
+ def tv_set_channel(value)
39
+ command("tv_set_channel #{value}")
40
+ end
41
+ alias :set_channel :tv_set_channel
42
+
43
+ # Set the current TV Channel to the last channel
44
+ def tv_last_channel
45
+ command("tv_last_channel")
46
+ end
47
+ alias :last_channel :tv_last_channel
48
+
49
+ # set TV Frequency in MHz
50
+ def tv_set_freq(value)
51
+ command("tv_set_freq #{value}")
52
+ end
53
+
54
+ # set the TV frequency relative to the current frequency
55
+ def tv_step_freq(value)
56
+ command("tv_step_freq #{value}")
57
+ end
58
+
59
+ # Set the TV tuner norm (PAL, SECAM, NTSC, ... ).
60
+ def tv_set_norm(value)
61
+ command("tv_set_norm #{value.to_s.upcase}")
62
+ end
63
+
64
+ # Set/adjust video parameters.
65
+ # If :relative, modifies parameter by <value>.
66
+ # If :absolute, parameter is set to <value>.
67
+ # <value> is in the range [-100, 100].
68
+ def tv_set_contrast(value, type = :relative)
69
+ setting :tv_set_contrast, value, type
70
+ end
71
+
72
+ # Set/adjust video parameters.
73
+ # If :relative, modifies parameter by <value>.
74
+ # If :absolute, parameter is set to <value>.
75
+ # <value> is in the range [-100, 100].
76
+ def tv_set_hue(value, type = :relative)
77
+ setting :tv_set_hue, value, type
78
+ end
79
+
80
+ # Set/adjust video parameters.
81
+ # If :relative, modifies parameter by <value>.
82
+ # If :absolute, parameter is set to <value>.
83
+ # <value> is in the range [-100, 100].
84
+ def tv_set_brightness(value, type = :relative)
85
+ setting :tv_set_brightness, value, type
86
+ end
87
+
88
+ # Set/adjust video parameters.
89
+ # If :relative, modifies parameter by <value>.
90
+ # If :absolute, parameter is set to <value>.
91
+ # <value> is in the range [-100, 100].
92
+ def tv_set_saturation(value, type = :relative)
93
+ setting :tv_set_saturation, value, type
94
+ end
95
+
96
+
97
+
98
+ end
99
+ end
@@ -1,40 +1,25 @@
1
1
  module MPlayer
2
2
  module SlaveVideoCommands
3
-
3
+
4
4
  # Set/adjust the audio delay.
5
5
  # If type is :relative adjust the delay by <value> seconds.
6
6
  # If type is :absolute, set the delay to <value> seconds.
7
7
  def audio_delay(value,type = :relative)
8
8
  adjust_set :audio_delay, value, type
9
9
  end
10
-
11
- # Adjust the subtitle delay
12
- # :relative is adjust by +/- <value> seconds.
13
- # :absolute is set it to <value>. (default)
14
- def sub_delay(value,type = :absolute)
15
- adjust_set :sub_delay, value, type
16
- end
17
10
 
18
- # Step forward in the subtitle list by <value> steps
19
- # step backwards if <value> is negative
20
- # can also set type to :backward or :forward and return postive <value>
21
- def sub_step(value, type = :forward)
22
- type = :backward if value < 0
23
- send(type == :forward ? "sub_step #{value.abs}" : "sub_step -#{value.abs}" )
24
- end
25
-
26
11
  # Toggle OSD mode
27
12
  # or set it to <level>
28
13
  def osd(level=nil)
29
- send(level.nil? ? "osd" : "osd #{level}")
14
+ command(level.nil? ? "osd" : "osd #{level}")
30
15
  end
31
16
 
32
17
  # Show <string> on the OSD.
33
18
  # :duration sets the length to display text.
34
19
  # :level sets the osd level to display at. (default: 0 => always show)
35
20
  def osd_show_text(string,options = {})
36
- options.reverse_merge!({:duration => 0, :level => 0})
37
- send("osd_show_text #{string} #{options[:duration]} #{options[:level]}")
21
+ options = {:duration => 0, :level => 0}.merge(options)
22
+ command("osd_show_text #{string} #{options[:duration]} #{options[:level]}")
38
23
  end
39
24
 
40
25
  # Show an expanded property string on the OSD
@@ -42,10 +27,10 @@ module MPlayer
42
27
  # :duration sets the length to display text.
43
28
  # :level sets the osd level to display at. (default: 0 => always show)
44
29
  def osd_show_property_text(string,options={})
45
- options.reverse_merge!({:duration => 0, :level => 0})
46
- send("osd_show_property_text #{string} #{options[:duration]} #{options[:level]}")
30
+ options = {:duration => 0, :level => 0}.merge(options)
31
+ command("osd_show_property_text #{string} #{options[:duration]} #{options[:level]}")
47
32
  end
48
-
33
+
49
34
  # Set/adjust video parameters.
50
35
  # If :relative, modifies parameter by <value>.
51
36
  # If :absolute, parameter is set to <value>.
@@ -85,7 +70,7 @@ module MPlayer
85
70
  def saturation(value, type = :relative)
86
71
  setting :saturation, value, type
87
72
  end
88
-
73
+
89
74
  # Toggle/set frame dropping mode
90
75
  # if :on, turns on dropping mode
91
76
  # if :off, turns off dropping mode
@@ -94,101 +79,6 @@ module MPlayer
94
79
  toggle :frame_drop, value
95
80
  end
96
81
 
97
- # Adjust/set subtitle position.
98
- # If :relative, modifies parameter by <value>.
99
- # If :absolute, parameter is set to <value>.
100
- def sub_pos(value,type = :relative)
101
- adjust_set :sub_pos, value, type
102
- end
103
-
104
- # Toggle/set subtitle alignment. [alignment]
105
- # :top sets top alignment
106
- # :center sets center alignment
107
- # :bottom sets bottom alignment
108
- def sub_alignment(alignment = nil)
109
- send case alignment
110
- when :top then "sub_alignment 0"
111
- when :center then "sub_alignment 1"
112
- when :bottom then "sub_alignment 2"
113
- else "sub_alignment"
114
- end
115
- end
116
-
117
- # Toggle/set subtitle visibility.
118
- # :on turns on visilibity.
119
- # :off turns off visilibility.
120
- # else toggles visibility.
121
- def sub_visibility(value = nil)
122
- toggle :sub_visibility, value
123
- end
124
-
125
- # Loads subtitles from <file>.
126
- def sub_load(file)
127
- raise ArgumentError, "Invalid File" unless File.exists? file
128
- send("sub_load #{file}")
129
- end
130
-
131
- # Removes the selected sub file
132
- # :all removes all sub files. (Default)
133
- # <value> removes the sub file at that index.
134
- def sub_remove(value = :all)
135
- cmd = (value == :all ? -1 : value)
136
- send "sub_remove #{cmd}"
137
- end
138
-
139
- # Displays subtitle
140
- # :cycle will cycle through all sub_titles. (Default)
141
- # <value> will display the sub_title at that index.
142
- def sub_select(value = :cycle)
143
- cmd = (value == :cycle ? -2 : value)
144
- send "sub_select #{cmd}"
145
- end
146
-
147
- # Display first subtitle from <value>
148
- # :sub for SUB_SOURCE_SUBS for file subs
149
- # :vobsub for SUB_SOURCE_VOBSUB for VOBsub files
150
- # :demux SUB_SOURCE_DEMUX for subtitle embedded in the media file or DVD subs.
151
- # :off will turn off subtitle display.
152
- # :cycle will cycle between the first subtitle of each currently available sources.
153
- def sub_source(value = :cycle)
154
- switch = case value
155
- when :sub then 0
156
- when :vobsub then 1
157
- when :demux then 2
158
- when :off then -1
159
- when :cycle then -2
160
- end
161
- send "sub_source #{switch}"
162
- end
163
-
164
- # Display subtitle specifid by <value> for file subs. corresponding to ID_FILE_SUB_ID
165
- # :off turns off sub
166
- # :cycle will cycle all file subs. (Default)
167
- def sub_vob(value = :cycle)
168
- select_cycle :sub_vob, value
169
- end
170
-
171
- # Display subtitle specifid by <value> for file subs. corresponding to ID_VOBSUB_ID
172
- # :off turns off sub
173
- # :cycle will cycle all file subs. (Default)
174
- def sub_file(value = :cycle)
175
- select_cycle :sub_file, value
176
- end
177
-
178
- # Display subtitle specifid by <value> for file subs. corresponding to ID_SUBTITLE_ID
179
- # :off turns off sub
180
- # :cycle will cycle all file subs. (Default)
181
- def sub_demux(value = :cycle)
182
- select_cycle :sub_demux, value
183
- end
184
-
185
- # Adjust the subtitle size by +/- <value>
186
- # :set set it to <value>
187
- # :relative adjusts it by value
188
- def sub_scale(value,type = :relative)
189
- adjust_set :sub_scale, value, type
190
- end
191
-
192
82
  # switch_audio [value] (currently MPEG*, AVI, Matroska and streams handled by libavformat)
193
83
  # <value> Switch to the audio track with the ID <value>.
194
84
  # :cycle available tracks if [value] is omitted or negative.
@@ -213,7 +103,7 @@ module MPlayer
213
103
  # <value> Change aspect ratio at runtime. [value] is the new aspect ratio expressed
214
104
  # as a float (e.g. 1.77778 for 16/9).
215
105
  # There might be problems with some video filters.
216
- def switch_ratio(value); send("switch_ratio #{value}"); end
106
+ def switch_ratio(value); command("switch_ratio #{value}"); end
217
107
 
218
108
  # switch_vsync [value]
219
109
  # :on Toggle vsync on
@@ -222,7 +112,131 @@ module MPlayer
222
112
  def switch_vsync(value = nil)
223
113
  toggle :switch_vsync, value
224
114
  end
225
-
226
-
115
+
116
+ # Toggle/set borderless display
117
+ # :on Toggle on
118
+ # :off Toggle off
119
+ # nil for Toggle
120
+ def vo_border(value = nil)
121
+ toggle :vo_border, value
122
+ end
123
+
124
+ # Toggle/set borderless display
125
+ # :on Toggle on
126
+ # :off Toggle off
127
+ # nil for Toggle
128
+ def vo_border(value = nil)
129
+ toggle :vo_border, value
130
+ end
131
+
132
+ # Toggle/set fullscreen mode
133
+ # :on Toggle on
134
+ # :off Toggle off
135
+ # nil for Toggle
136
+ def vo_fullscreen(value = nil)
137
+ toggle :vo_fullscreen, value
138
+ end
139
+
140
+ # Toggle/set stay-on-top
141
+ # :on Toggle on
142
+ # :off Toggle off
143
+ # nil for Toggle
144
+ def vo_ontop(value = nil)
145
+ toggle :vo_ontop, value
146
+ end
147
+
148
+ # Toggle/set playback on root window
149
+ # :on Toggle on
150
+ # :off Toggle off
151
+ # nil for Toggle
152
+ def vo_rootwin(value = nil)
153
+ toggle :vo_rootwin, value
154
+ end
155
+
156
+ # Take a screenshot. Requires the screenshot filter to be loaded.
157
+ # nil Take a single screenshot.
158
+ # :toggle Start/stop taking screenshot of each frame.
159
+ def screenshot(toggle=nil)
160
+ switch, pattern = case toggle
161
+ when :toggle
162
+ [ 1, // ]
163
+ else
164
+ [ 0, /screenshot/ ]
165
+ end
166
+ (command("screenshot #{switch}", pattern)) =~ /(shot\d*\.png)/ ? $~[1] : ""
167
+ end
168
+
169
+ # Increases or descreases the panscan range by <value>. maximum is 1.0.
170
+ def panscan(value)
171
+ raise ArgumentError, "Value out of Range -1.0 .. 1.0" unless value.abs <= 1
172
+ command "panscan #{value} 0"
173
+ end
174
+
175
+ # presses the given dvd button
176
+ # available buttons are:
177
+ # :up :down :left :right :menu :select :prev :mouse
178
+ def dvdnav(button)
179
+ unless %w[up down left right menu select prev mouse].include? button.to_s
180
+ raise ArgumentError, "Invalid button name"
181
+ end
182
+ command "dvdnav #{button}"
183
+ end
184
+
185
+ # Print out the current value of a property.
186
+ # raises an error if it fails to get the property
187
+ def get_property(value)
188
+ resp = command("get_property #{value}",/#{value.to_s}/).gsub(/ANS(.+?)\=/,"")
189
+ raise StandardError,resp if resp =~ /Failed/
190
+ resp
191
+ end
192
+
193
+ #Set the value to a property
194
+ def set_property(name,value)
195
+ command "set_property #{name} #{value}"
196
+ end
197
+
198
+ #adjust the propery by steps
199
+ # if value is < 0, steps downards
200
+ # else, steps upward
201
+ def step_property(name,value)
202
+ direction = value < 0 ? -1 : 1
203
+ command "step_property #{name} #{value.abs} #{direction}"
204
+ end
205
+
206
+ # Returns if it is in fullscreen mode.
207
+ # true if it is fullscreen
208
+ # false if it is windowed
209
+ def get_vofullscreen
210
+ resp = command "get_vofullscreen",/(0|1)/
211
+ return true if resp =~ /1/
212
+ false
213
+ end
214
+ alias :is_fullscreen? :get_vofullscreen
215
+
216
+ # Returns if it the sub is visibile mode.
217
+ # true if it is fullscreen
218
+ # false if it is windowed
219
+ def get_sub_visibility
220
+ resp = command "get_sub_visibility",/(0|1)/
221
+ return true if resp =~ /1/
222
+ false
223
+ end
224
+ alias :is_sub_visible? :get_sub_visibility
225
+
226
+ # Seek to the start of a chapter
227
+ # :relative does a relative seek (+/-)
228
+ # :absolute goes to the exact value of chapter
229
+ def seek_chapter(value, type = :relative)
230
+ adjust_set :seek_chapter, value, type
231
+ end
232
+
233
+ def change_rectangle(coord,value,type = :relative)
234
+ switch = case coord
235
+ when :x then (0 + (type == :relative ? 2 : 0))
236
+ when :y then (1 + (type == :relative ? 2 : 0))
237
+ end
238
+ command("change_rectangle #{switch} #{value}")
239
+ end
240
+
227
241
  end
228
- end
242
+ end