aboutsummaryrefslogtreecommitdiff
path: root/modules/newsboat.home/opener.sh
blob: 162b32eff2541640c53bc8901a0242f84f898aab (plain) (blame)
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
#!/usr/bin/env bash

type="$1"; shift;

spawn() { setsid -f "$@" >/dev/null 2>&1; }

video() {
  spawn mpv \
    -keep-open \
    --player-operation-mode=pseudo-gui \
    --force-window=immediate \
    "$@";
}

image() { spawn feh -x -F --image-bg "#0f0c19" "$@"; }

__tts() {
  # https://huggingface.co/rhasspy/piper-voices/tree/main/en/en_US
  # local tts_model="en_US-ryan-high.onnx";
  local tts_model="en_US-lessac-medium.onnx";
  # local tts_model="en_US-bryce-medium.onnx";
  local tts_model_path="$HOME/.config/piper-models/$tts_model";
  [ -f "$tts_model_path" ] || (echo "Model not found" && exit 1);

  local tmp_file=$(mktemp /tmp/newsboat-piper-tts.XXX);
  notify-send -t 6000 'Loading tts...';
  piper --model "$tts_model_path" -f "$tmp_file" --sentence_silence 0.4;
  video "$tmp_file";
}
tts() { __tts >/dev/null 2>&1; }

browser() { spawn sensible-browser "$@"; }

torrent-dl() { ~/scripts/torrent.sh torrent "$1" >/dev/null 2>&1; }

torrent-stream() {
  notify-send -t 10000 'Starting stream player...';
  spawn peerflix "$1" --mpv -- -keep-open --force-window=immediate >/dev/null 2>&1;
}

case "$type" in
  copy) echo "$@" | xclip -selection clipboard ;;
  tts) tts ;;
  image) image "$@" ;;
  video|audio) video "$@" ;;
  torrent-dl) torrent-dl "$@" ;;
  torrent-stream) torrent-stream "$@" ;;
  *)
    case "$1" in
      https://*youtu.be/*|https://*youtube.com/v/*) video "$@" ;;
      https://*youtube.com/watch*) video "$@" ;;
      magnet:*) torrent-dl "$@" ;;
      https*.torrent) torrent-dl "$@" ;;
      *) browser "$@" ;;
    esac
  ;;
esac;