aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-01-18 06:29:02 -0800
committerFuwn <[email protected]>2024-01-18 06:29:02 -0800
commit7029604ead16c559cc1f4d43c92750da4dd4f800 (patch)
treead4c1ef7a0048ee0fec7329522eb32b3e0ef7af5
parentdocs(readme): update description (diff)
downloadtama-7029604ead16c559cc1f4d43c92750da4dd4f800.tar.xz
tama-7029604ead16c559cc1f4d43c92750da4dd4f800.zip
feat(watch): local streaming
-rw-r--r--README.md9
-rw-r--r--src/bashly.yml11
-rw-r--r--src/watch_command.sh10
-rwxr-xr-xtama60
4 files changed, 83 insertions, 7 deletions
diff --git a/README.md b/README.md
index c38a915..f24efec 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,13 @@
# 📺 `tama`
-A command-line client for navigating and watching anime from [Hiruki](https://hiruki.xyz)
+A command-line client for navigating and streaming anime from [Hiruki](https://hiruki.xyz)
+
+Tama allows you to view recent anime trends, search for any anime, and watch any
+anime directly on your local system in a trivial manner.
+
+Tama supports any video player and defaults to [`mpv`](https://mpv.io/), but
+optionally allows you to open and view anime in your browser instead of a local
+video player.
## Usage
diff --git a/src/bashly.yml b/src/bashly.yml
index db88e52..1b0e954 100644
--- a/src/bashly.yml
+++ b/src/bashly.yml
@@ -30,7 +30,16 @@ commands:
required: true
help: Episode to watch
help: Watch an anime by episode
- dependencies: [xdg-open]
+ dependencies: [xdg-open, base64]
+ flags:
+ - long: --browser
+ short: -b
+ help: Open the stream in your browser instead of a local video player
+ - long: --player
+ short: -p
+ arg: player
+ help: Override mpv as the local video player
+ default: mpv
- name: episodes
alias: e
args:
diff --git a/src/watch_command.sh b/src/watch_command.sh
index 6c94bf0..0d42267 100644
--- a/src/watch_command.sh
+++ b/src/watch_command.sh
@@ -1,4 +1,12 @@
-xdg-open "$(get "/stream/$(get "/episodes/${args[id]}" |
+PLAYER="$(get "/stream/$(get "/episodes/${args[id]}" |
jq -r ".[] | .id" |
head -n 1 |
sed -E 's/-episode-[0-9]+$//')-episode-1" | jq -r ".plyr.default")"
+
+if [[ -n "${args[--browser]}" ]]; then
+ xdg-open "${PLAYER}"
+else
+ "${args[--player]}" "$(echo "${PLAYER}" |
+ sed -E 's/.*#//' |
+ base64 --decode)"
+fi
diff --git a/tama b/tama
index ad5ee74..e2569d2 100755
--- a/tama
+++ b/tama
@@ -209,7 +209,7 @@ tama_watch_usage() {
echo
printf "%s\n" "Usage:"
- printf " tama watch ID EPISODE\n"
+ printf " tama watch ID EPISODE [OPTIONS]\n"
printf " tama watch --help | -h\n"
echo
@@ -217,6 +217,18 @@ tama_watch_usage() {
if [[ -n $long_usage ]]; then
printf "%s\n" "Options:"
+ # :command.usage_flags
+ # :flag.usage
+ printf " %s\n" "--browser, -b"
+ printf " Open the stream in your browser instead of a local video player\n"
+ echo
+
+ # :flag.usage
+ printf " %s\n" "--player, -p PLAYER"
+ printf " Override mpv as the local video player\n"
+ printf " Default: mpv\n"
+ echo
+
# :command.usage_fixed_flags
printf " %s\n" "--help, -h"
printf " Show this help\n"
@@ -387,11 +399,19 @@ tama_search_command() {
# :command.function
tama_watch_command() {
# src/watch_command.sh
- xdg-open "$(get "/stream/$(get "/episodes/${args[id]}" |
+ PLAYER="$(get "/stream/$(get "/episodes/${args[id]}" |
jq -r ".[] | .id" |
head -n 1 |
sed -E 's/-episode-[0-9]+$//')-episode-1" | jq -r ".plyr.default")"
+ if [[ -n "${args[--browser]}" ]]; then
+ xdg-open "${PLAYER}"
+ else
+ "${args[--player]}" "$(echo "${PLAYER}" |
+ sed -E 's/.*#//' |
+ base64 --decode)"
+ fi
+
}
# :command.function
@@ -774,6 +794,13 @@ tama_watch_parse_requirements() {
exit 1
fi
+ if command -v base64 >/dev/null 2>&1; then
+ deps['base64']="$(command -v base64 | head -n1)"
+ else
+ printf "missing dependency: base64\n" >&2
+ exit 1
+ fi
+
# :command.command_filter
action="watch"
@@ -781,6 +808,28 @@ tama_watch_parse_requirements() {
while [[ $# -gt 0 ]]; do
key="$1"
case "$key" in
+ # :flag.case
+ --browser | -b)
+
+ # :flag.case_no_arg
+ args['--browser']=1
+ shift
+ ;;
+
+ # :flag.case
+ --player | -p)
+
+ # :flag.case_arg
+ if [[ -n ${2+x} ]]; then
+
+ args['--player']="$2"
+ shift
+ shift
+ else
+ printf "%s\n" "--player requires an argument: --player, -p PLAYER" >&2
+ exit 1
+ fi
+ ;;
-?*)
printf "invalid option: %s\n" "$key" >&2
@@ -810,14 +859,17 @@ tama_watch_parse_requirements() {
# :command.required_args_filter
if [[ -z ${args['id']+x} ]]; then
- printf "missing required argument: ID\nusage: tama watch ID EPISODE\n" >&2
+ printf "missing required argument: ID\nusage: tama watch ID EPISODE [OPTIONS]\n" >&2
exit 1
fi
if [[ -z ${args['episode']+x} ]]; then
- printf "missing required argument: EPISODE\nusage: tama watch ID EPISODE\n" >&2
+ printf "missing required argument: EPISODE\nusage: tama watch ID EPISODE [OPTIONS]\n" >&2
exit 1
fi
+ # :command.default_assignments
+ [[ -n ${args['--player']:-} ]] || args['--player']="mpv"
+
}
# :command.parse_requirements