mpv 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d25be70e3e15c8720044d842ed74d45c977abec9
4
- data.tar.gz: 7b62cdd7455685761611b49ae7e34b25c68f1f15
3
+ metadata.gz: a56beb79994103bfdb822f55160b357c84288459
4
+ data.tar.gz: 8c8356594fd17c1887019136f3f57f9eb359668d
5
5
  SHA512:
6
- metadata.gz: d4ddcf887372cd392010ba7f3503bee58ac09ef1a9fec8bc6c52874a76f25bd38f773d533ed12ac84d1aef7e6427d382df3e8b7c56da8e198a7f8ad973d6f323
7
- data.tar.gz: f4d3527f5e8a6a1059ac92b0179edc7b69bd72bf5c90e75b7bcc8aac49eef5e33a23b4171e9c1f2659d92b44f509e9339d8d0306271536c33879b452e3f7fc86
6
+ metadata.gz: a5cccbc367d135c2da27cc9dc881df213df3ddb3a85585381828283197f5a3eb8e28ca9077d43209076c62899085fa92a449b18099807191612fb41d3ad0ab6d
7
+ data.tar.gz: d76614aacb7a00f0fba4758ff0c30f857b43fadb02c2747bef1e72a6c88aea3c71af3a1cd2f299430e346ba4f398aa33bef638f23f3debb173f22564ab9a391d
data/lib/mpv.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require_relative "mpv/exceptions"
2
+ require_relative "mpv/utils"
1
3
  require_relative "mpv/callback"
2
4
  require_relative "mpv/client"
3
5
  require_relative "mpv/server"
@@ -6,5 +8,5 @@ require_relative "mpv/session"
6
8
  # The toplevel namespace for ruby-mpv.
7
9
  module MPV
8
10
  # The current version of ruby-mpv.
9
- VERSION = "1.1.2".freeze
11
+ VERSION = "1.2.0".freeze
10
12
  end
@@ -0,0 +1,16 @@
1
+ module MPV
2
+ class MPVError < RuntimeError
3
+ end
4
+
5
+ class MPVNotAvailableError < MPVError
6
+ def initialize
7
+ super "Could not find an mpv binary to execute in the system path"
8
+ end
9
+ end
10
+
11
+ class MPVUnsupportedFlagError < MPVError
12
+ def initialize(flag)
13
+ super "Installed mpv doesn't support the #{flag} flag"
14
+ end
15
+ end
16
+ end
@@ -12,19 +12,56 @@ module MPV
12
12
  # @return [Fixnum] the process id of the mpv process
13
13
  attr_reader :pid
14
14
 
15
+ # @return [Boolean] whether `mpv` is executable within the system path
16
+ def self.available?
17
+ Utils.which?("mpv")
18
+ end
19
+
20
+ # @return [Boolean] whether `mpv` supports the given flag
21
+ # @note returns false if `mpv` is not available
22
+ def self.has_flag?(flag)
23
+ return false unless available?
24
+
25
+ # MPV allows flags to be suffixed with =yes or =no, but doesn't
26
+ # include these variations in their list. They also allow a --no-
27
+ # prefix that isn't included in the list, so we normalize these out.
28
+ # Additionally, we need to remove trailing arguments.
29
+ normalized_flag = flag.sub(/^--no-/, '--').sub(/=\S*/, '')
30
+
31
+ flags = `mpv --list-options`.split.select { |s| s.start_with?("--") }
32
+ flags.include?(normalized_flag)
33
+ end
34
+
35
+ # Ensures that a binary named `mpv` can be executed.
36
+ # @raise [MPVNotAvailableError] if no `mpv` executable in the system path
37
+ def self.ensure_available!
38
+ raise MPVNotAvailableError unless available?
39
+ end
40
+
41
+ # Ensures that that the `mpv` being executed supports the given flag.
42
+ # @raise [MPVNotAvailableError] if no `mpv` executable in the system path
43
+ # @raise [MPVUnsupportedFlagError] if `mpv` does not support the given flag
44
+ def self.ensure_flag!(flag)
45
+ ensure_available!
46
+ raise MPVUnsupportedFlagError, flag unless has_flag?(flag)
47
+ end
48
+
15
49
  # @param path [String] the path of the socket to be created
16
50
  # (defaults to a tmpname in `/tmp`)
17
51
  # @param user_args [Array<String>] additional arguments to use when
18
52
  # spawning mpv
19
53
  def initialize(path: Dir::Tmpname.make_tmpname("/tmp/mpv", ".sock"),
20
54
  user_args: [])
55
+
21
56
  @socket_path = path
22
57
  @args = [
23
58
  "--idle",
24
- "--no-terminal",
59
+ "--terminal=no",
25
60
  "--input-ipc-server=%{path}" % { path: @socket_path },
26
61
  ].concat(user_args).uniq
27
62
 
63
+ @args.each { |arg| self.class.ensure_flag! arg }
64
+
28
65
  @pid = Process.spawn("mpv", *@args)
29
66
  end
30
67
 
@@ -0,0 +1,13 @@
1
+ module MPV
2
+ module Utils
3
+ # Tests whether the given utility is available in the system path.
4
+ # @param util [String] the utility to test
5
+ # @return [Boolean] whether or not the utility is available
6
+ # @api private
7
+ def self.which?(util)
8
+ ENV["PATH"].split(File::PATH_SEPARATOR).any? do |path|
9
+ File.executable?(File.join(path, util))
10
+ end
11
+ end
12
+ end
13
+ end
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: 1.1.2
4
+ version: 1.2.0
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-01-15 00:00:00.000000000 Z
11
+ date: 2017-01-24 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
@@ -22,8 +22,10 @@ files:
22
22
  - lib/mpv.rb
23
23
  - lib/mpv/callback.rb
24
24
  - lib/mpv/client.rb
25
+ - lib/mpv/exceptions.rb
25
26
  - lib/mpv/server.rb
26
27
  - lib/mpv/session.rb
28
+ - lib/mpv/utils.rb
27
29
  homepage: https://github.com/woodruffw/ruby-mpv
28
30
  licenses:
29
31
  - MIT