mpv 1.2.1 → 2.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/mpv.rb +3 -2
- data/lib/mpv/client.rb +6 -5
- data/lib/mpv/exceptions.rb +2 -0
- data/lib/mpv/server.rb +9 -9
- data/lib/mpv/session.rb +3 -3
- data/lib/mpv/utils.rb +2 -0
- metadata +4 -5
- data/lib/mpv/callback.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a28500919bd886fcb25f03be50439131c8f9c12
|
4
|
+
data.tar.gz: aa2dd2f726680599a0b6e48266e1586755bc8f38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2405d8b355035b1dffb513e92f89a1b5975816a3c381c7d4d0dc7521f77d3e550675ce492540ecf34e974dfe256840a6d9c157fad5dd718ee6b911f4d69e07a2
|
7
|
+
data.tar.gz: e1e01d4e9735dab1b7cf2966cec6ee7d52bfa2697a5c0e73d62c831ad67b4b11288137a76cf1b5c097c23e675067fde9d2e4caf903aa52a9ae46685ffaa259f7
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ def something_happened(event)
|
|
23
23
|
end
|
24
24
|
|
25
25
|
session = MPV::Session.new # contains both a MPV::Server and a MPV::Client
|
26
|
-
session.callbacks <<
|
26
|
+
session.callbacks << method(:something_happened)
|
27
27
|
session.get_property "pause"
|
28
28
|
session.command "get_version"
|
29
29
|
session.command "loadlist", "my_huge_playlist.txt", "append"
|
data/lib/mpv.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "mpv/exceptions"
|
2
4
|
require_relative "mpv/utils"
|
3
|
-
require_relative "mpv/callback"
|
4
5
|
require_relative "mpv/client"
|
5
6
|
require_relative "mpv/server"
|
6
7
|
require_relative "mpv/session"
|
@@ -8,5 +9,5 @@ require_relative "mpv/session"
|
|
8
9
|
# The toplevel namespace for ruby-mpv.
|
9
10
|
module MPV
|
10
11
|
# The current version of ruby-mpv.
|
11
|
-
VERSION = "
|
12
|
+
VERSION = "2.0.1"
|
12
13
|
end
|
data/lib/mpv/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "socket"
|
2
4
|
require "json"
|
3
5
|
require "thread"
|
@@ -13,7 +15,7 @@ module MPV
|
|
13
15
|
# @return [String] the path of the socket used to communicate with mpv
|
14
16
|
attr_reader :socket_path
|
15
17
|
|
16
|
-
# @return [Array<
|
18
|
+
# @return [Array<Proc>] callback procs that will be invoked
|
17
19
|
# whenever mpv emits an event
|
18
20
|
attr_accessor :callbacks
|
19
21
|
|
@@ -50,7 +52,7 @@ module MPV
|
|
50
52
|
return unless alive?
|
51
53
|
|
52
54
|
payload = {
|
53
|
-
"command" => args
|
55
|
+
"command" => args,
|
54
56
|
}
|
55
57
|
|
56
58
|
@command_queue << JSON.generate(payload)
|
@@ -84,8 +86,7 @@ module MPV
|
|
84
86
|
# @return [void]
|
85
87
|
# @note this object becomes garbage once this method is run
|
86
88
|
def quit!
|
87
|
-
|
88
|
-
command "quit"
|
89
|
+
command "quit" if alive?
|
89
90
|
ensure
|
90
91
|
@alive = false
|
91
92
|
@socket = nil
|
@@ -131,7 +132,7 @@ module MPV
|
|
131
132
|
|
132
133
|
callbacks.each do |callback|
|
133
134
|
Thread.new do
|
134
|
-
callback.
|
135
|
+
callback.call event
|
135
136
|
end
|
136
137
|
end
|
137
138
|
end
|
data/lib/mpv/exceptions.rb
CHANGED
data/lib/mpv/server.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "tempfile"
|
2
4
|
|
3
5
|
module MPV
|
@@ -19,14 +21,14 @@ module MPV
|
|
19
21
|
|
20
22
|
# @return [Boolean] whether `mpv` supports the given flag
|
21
23
|
# @note returns false if `mpv` is not available
|
22
|
-
def self.
|
24
|
+
def self.flag?(flag)
|
23
25
|
return false unless available?
|
24
26
|
|
25
27
|
# MPV allows flags to be suffixed with =yes or =no, but doesn't
|
26
28
|
# include these variations in their list. They also allow a --no-
|
27
29
|
# prefix that isn't included in the list, so we normalize these out.
|
28
30
|
# Additionally, we need to remove trailing arguments.
|
29
|
-
normalized_flag = flag.sub(/^--no-/,
|
31
|
+
normalized_flag = flag.sub(/^--no-/, "--").sub(/=\S*/, "")
|
30
32
|
|
31
33
|
flags = `mpv --list-options`.split.select { |s| s.start_with?("--") }
|
32
34
|
flags.include?(normalized_flag)
|
@@ -43,7 +45,7 @@ module MPV
|
|
43
45
|
# @raise [MPVUnsupportedFlagError] if `mpv` does not support the given flag
|
44
46
|
def self.ensure_flag!(flag)
|
45
47
|
ensure_available!
|
46
|
-
raise MPVUnsupportedFlagError, flag unless
|
48
|
+
raise MPVUnsupportedFlagError, flag unless flag?(flag)
|
47
49
|
end
|
48
50
|
|
49
51
|
# @param path [String] the path of the socket to be created
|
@@ -57,7 +59,7 @@ module MPV
|
|
57
59
|
@args = [
|
58
60
|
"--idle",
|
59
61
|
"--terminal=no",
|
60
|
-
"--input-ipc-server
|
62
|
+
"--input-ipc-server=%<path>s" % { path: @socket_path },
|
61
63
|
].concat(user_args).uniq
|
62
64
|
|
63
65
|
@args.each { |arg| self.class.ensure_flag! arg }
|
@@ -67,11 +69,9 @@ module MPV
|
|
67
69
|
|
68
70
|
# @return [Boolean] whether or not the mpv process is running
|
69
71
|
def running?
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
false
|
74
|
-
end
|
72
|
+
!!@pid && Process.waitpid(@pid, Process::WNOHANG).nil?
|
73
|
+
rescue Errno::ECHILD
|
74
|
+
false
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
data/lib/mpv/session.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "forwardable"
|
2
4
|
|
3
5
|
module MPV
|
@@ -25,9 +27,7 @@ module MPV
|
|
25
27
|
|
26
28
|
@server = Server.new(path: @socket_path, user_args: user_args)
|
27
29
|
|
28
|
-
until File.exist?(@socket_path)
|
29
|
-
sleep 0.1
|
30
|
-
end
|
30
|
+
sleep 0.1 until File.exist?(@socket_path)
|
31
31
|
|
32
32
|
@client = Client.new(@socket_path)
|
33
33
|
end
|
data/lib/mpv/utils.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mpv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Woodruff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A library for creating and controlling mpv instances.
|
14
14
|
email: william@tuffbizz.com
|
@@ -20,7 +20,6 @@ files:
|
|
20
20
|
- LICENSE
|
21
21
|
- README.md
|
22
22
|
- lib/mpv.rb
|
23
|
-
- lib/mpv/callback.rb
|
24
23
|
- lib/mpv/client.rb
|
25
24
|
- lib/mpv/exceptions.rb
|
26
25
|
- lib/mpv/server.rb
|
@@ -38,7 +37,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
37
|
requirements:
|
39
38
|
- - ">="
|
40
39
|
- !ruby/object:Gem::Version
|
41
|
-
version: 2.
|
40
|
+
version: 2.3.0
|
42
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
42
|
requirements:
|
44
43
|
- - ">="
|
@@ -46,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
45
|
version: '0'
|
47
46
|
requirements: []
|
48
47
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.
|
48
|
+
rubygems_version: 2.6.11
|
50
49
|
signing_key:
|
51
50
|
specification_version: 4
|
52
51
|
summary: mpv - A ruby library for controlling mpv processes.
|
data/lib/mpv/callback.rb
DELETED
@@ -1,35 +0,0 @@
|
|
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
|
-
object.send method, event
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|