aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-01-18 04:33:22 -0800
committerFuwn <[email protected]>2024-01-18 04:33:26 -0800
commitd2596243e3cffd356e02b2697c5902bc3fe03d74 (patch)
treeb62399bf609846cad5fba8214924c45268ab417d
parentfeat(bashly): add descriptions (diff)
downloadtama-d2596243e3cffd356e02b2697c5902bc3fe03d74.tar.xz
tama-d2596243e3cffd356e02b2697c5902bc3fe03d74.zip
feat: episodes and watch sub-commands
-rw-r--r--README.md2
-rw-r--r--src/bashly.yml20
-rw-r--r--src/episodes_command.sh10
-rw-r--r--src/lib/print.sh2
-rw-r--r--src/watch_command.sh4
-rwxr-xr-xtama275
6 files changed, 310 insertions, 3 deletions
diff --git a/README.md b/README.md
index 082e764..5fd4c7e 100644
--- a/README.md
+++ b/README.md
@@ -28,6 +28,8 @@ Commands:
popular Popular anime
upcoming Upcoming anime
search Search for a number of anime
+ watch Watch an anime by episode
+ episodes An anime's episodes
```
### Dependencies
diff --git a/src/bashly.yml b/src/bashly.yml
index 81f8204..db88e52 100644
--- a/src/bashly.yml
+++ b/src/bashly.yml
@@ -17,4 +17,24 @@ commands:
args:
- name: query
repeatable: true
+ required: true
help: Search for a number of anime
+ - name: watch
+ alias: w
+ args:
+ - name: id
+ required: true
+ help: |
+ Found by either the trending, popular, upcoming, or search subcommand
+ - name: episode
+ required: true
+ help: Episode to watch
+ help: Watch an anime by episode
+ dependencies: [xdg-open]
+ - name: episodes
+ alias: e
+ args:
+ - name: id
+ required: true
+ help: An anime's episodes
+ dependencies: [head]
diff --git a/src/episodes_command.sh b/src/episodes_command.sh
new file mode 100644
index 0000000..5218081
--- /dev/null
+++ b/src/episodes_command.sh
@@ -0,0 +1,10 @@
+function episodes() {
+ echo
+
+ get "/episodes/${1}" |
+ jq -r '.[] | [.number, ". ", .title] | join("")' |
+ mdcat |
+ sed 's/^/ /'
+}
+
+episodes "${args[id]}"
diff --git a/src/lib/print.sh b/src/lib/print.sh
index 8c66ad6..1addd3d 100644
--- a/src/lib/print.sh
+++ b/src/lib/print.sh
@@ -2,7 +2,7 @@ function print() {
echo
get "${1}" |
- jq -r '.[] | ["[", .title.romaji, "](https://hiruki.xyz/i/", .id, ")"] | join("")' |
+ jq -r '.[] | ["[", .title.romaji, "](https://hiruki.xyz/i/", .id, ") • ", .id] | join("")' |
sed 's/^/* /' |
mdcat |
sed 's/^/ /'
diff --git a/src/watch_command.sh b/src/watch_command.sh
new file mode 100644
index 0000000..6c94bf0
--- /dev/null
+++ b/src/watch_command.sh
@@ -0,0 +1,4 @@
+xdg-open "$(get "/stream/$(get "/episodes/${args[id]}" |
+ jq -r ".[] | .id" |
+ head -n 1 |
+ sed -E 's/-episode-[0-9]+$//')-episode-1" | jq -r ".plyr.default")"
diff --git a/tama b/tama
index abd0977..ad5ee74 100755
--- a/tama
+++ b/tama
@@ -38,6 +38,8 @@ tama_usage() {
printf " %s Popular anime\n" "popular "
printf " %s Upcoming anime\n" "upcoming"
printf " %s Search for a number of anime\n" "search "
+ printf " %s Watch an anime by episode\n" "watch "
+ printf " %s An anime's episodes\n" "episodes"
echo
# :command.long_usage
@@ -167,7 +169,7 @@ tama_search_usage() {
echo
printf "%s\n" "Usage:"
- printf " tama search [QUERY...]\n"
+ printf " tama search QUERY...\n"
printf " tama search --help | -h\n"
echo
@@ -191,6 +193,91 @@ tama_search_usage() {
fi
}
+# :command.usage
+tama_watch_usage() {
+ if [[ -n $long_usage ]]; then
+ printf "tama watch - Watch an anime by episode\n"
+ echo
+
+ else
+ printf "tama watch - Watch an anime by episode\n"
+ echo
+
+ fi
+
+ printf "Alias: w\n"
+ echo
+
+ printf "%s\n" "Usage:"
+ printf " tama watch ID EPISODE\n"
+ printf " tama watch --help | -h\n"
+ echo
+
+ # :command.long_usage
+ if [[ -n $long_usage ]]; then
+ printf "%s\n" "Options:"
+
+ # :command.usage_fixed_flags
+ printf " %s\n" "--help, -h"
+ printf " Show this help\n"
+ echo
+
+ # :command.usage_args
+ printf "%s\n" "Arguments:"
+
+ # :argument.usage
+ printf " %s\n" "ID"
+ printf " Found by either the trending, popular, upcoming, or search subcommand\n"
+ echo
+
+ # :argument.usage
+ printf " %s\n" "EPISODE"
+ printf " Episode to watch\n"
+ echo
+
+ fi
+}
+
+# :command.usage
+tama_episodes_usage() {
+ if [[ -n $long_usage ]]; then
+ printf "tama episodes - An anime's episodes\n"
+ echo
+
+ else
+ printf "tama episodes - An anime's episodes\n"
+ echo
+
+ fi
+
+ printf "Alias: e\n"
+ echo
+
+ printf "%s\n" "Usage:"
+ printf " tama episodes ID\n"
+ printf " tama episodes --help | -h\n"
+ echo
+
+ # :command.long_usage
+ if [[ -n $long_usage ]]; then
+ printf "%s\n" "Options:"
+
+ # :command.usage_fixed_flags
+ printf " %s\n" "--help, -h"
+ printf " Show this help\n"
+ echo
+
+ # :command.usage_args
+ printf "%s\n" "Arguments:"
+
+ # :argument.usage
+ printf " %s\n" "ID"
+ printf "\n"
+ echo
+
+ fi
+}
+
# :command.normalize_input
normalize_input() {
local arg flags
@@ -262,7 +349,7 @@ function print() {
echo
get "${1}" |
- jq -r '.[] | ["[", .title.romaji, "](https://hiruki.xyz/i/", .id, ")"] | join("")' |
+ jq -r '.[] | ["[", .title.romaji, "](https://hiruki.xyz/i/", .id, ") • ", .id] | join("")' |
sed 's/^/* /' |
mdcat |
sed 's/^/ /'
@@ -297,6 +384,32 @@ tama_search_command() {
}
+# :command.function
+tama_watch_command() {
+ # src/watch_command.sh
+ xdg-open "$(get "/stream/$(get "/episodes/${args[id]}" |
+ jq -r ".[] | .id" |
+ head -n 1 |
+ sed -E 's/-episode-[0-9]+$//')-episode-1" | jq -r ".plyr.default")"
+
+}
+
+# :command.function
+tama_episodes_command() {
+ # src/episodes_command.sh
+ function episodes() {
+ echo
+
+ get "/episodes/${1}" |
+ jq -r '.[] | [.number, ". ", .title] | join("")' |
+ mdcat |
+ sed 's/^/ /'
+ }
+
+ episodes "${args[id]}"
+
+}
+
# :command.parse_requirements
parse_requirements() {
# :command.fixed_flags_filter
@@ -397,6 +510,20 @@ parse_requirements() {
shift $#
;;
+ watch | w)
+ action="watch"
+ shift
+ tama_watch_parse_requirements "$@"
+ shift $#
+ ;;
+
+ episodes | e)
+ action="episodes"
+ shift
+ tama_episodes_parse_requirements "$@"
+ shift $#
+ ;;
+
# :command.command_fallback
"")
tama_usage >&2
@@ -613,6 +740,148 @@ tama_search_parse_requirements() {
esac
done
+ # :command.required_args_filter
+ if [[ -z ${args['query']+x} ]]; then
+ printf "missing required argument: QUERY\nusage: tama search QUERY...\n" >&2
+ exit 1
+ fi
+
+}
+
+# :command.parse_requirements
+tama_watch_parse_requirements() {
+ # :command.fixed_flags_filter
+ while [[ $# -gt 0 ]]; do
+ case "${1:-}" in
+ --help | -h)
+ long_usage=yes
+ tama_watch_usage
+ exit
+ ;;
+
+ *)
+ break
+ ;;
+
+ esac
+ done
+
+ # :command.dependencies_filter
+ if command -v xdg-open >/dev/null 2>&1; then
+ deps['xdg-open']="$(command -v xdg-open | head -n1)"
+ else
+ printf "missing dependency: xdg-open\n" >&2
+ exit 1
+ fi
+
+ # :command.command_filter
+ action="watch"
+
+ # :command.parse_requirements_while
+ while [[ $# -gt 0 ]]; do
+ key="$1"
+ case "$key" in
+
+ -?*)
+ printf "invalid option: %s\n" "$key" >&2
+ exit 1
+ ;;
+
+ *)
+ # :command.parse_requirements_case
+ # :command.parse_requirements_case_simple
+ if [[ -z ${args['id']+x} ]]; then
+
+ args['id']=$1
+ shift
+ elif [[ -z ${args['episode']+x} ]]; then
+
+ args['episode']=$1
+ shift
+ else
+ printf "invalid argument: %s\n" "$key" >&2
+ exit 1
+ fi
+
+ ;;
+
+ esac
+ done
+
+ # :command.required_args_filter
+ if [[ -z ${args['id']+x} ]]; then
+ printf "missing required argument: ID\nusage: tama watch ID EPISODE\n" >&2
+ exit 1
+ fi
+ if [[ -z ${args['episode']+x} ]]; then
+ printf "missing required argument: EPISODE\nusage: tama watch ID EPISODE\n" >&2
+ exit 1
+ fi
+
+}
+
+# :command.parse_requirements
+tama_episodes_parse_requirements() {
+ # :command.fixed_flags_filter
+ while [[ $# -gt 0 ]]; do
+ case "${1:-}" in
+ --help | -h)
+ long_usage=yes
+ tama_episodes_usage
+ exit
+ ;;
+
+ *)
+ break
+ ;;
+
+ esac
+ done
+
+ # :command.dependencies_filter
+ if command -v head >/dev/null 2>&1; then
+ deps['head']="$(command -v head | head -n1)"
+ else
+ printf "missing dependency: head\n" >&2
+ exit 1
+ fi
+
+ # :command.command_filter
+ action="episodes"
+
+ # :command.parse_requirements_while
+ while [[ $# -gt 0 ]]; do
+ key="$1"
+ case "$key" in
+
+ -?*)
+ printf "invalid option: %s\n" "$key" >&2
+ exit 1
+ ;;
+
+ *)
+ # :command.parse_requirements_case
+ # :command.parse_requirements_case_simple
+ if [[ -z ${args['id']+x} ]]; then
+
+ args['id']=$1
+ shift
+ else
+ printf "invalid argument: %s\n" "$key" >&2
+ exit 1
+ fi
+
+ ;;
+
+ esac
+ done
+
+ # :command.required_args_filter
+ if [[ -z ${args['id']+x} ]]; then
+ printf "missing required argument: ID\nusage: tama episodes ID\n" >&2
+ exit 1
+ fi
+
}
# :command.initialize
@@ -637,6 +906,8 @@ run() {
"popular") tama_popular_command ;;
"upcoming") tama_upcoming_command ;;
"search") tama_search_command ;;
+ "watch") tama_watch_command ;;
+ "episodes") tama_episodes_command ;;
esac
}