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, format_duration, format_progress, format_size, parse_format, readline
Constructor Details
#initialize(pref) ⇒ MPVBridge
Returns a new instance of MPVBridge.
8
9
10
11
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 8
def initialize pref
@pref = pref
connect
end
|
Instance Method Details
#attributes ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
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
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 42
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
32
33
34
35
36
37
38
39
40
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 32
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
17
18
19
20
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 17
def connect
return unless @mpv == nil or @mpv.client.get_property("idle-active") == nil
@mpv = MPV::Session.new(user_args: @pref.get("mpv_args").split(" "))
end
|
#play(file) ⇒ Object
22
23
24
25
26
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 22
def play file
connect
@playing_file = file
@mpv.client.command "loadfile", file.path
end
|
#playing? ⇒ Boolean
28
29
30
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 28
def playing?
@mpv.client.get_property("time-pos") != nil
end
|
#quit! ⇒ Object
13
14
15
|
# File 'lib/aniview/interface/mpv/mpvbridge.rb', line 13
def quit!
@mpv.quit!
end
|