-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate-screenshots.sh
More file actions
169 lines (150 loc) · 3.17 KB
/
update-screenshots.sh
File metadata and controls
169 lines (150 loc) · 3.17 KB
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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
function focus()
{
JS="""
global.get_window_actors().forEach(function(w)
{
const mw = w.meta_window;
if(mw.get_pid() === $PID)
{
mw.move_resize_frame(0, 0, 0, 1024, 576);
mw.focus(0);
}
});
"""
RES=$(gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /org/gnome/Shell \
--method org.gnome.Shell.Eval \
"$JS")
if [ "${RES//[[:blank:]]/}" != "(true,'')" ]
then
tput setaf 1
echo "ERROR: Failed resize window using GJS. You may need to run 'global.context.unsafe_mode = true' in Looking Glass." 1>&2
tput sgr0
exit 1
fi
sleep 1
}
function screenshot()
{
gdbus call \
--session \
--dest org.gnome.Shell.Screenshot \
--object-path /org/gnome/Shell/Screenshot \
--method org.gnome.Shell.Screenshot.ScreenshotWindow \
"false" "false" "true" "$1" \
> /dev/null
mogrify -gravity center \
-alpha off \
-trim \
-fuzz 1% \
-transparent black \
+repage \
"$1"
}
function launch()
{
if [ ! -z "$(pgrep celluloid)" ]
then
tput setaf 1
echo "ERROR: An instance of Celluloid is already running." 1>&2
tput sgr0
exit 1
fi
celluloid --mpv-panscan=1 --mpv-autofit=0 &
PID=$!
sleep 2
gdbus call \
--session \
--dest org.mpris.MediaPlayer2.io.github.celluloid_player.Celluloid.instance-1 \
--object-path /org/mpris/MediaPlayer2 \
--method org.mpris.MediaPlayer2.Player.OpenUri \
"$2" \
> /dev/null
sleep 1
gdbus call \
--session \
--dest org.mpris.MediaPlayer2.io.github.celluloid_player.Celluloid.instance-1 \
--object-path /org/mpris/MediaPlayer2 \
--method org.mpris.MediaPlayer2.Player.Pause \
> /dev/null
gdbus call \
--session \
--dest org.mpris.MediaPlayer2.io.github.celluloid_player.Celluloid.instance-1 \
--object-path /org/mpris/MediaPlayer2 \
--method org.mpris.MediaPlayer2.Player.SetPosition \
'/io/github/CelluloidPlayer/Celluloid/Track/0' \
"$1" \
> /dev/null
ps -p $PID > /dev/null
if [ $? -ne 0 ]
then
tput setaf 1
echo "ERROR: Failed to start Celluloid." 1>&2
tput sgr0
exit 1
fi
sleep 1
}
function set_csd_enable()
{
gsettings set \
io.github.celluloid-player.Celluloid \
csd-enable \
"$1"
}
function set_floating_controls()
{
gsettings set \
io.github.celluloid-player.Celluloid \
always-use-floating-controls \
"$1"
}
function set_show_playlist()
{
gdbus call \
--session \
--dest io.github.celluloid_player.Celluloid \
--object-path /io/github/celluloid_player/Celluloid/window/1 \
--method org.gtk.Actions.Activate \
'set-playlist-visible' \
"[<$1>]" \
'{}' \
> /dev/null
}
function run()
{
echo "Taking screenshot $3 (csd=$1, playlist=$2)..."
set_csd_enable "$1"
launch "$5" "$6"
set_show_playlist "$2"
set_floating_controls "$3"
focus
screenshot "$4"
kill -TERM $PID
PID=""
sleep 1
}
function cleanup()
{
[ ! -z "$TMPDIR" ] && rm -r $TMPDIR
[ ! -z "$PID" ] && kill -TERM $PID
}
if [ $# -ne 2 ]
then
echo "Usage: $0 TIMESTAMP VIDEO_FILE" 1>&2
exit 1
fi
export TMPDIR=$(mktemp -d)
export XDG_CONFIG_HOME=$TMPDIR
export GSETTINGS_BACKEND=keyfile
trap cleanup EXIT
ARRAY=({true,false}\ {false,true}\ {false,true})
COUNT=0
for X in "${ARRAY[@]}"
do
run $X "$(pwd)/images/screenshot-$COUNT.png" "$1" "$2"
((COUNT++))
done