forked from guysoft/electricsheep-hd-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay
executable file
·63 lines (54 loc) · 1.76 KB
/
play
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env ruby
# This script plays a seasons passed as ARV[0] from a random offset
# If ARGV[0] is not given it reads from .active-season
`which mpv` ; raise "Install mpv (https://mpv.io/) to use this script" if $? != 0
require 'socket'
PLAYLIST = "/tmp/eshd.m3u"
INPUTCONF = File.absolute_path(File.dirname(__FILE__)) + "/mpv-input.conf"
ARGV[0] ||= File.dirname(__FILE__) + "/branches/" + File.read(File.dirname(__FILE__) + "/.active-season") + "/movies/"
frame_dir = ARGV[0]
season = File.basename(frame_dir)
Dir.chdir(frame_dir)
@parts = []
Dir.glob("electricsheep*.webm").sort.each do |seq|
seq1 = seq.split("_")[0]
seq2 = seq.split("_")[1].sub(/\.webm$/,"")
seq = File.absolute_path(seq)
if seq1 == seq2
2.times { @parts << seq}
else
@parts << seq
end
end
puts "Got #{@parts.count} parts"
OFFSET = rand(0..(@parts.count))
if @parts.count < 1
fail "No enough completed parts - start the daemon to render some frames"
end
File.open(PLAYLIST, "w") { |f| f.write @parts.rotate(OFFSET).join("\n") }
mpv_args = %W(--input-conf="#{INPUTCONF}" --loop-playlist=inf --no-input-default-bindings --no-stop-screensaver --no-osc -fs --panscan=1 --idle --quiet #{PLAYLIST})
mpv_args << "--wid #{ENV['XSCREENSAVER_WINDOW']}" if ENV['XSCREENSAVER_WINDOW']
mpv = Thread.new do
begin
Thread.current.abort_on_exception=true
if Gem.win_platform?
@pid = Process.spawn("mpv #{mpv_args.join(" ")}")
else
@pid = Process.spawn("mpv #{mpv_args.join(" ")}")
end
Process.wait(@pid)
ensure
Process.kill("KILL", @pid)
Thread.current.kill
end
end
Signal.trap("SIGTERM") { puts "SIGTERM" ; Process.kill("KILL", @pid) ; Thread.kill(mpv) ; exit }
Thread.new do
loop do
sleep 0.5
unless mpv.status
exit
end
end
end
mpv.join