mpv 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/mpv.rb +2 -1
- data/lib/mpv/callback.rb +36 -0
- data/lib/mpv/client.rb +23 -2
- data/lib/mpv/session.rb +15 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a818d6765d547de2c4b2762fad829c88d276727
|
4
|
+
data.tar.gz: b086dab6ac928bbd5922b9c23fa2d651bc854b03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b31aaf4f3cbc0945d1520267f4d97ad7703790cace3f0acd9f0faa4fc0e05329570b13d2b659cc2f58271f3fd498f1464ab5c59fc3a4cefc5f19e4a9f61b30c
|
7
|
+
data.tar.gz: 2c6ba98059b02017d69e64f51161628cc56b29df54ee8286133f310dfb10df2d9430da9169593733f11b01d81dfe200fed30a934b64acce3e22760df4232f41e
|
data/README.md
CHANGED
@@ -18,12 +18,12 @@ For full documentation, please see the
|
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
# this will be called every time mpv sends an event back over the socket
|
21
|
-
def
|
22
|
-
puts "look ma! a callback: #{event}"
|
21
|
+
def something_happened(event)
|
22
|
+
puts "look ma! a callback: #{event.to_s}"
|
23
23
|
end
|
24
24
|
|
25
25
|
session = MPV::Session.new # contains both a MPV::Server and a MPV::Client
|
26
|
-
session.client.callbacks << self
|
26
|
+
session.client.callbacks << MPV::Callback.new(self, :something_happened)
|
27
27
|
session.client.get_property "pause"
|
28
28
|
session.client.command "get_version"
|
29
29
|
session.client.command "loadlist", "my_huge_playlist.txt", "append"
|
data/lib/mpv.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require_relative "mpv/callback"
|
1
2
|
require_relative "mpv/client"
|
2
3
|
require_relative "mpv/server"
|
3
4
|
require_relative "mpv/session"
|
@@ -5,5 +6,5 @@ require_relative "mpv/session"
|
|
5
6
|
# The toplevel namespace for ruby-mpv.
|
6
7
|
module MPV
|
7
8
|
# The current version of ruby-mpv.
|
8
|
-
VERSION = "1.
|
9
|
+
VERSION = "1.1.0".freeze
|
9
10
|
end
|
data/lib/mpv/callback.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module MPV
|
2
|
+
# Encapsulates an object-method pair that will be invoked whenever
|
3
|
+
# an {MPV::Client} receives an event.
|
4
|
+
class Callback
|
5
|
+
# @return [Object] the object that the callback will be issued to
|
6
|
+
attr_accessor :object
|
7
|
+
|
8
|
+
# @return [Symbol] the method that the callback will invoke
|
9
|
+
attr_accessor :method
|
10
|
+
|
11
|
+
# @param object [Object] the object that the callback will be issued to
|
12
|
+
# @param method [Symbol] the method that the callback will invoke
|
13
|
+
def initialize(object, method)
|
14
|
+
@object = object
|
15
|
+
@method = method
|
16
|
+
end
|
17
|
+
|
18
|
+
# Determines the validity of the instantiated callback. A callback
|
19
|
+
# is said to be valid if the object responds to the given method
|
20
|
+
# and the method has an arity of 1 (for the event data).
|
21
|
+
# @return [Boolean] whether or not the callback is valid
|
22
|
+
def valid?
|
23
|
+
object.respond_to?(method) && object.method(method).arity == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
# Dispatches the callback. Does nothing unless {#valid?} is true.
|
27
|
+
# @param event [string] the event name
|
28
|
+
# @return [void]
|
29
|
+
def dispatch!(event)
|
30
|
+
return unless valid?
|
31
|
+
|
32
|
+
puts "dispatch #{event}"
|
33
|
+
object.send method, event
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/mpv/client.rb
CHANGED
@@ -13,7 +13,7 @@ module MPV
|
|
13
13
|
# @return [String] the path of the socket used to communicate with mpv
|
14
14
|
attr_reader :socket_path
|
15
15
|
|
16
|
-
# @return [Array<
|
16
|
+
# @return [Array<MPV::Callback>] callback objects that will be invoked
|
17
17
|
# whenever mpv emits an event
|
18
18
|
attr_accessor :callbacks
|
19
19
|
|
@@ -22,6 +22,7 @@ module MPV
|
|
22
22
|
@socket_path = path
|
23
23
|
|
24
24
|
@socket = UNIXSocket.new(@socket_path)
|
25
|
+
@alive = true
|
25
26
|
|
26
27
|
@callbacks = []
|
27
28
|
|
@@ -34,12 +35,20 @@ module MPV
|
|
34
35
|
@events_thread = Thread.new { dispatch_events! }
|
35
36
|
end
|
36
37
|
|
38
|
+
# @return [Boolean] whether or not the player is currently active
|
39
|
+
# @note When false, most methods will cease to function.
|
40
|
+
def alive?
|
41
|
+
@alive
|
42
|
+
end
|
43
|
+
|
37
44
|
# Sends a command to the mpv process.
|
38
45
|
# @param args [Array] the individual command arguments to send
|
39
46
|
# @return [Hash] mpv's response to the command
|
40
47
|
# @example
|
41
48
|
# client.command "loadfile", "mymovie.mp4", "append-play"
|
42
49
|
def command(*args)
|
50
|
+
return unless alive?
|
51
|
+
|
43
52
|
payload = {
|
44
53
|
"command" => args
|
45
54
|
}
|
@@ -55,6 +64,8 @@ module MPV
|
|
55
64
|
# @example
|
56
65
|
# client.set_property "pause", true
|
57
66
|
def set_property(*args)
|
67
|
+
return unless alive?
|
68
|
+
|
58
69
|
command "set_property", *args
|
59
70
|
end
|
60
71
|
|
@@ -64,6 +75,8 @@ module MPV
|
|
64
75
|
# @example
|
65
76
|
# client.get_property "pause" # => true
|
66
77
|
def get_property(*args)
|
78
|
+
return unless alive?
|
79
|
+
|
67
80
|
command("get_property", *args)["data"]
|
68
81
|
end
|
69
82
|
|
@@ -71,23 +84,29 @@ module MPV
|
|
71
84
|
# @return [void]
|
72
85
|
# @note this object becomes garbage once this method is run
|
73
86
|
def quit!
|
87
|
+
return unless alive?
|
74
88
|
command "quit"
|
89
|
+
ensure
|
90
|
+
@alive = false
|
75
91
|
@socket = nil
|
76
92
|
File.delete(@socket_path) if File.exist?(@socket_path)
|
77
93
|
end
|
78
94
|
|
79
95
|
private
|
80
96
|
|
97
|
+
# Pumps commands from the command queue to the socket.
|
81
98
|
def pump_commands!
|
82
99
|
loop do
|
83
100
|
begin
|
84
101
|
@socket.puts(@command_queue.pop)
|
85
102
|
rescue # the player is deactivating
|
103
|
+
@alive = false
|
86
104
|
Thread.exit
|
87
105
|
end
|
88
106
|
end
|
89
107
|
end
|
90
108
|
|
109
|
+
# Pumps results from the socket to the result and event queues.
|
91
110
|
def pump_results!
|
92
111
|
loop do
|
93
112
|
begin
|
@@ -99,18 +118,20 @@ module MPV
|
|
99
118
|
@result_queue << response
|
100
119
|
end
|
101
120
|
rescue # the player is deactivating
|
121
|
+
@alive = false
|
102
122
|
Thread.exit
|
103
123
|
end
|
104
124
|
end
|
105
125
|
end
|
106
126
|
|
127
|
+
# Takes events from the event queue and dispatches them to callbacks.
|
107
128
|
def dispatch_events!
|
108
129
|
loop do
|
109
130
|
event = @event_queue.pop
|
110
131
|
|
111
132
|
callbacks.each do |callback|
|
112
133
|
Thread.new do
|
113
|
-
callback.
|
134
|
+
callback.dispatch! event
|
114
135
|
end
|
115
136
|
end
|
116
137
|
end
|
data/lib/mpv/session.rb
CHANGED
@@ -46,5 +46,20 @@ module MPV
|
|
46
46
|
# @return (see MPV::Client#quit!)
|
47
47
|
# @see MPV::Client#quit!
|
48
48
|
def_delegators :@client, :quit!
|
49
|
+
|
50
|
+
# @!method command
|
51
|
+
# @return (see MPV::Client#command)
|
52
|
+
# @see MPV::Client#command
|
53
|
+
def_delegators :@client, :command
|
54
|
+
|
55
|
+
# @!method get_property
|
56
|
+
# @return (see MPV::Client#get_property)
|
57
|
+
# @see MPV::Client#get_property
|
58
|
+
def_delegators :@client, :get_property
|
59
|
+
|
60
|
+
# @!method set_property
|
61
|
+
# @return (see MPV::Client#set_property)
|
62
|
+
# @see MPV::Client#set_property
|
63
|
+
def_delegators :@client, :set_property
|
49
64
|
end
|
50
65
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mpv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Woodruff
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- LICENSE
|
21
21
|
- README.md
|
22
22
|
- lib/mpv.rb
|
23
|
+
- lib/mpv/callback.rb
|
23
24
|
- lib/mpv/client.rb
|
24
25
|
- lib/mpv/server.rb
|
25
26
|
- lib/mpv/session.rb
|