Class: Aniview::Interface::MPVBridge
- Inherits:
-
Object
- Object
- Aniview::Interface::MPVBridge
show all
- Includes:
- Util
- Defined in:
- lib/aniview/interface/mpv/mpvbridge.rb
Instance Method Summary
collapse
Methods included from Util
decode_object, encode_object, error_message, format_duration, format_progress, format_size, parse_format, readline
Constructor Details
#initialize(pref) ⇒ MPVBridge
Returns a new instance of MPVBridge.
8
9
10
11
12
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 8
def initialize pref
@pref = pref
@mpv_enabled = true
connect
end
|
Instance Method Details
#attributes ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 54
def attributes
if playing?
r = {}
props = [
"time-pos",
"percent-pos",
"duration"
]
props.each { |prop|
prop_val = @mpv.client.get_property(prop)
prop_val = 0 if prop_val == nil
r.merge!(
prop[0] => prop_val
)
}
if @playing_file != nil
r.merge!("n" => @playing_file.attributes["t"])
else
r.merge!("n" => "loading")
end
checkSetWatched r["p"]
{
"t" => Util.format_duration(r["t"]),
"p" => Util.format_progress(r["p"]),
"d" => Util.format_duration(r["d"]),
"n" => r["n"]
}
else
{
"t" => "0:00",
"p" => "0",
"d" => "0:00",
"n" => "."
}
end
end
|
#checkSetWatched(percentage) ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 44
def checkSetWatched percentage
if @playing_file != nil
swp = Integer(@pref.get "set_watched_percentage")
pct = Float(percentage)
if pct >= swp and not @playing_file.seen?
@playing_file.watch
end
end
end
|
#connect ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 18
def connect
return unless @mpv_enabled
return unless @mpv == nil or @mpv.client.get_property("idle-active") == nil
@mpv = nil
@mpv_enabled = false
begin
@mpv = MPV::Session.new(user_args: @pref.get("mpv_args").split(" "))
rescue MPV::MPVNotAvailableError
rescue MPV::MPVUnsupportedFlagError
else
@mpv_enabled = true
end
end
|
#play(file) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 32
def play file
return unless @mpv_enabled
connect
@playing_file = file
@mpv.client.command "loadfile", file.path
end
|
#playing? ⇒ Boolean
39
40
41
42
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 39
def playing?
return false unless @mpv_enabled
@mpv.client.get_property("time-pos") != nil
end
|
#quit! ⇒ Object
14
15
16
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 14
def quit!
@mpv.quit! unless @mpv == nil
end
|