2 * Copyright (c) 2019, De Rais <derais@cock.li>
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
26 #include <sys/types.h>
32 extern char **environ
;
35 launch_downloader(const char *uri
)
38 posix_spawn_file_actions_t fa
;
42 char *uridup
= strdup(uri
);
43 char *prog
= strdup("youtube-dl");
44 char *quiet
= strdup("--quiet");
45 char *no_warnings
= strdup("--no-warnings");
46 char * const argv
[5] = { prog
, quiet
, no_warnings
, uridup
, 0 };
54 if (posix_spawn_file_actions_init(&fa
)) {
55 PERROR_MESSAGE("posix_spawn_file_actions_init");
61 if (posix_spawnattr_init(&sa
)) {
62 PERROR_MESSAGE("posix_spawnattr_init");
68 if (posix_spawn_file_actions_addclose(&fa
, 0)) {
69 PERROR_MESSAGE("posix_spawn_file_actions_addclose");
73 if (posix_spawn_file_actions_addclose(&fa
, 1)) {
74 PERROR_MESSAGE("posix_spawn_file_actions_addclose");
78 if (posix_spawn_file_actions_addclose(&fa
, 2)) {
79 PERROR_MESSAGE("posix_spawn_file_actions_addclose");
83 if (posix_spawnattr_setflags(&sa
, POSIX_SPAWN_SETSIGDEF
)) {
84 PERROR_MESSAGE("posix_spawnattr_setflags");
88 if (posix_spawn_file_actions_addopen(&fa
, 0, "/dev/null", O_RDONLY
,
90 PERROR_MESSAGE("posix_spawn_file_actions_addopen");
94 if (posix_spawn_file_actions_addopen(&fa
, 1, "/dev/null", O_WRONLY
,
96 PERROR_MESSAGE("posix_spawn_file_actions_addopen");
100 if (posix_spawn_file_actions_adddup2(&fa
, 1, 2)) {
101 PERROR_MESSAGE("posix_spawn_file_actions_adddup2");
105 posix_spawnp(&dummy
, "youtube-dl", &fa
, &sa
, argv
, environ
);
109 posix_spawn_file_actions_destroy(&fa
);
113 posix_spawnattr_destroy(&sa
);
123 launch_player(const char *uri
)
126 posix_spawn_file_actions_t fa
;
128 posix_spawnattr_t sa
;
130 char *uridup
= strdup(uri
);
131 char *prog
= strdup("mpv");
132 char *quiet
= strdup("--quiet");
133 char * const argv
[4] = { prog
, quiet
, uridup
, 0 };
141 if (posix_spawn_file_actions_init(&fa
)) {
142 PERROR_MESSAGE("posix_spawn_file_actions_init");
148 if (posix_spawnattr_init(&sa
)) {
149 PERROR_MESSAGE("posix_spawnattr_init");
155 if (posix_spawn_file_actions_addclose(&fa
, 0)) {
156 PERROR_MESSAGE("posix_spawn_file_actions_addclose");
160 if (posix_spawn_file_actions_addclose(&fa
, 1)) {
161 PERROR_MESSAGE("posix_spawn_file_actions_addclose");
165 if (posix_spawn_file_actions_addclose(&fa
, 2)) {
166 PERROR_MESSAGE("posix_spawn_file_actions_addclose");
170 if (posix_spawnattr_setflags(&sa
, POSIX_SPAWN_SETSIGDEF
)) {
171 PERROR_MESSAGE("posix_spawnattr_setflags");
175 if (posix_spawn_file_actions_addopen(&fa
, 0, "/dev/null", O_RDONLY
,
177 PERROR_MESSAGE("posix_spawn_file_actions_addopen");
181 if (posix_spawn_file_actions_addopen(&fa
, 1, "/dev/null", O_WRONLY
,
183 PERROR_MESSAGE("posix_spawn_file_actions_addopen");
187 if (posix_spawn_file_actions_adddup2(&fa
, 1, 2)) {
188 PERROR_MESSAGE("posix_spawn_file_actions_adddup2");
192 posix_spawnp(&dummy
, "mpv-with-load-screen", &fa
, &sa
, argv
, environ
);
196 posix_spawn_file_actions_destroy(&fa
);
200 posix_spawnattr_destroy(&sa
);