adds keybind help and fixes scripts
This commit is contained in:
+100
-13
@@ -1,17 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
version_number="4.10.4"
|
||||
version_number="4.14.0"
|
||||
|
||||
# UI
|
||||
|
||||
external_menu() {
|
||||
rofi "$1" -sort -dmenu -i -width 1500 -p "$2" "$3"
|
||||
[ "$use_external_menu" = "1" ] && rofi "$1" -sort -dmenu -i -width 1500 -p "$2" "$3"
|
||||
[ "$use_external_menu" = "2" ] && dmenu -l 20 -p "$2"
|
||||
}
|
||||
|
||||
launcher() {
|
||||
[ "$use_external_menu" = "0" ] && [ -z "$1" ] && set -- "+m" "$2"
|
||||
[ "$use_external_menu" = "0" ] && fzf "$1" --reverse --cycle --prompt "$2"
|
||||
[ "$use_external_menu" = "1" ] && external_menu "$1" "$2" "$external_menu_args"
|
||||
[ "$use_external_menu" = "2" ] && external_menu "$1" "$2"
|
||||
}
|
||||
|
||||
nth() {
|
||||
@@ -72,6 +74,8 @@ help_info() {
|
||||
Play dubbed version
|
||||
--rofi
|
||||
Use rofi instead of fzf for the interactive menu
|
||||
--dmenu
|
||||
Use dmenu instead of fzf for the interactive menu
|
||||
--skip
|
||||
Use ani-skip to skip the intro of the episode (mpv only)
|
||||
--no-detach
|
||||
@@ -177,9 +181,14 @@ generate_link() {
|
||||
1) provider_init "wixmp" "/Default :/p" ;; # wixmp(default)(m3u8)(multi) -> (mp4)(multi)
|
||||
2) provider_init "youtube" "/Yt-mp4 :/p" ;; # youtube(mp4)(single)
|
||||
3) provider_init "sharepoint" "/S-mp4 :/p" ;; # sharepoint(mp4)(single)
|
||||
5) provider_init "filemoon" "/Fm-mp4 :/p" ;; # filemoon(m3u8)(single)
|
||||
*) provider_init "hianime" "/Luf-Mp4 :/p" ;; # hianime(m3u8)(multi)
|
||||
esac
|
||||
[ -n "$provider_id" ] && get_links "$provider_id"
|
||||
if [ "$1" = "5" ] && [ -n "$provider_id" ]; then
|
||||
get_filemoon_links "$provider_id"
|
||||
else
|
||||
[ -n "$provider_id" ] && get_links "$provider_id"
|
||||
fi
|
||||
}
|
||||
|
||||
select_quality() {
|
||||
@@ -204,16 +213,87 @@ select_quality() {
|
||||
episode=$(printf "%s" "$result" | cut -d'>' -f2)
|
||||
}
|
||||
|
||||
decode_tobeparsed() {
|
||||
tmp="$(mktemp)"
|
||||
printf '%s' "$1" | base64 -d >"$tmp"
|
||||
file_size="$(wc -c <"$tmp")"
|
||||
iv="$(dd if="$tmp" bs=1 skip=1 count=12 2>/dev/null | od -A n -t x1 | tr -d ' \n')"
|
||||
ctr="${iv}00000002"
|
||||
ct_len=$((file_size - 13 - 16))
|
||||
plain="$(dd if="$tmp" bs=1 skip=13 count="$ct_len" 2>/dev/null | openssl enc -d -aes-256-ctr -K "$allanime_key" -iv "$ctr" -nosalt -nopad 2>/dev/null)"
|
||||
rm -f "$tmp"
|
||||
printf '%s' "$plain" | tr '{}' '\n' | sed -nE 's|.*"sourceUrl":"--([^"]*)".*"sourceName":"([^"]*)".*|\2 :\1|p'
|
||||
}
|
||||
|
||||
b64url_to_hex() {
|
||||
_len=$(printf '%s' "$1" | wc -c | tr -d ' ')
|
||||
_mod=$((_len % 4))
|
||||
case $_mod in
|
||||
2) _pad="==" ;;
|
||||
3) _pad="=" ;;
|
||||
*) _pad="" ;;
|
||||
esac
|
||||
printf '%s%s' "$1" "$_pad" | tr -- '-_' '+/' | base64 -d | od -A n -t x1 | tr -d ' \n'
|
||||
}
|
||||
|
||||
get_filemoon_links() {
|
||||
response="$(curl -e "$allanime_refr" -s "https://${allanime_base}$1" -A "$agent")"
|
||||
_fm_json="$(printf '%s' "$response" | tr -d '\n ' | tr ',' '\n')"
|
||||
iv="$(printf '%s' "$_fm_json" | sed -nE 's|^"iv":"([^"]*)"$|\1|p')"
|
||||
payload="$(printf '%s' "$_fm_json" | sed -nE 's|^"payload":"([^"]*)"$|\1|p')"
|
||||
kp1="$(printf '%s' "$_fm_json" | sed -nE 's|^"key_parts":\["([^"]*)"$|\1|p')"
|
||||
kp2="$(printf '%s' "$_fm_json" | sed -nE 's|^"([A-Za-z0-9_-]+)"\]$|\1|p' | head -1)"
|
||||
_kp1_hex="$(b64url_to_hex "$kp1")"
|
||||
_kp2_hex="$(b64url_to_hex "$kp2")"
|
||||
key_hex="$_kp1_hex$_kp2_hex"
|
||||
iv_hex="$(b64url_to_hex "$iv")00000002"
|
||||
tmp="$(mktemp)"
|
||||
_fm_len=$(printf '%s' "$payload" | wc -c | tr -d ' ')
|
||||
_fm_mod=$((_fm_len % 4))
|
||||
case $_fm_mod in
|
||||
2) _fm_pad="==" ;;
|
||||
3) _fm_pad="=" ;;
|
||||
*) _fm_pad="" ;;
|
||||
esac
|
||||
printf '%s%s' "$payload" "$_fm_pad" | tr -- '-_' '+/' | base64 -d >"$tmp"
|
||||
ct_len=$(($(wc -c <"$tmp") - 16))
|
||||
plain="$(dd if="$tmp" bs=1 count="$ct_len" 2>/dev/null | openssl enc -d -aes-256-ctr -K "$key_hex" -iv "$iv_hex" -nosalt -nopad 2>/dev/null)"
|
||||
rm -f "$tmp"
|
||||
printf '%s' "$plain" | tr '{}[]' '\n' |
|
||||
sed -nE 's|.*"url":"([^"]*)".*"height":([0-9]+).*|\2 >\1|p;s|.*"height":([0-9]+).*"url":"([^"]*)".*|\1 >\2|p' |
|
||||
sed 's|\\u0026|\&|g;s|\\u003D|=|g' | sort -rn
|
||||
printf "\033[1;32m%s\033[0m Links Fetched\n" "Filemoon" 1>&2
|
||||
}
|
||||
|
||||
# gets embed urls, collects direct links into provider files, selects one with desired quality into $episode
|
||||
get_episode_url() {
|
||||
# get the embed urls of the selected episode
|
||||
#shellcheck disable=SC2016
|
||||
episode_embed_gql='query ($showId: String!, $translationType: VaildTranslationTypeEnumType!, $episodeString: String!) { episode( showId: $showId translationType: $translationType episodeString: $episodeString ) { episodeString sourceUrls }}'
|
||||
|
||||
resp=$(curl -e "$allanime_refr" -s -G "${allanime_api}/api" --data-urlencode "variables={\"showId\":\"$id\",\"translationType\":\"$mode\",\"episodeString\":\"$ep_no\"}" --data-urlencode "query=$episode_embed_gql" -A "$agent" | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":"--([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p')
|
||||
query_hash="d405d0edd690624b66baba3068e0edc3ac90f1597d898a1ec8db4e5c43c00fec"
|
||||
query_vars="{\"showId\":\"$id\",\"translationType\":\"$mode\",\"episodeString\":\"$ep_no\"}"
|
||||
query_ext="{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"$query_hash\"}}"
|
||||
|
||||
encoded_vars=$(printf '%s' "$query_vars" | sed 's/"/%22/g; s/:/%3A/g; s/{/%7B/g; s/}/%7D/g; s/,/%2C/g')
|
||||
encoded_ext=$(printf '%s' "$query_ext" | sed 's/"/%22/g; s/:/%3A/g; s/{/%7B/g; s/}/%7D/g; s/,/%2C/g; s/ /%20/g')
|
||||
|
||||
api_url="${allanime_api}/api?variables=${encoded_vars}&extensions=${encoded_ext}"
|
||||
|
||||
api_resp="$(curl -e "https://youtu-chan.com" -s -A "$agent" -H "Origin: https://youtu-chan.com" "$api_url")"
|
||||
|
||||
if [ -z "$api_resp" ] || ! printf "%s" "$api_resp" | grep -q "tobeparsed"; then
|
||||
api_resp="$(curl -e "$allanime_refr" -s -H "Content-Type: application/json" -X POST "${allanime_api}/api" --data "{\"variables\":{\"showId\":\"$id\",\"translationType\":\"$mode\",\"episodeString\":\"$ep_no\"},\"query\":\"$episode_embed_gql\"}" -A "$agent")"
|
||||
fi
|
||||
|
||||
if printf "%s" "$api_resp" | grep -q '"tobeparsed"'; then
|
||||
blob="$(printf "%s" "$api_resp" | sed -nE 's|.*"tobeparsed":"([^"]*)".*|\1|p')"
|
||||
resp="$(decode_tobeparsed "$blob")"
|
||||
else
|
||||
resp="$(printf "%s" "$api_resp" | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":"--([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p')"
|
||||
fi
|
||||
# generate links into sequential files
|
||||
cache_dir="$(mktemp -d)"
|
||||
providers="1 2 3 4"
|
||||
providers="1 2 3 4 5"
|
||||
for provider in $providers; do
|
||||
generate_link "$provider" >"$cache_dir"/"$provider" &
|
||||
done
|
||||
@@ -234,7 +314,7 @@ search_anime() {
|
||||
#shellcheck disable=SC2016
|
||||
search_gql='query( $search: SearchInput $limit: Int $page: Int $translationType: VaildTranslationTypeEnumType $countryOrigin: VaildCountryOriginEnumType ) { shows( search: $search limit: $limit page: $page translationType: $translationType countryOrigin: $countryOrigin ) { edges { _id name availableEpisodes __typename } }}'
|
||||
|
||||
curl -e "$allanime_refr" -s -G "${allanime_api}/api" --data-urlencode "variables={\"search\":{\"allowAdult\":false,\"allowUnknown\":false,\"query\":\"$1\"},\"limit\":40,\"page\":1,\"translationType\":\"$mode\",\"countryOrigin\":\"ALL\"}" --data-urlencode "query=$search_gql" -A "$agent" | sed 's|Show|\
|
||||
curl -e "$allanime_refr" -s -H "Content-Type: application/json" -X POST "${allanime_api}/api" --data "{\"variables\":{\"search\":{\"allowAdult\":false,\"allowUnknown\":false,\"query\":\"$1\"},\"limit\":40,\"page\":1,\"translationType\":\"$mode\",\"countryOrigin\":\"ALL\"},\"query\":\"$search_gql\"}" -A "$agent" | sed 's|Show|\
|
||||
| g' | sed -nE "s|.*_id\":\"([^\"]*)\",\"name\":\"(.+)\",.*${mode}\":([1-9][^,]*).*|\1 \2 (\3 episodes)|p" | sed 's/\\"//g'
|
||||
}
|
||||
|
||||
@@ -257,7 +337,7 @@ episodes_list() {
|
||||
#shellcheck disable=SC2016
|
||||
episodes_list_gql='query ($showId: String!) { show( _id: $showId ) { _id availableEpisodesDetail }}'
|
||||
|
||||
curl -e "$allanime_refr" -s -G "${allanime_api}/api" --data-urlencode "variables={\"showId\":\"$*\"}" --data-urlencode "query=$episodes_list_gql" -A "$agent" | sed -nE "s|.*$mode\":\[([0-9.\",]*)\].*|\1|p" | sed 's|,|\
|
||||
curl -e "$allanime_refr" -s -H "Content-Type: application/json" -X POST "${allanime_api}/api" --data "{\"variables\":{\"showId\":\"$*\"},\"query\":\"$episodes_list_gql\"}" -A "$agent" | sed -nE "s|.*$mode\":\[([0-9.\",]*)\].*|\1|p" | sed 's|,|\
|
||||
|g; s|"||g' | sort -n -k 1
|
||||
}
|
||||
|
||||
@@ -347,6 +427,7 @@ play_episode() {
|
||||
unset episode
|
||||
update_history
|
||||
[ "$use_external_menu" = "1" ] && wait
|
||||
[ "$use_external_menu" = "2" ] && wait
|
||||
}
|
||||
|
||||
play() {
|
||||
@@ -382,7 +463,8 @@ agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefo
|
||||
allanime_refr="https://allmanga.to"
|
||||
allanime_base="allanime.day"
|
||||
allanime_api="https://api.${allanime_base}"
|
||||
mode="${ANI_CLI_MODE:-dub}"
|
||||
allanime_key="$(printf '%s' 'Xot36i3lK3:v1' | openssl dgst -sha256 -binary | od -A n -t x1 | tr -d ' \n')"
|
||||
mode="${ANI_CLI_MODE:-sub}"
|
||||
download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}"
|
||||
log_episode="${ANI_CLI_LOG:-1}"
|
||||
quality="${ANI_CLI_QUALITY:-best}"
|
||||
@@ -399,9 +481,9 @@ exit_after_play="${ANI_CLI_EXIT_AFTER_PLAY:-0}"
|
||||
use_external_menu="${ANI_CLI_EXTERNAL_MENU:-0}"
|
||||
external_menu_normal_window="${ANI_CLI_EXTERNAL_MENU_NORMAL_WINDOW:-0}"
|
||||
skip_intro="${ANI_CLI_SKIP_INTRO:-0}"
|
||||
# shellcheck disable=SC2154
|
||||
skip_title="$ANI_CLI_SKIP_TITLE"
|
||||
[ -t 0 ] || use_external_menu=1
|
||||
skip_title="${ANI_CLI_SKIP_TITLE:-}"
|
||||
[ -t 0 ] || (command -v dmenu && use_external_menu=2)
|
||||
[ -t 0 ] || (command -v rofi && use_external_menu=1)
|
||||
hist_dir="${ANI_CLI_HIST_DIR:-${XDG_STATE_HOME:-$HOME/.local/state}/ani-cli}"
|
||||
[ ! -d "$hist_dir" ] && mkdir -p "$hist_dir"
|
||||
histfile="$hist_dir/ani-hsts"
|
||||
@@ -466,6 +548,7 @@ while [ $# -gt 0 ]; do
|
||||
--no-detach) no_detach=1 ;;
|
||||
--exit-after-play) exit_after_play=1 && no_detach=1 ;;
|
||||
--rofi) use_external_menu=1 ;;
|
||||
--dmenu) use_external_menu=2 ;;
|
||||
--skip) skip_intro=1 ;;
|
||||
--skip-title)
|
||||
[ $# -lt 2 ] && die "missing argument!"
|
||||
@@ -483,6 +566,10 @@ done
|
||||
[ "$external_menu_normal_window" = "1" ] && external_menu_args="-normal-window"
|
||||
printf "\33[2K\r\033[1;34mChecking dependencies...\033[0m\n"
|
||||
dep_ch "curl" "sed" "grep" || true
|
||||
case "$(uname -o 2>/dev/null)" in
|
||||
*ndroid*) command -v openssl >/dev/null || die 'Program "openssl" not found. On Termux, install with: pkg install openssl-tool' ;;
|
||||
*) dep_ch "openssl" || true ;;
|
||||
esac
|
||||
[ "$skip_intro" = 1 ] && (dep_ch "ani-skip" || true)
|
||||
dep_ch "fzf" || true
|
||||
case "$player_function" in
|
||||
@@ -576,4 +663,4 @@ done
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Project repository: https://github.com/pystardust/ani-cli
|
||||
# Project repository: https://github.com/pystardust/ani-cli
|
||||
|
||||
Executable
+115
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
file="${1:-$HOME/.config/hypr/conf/keybinds.lua}"
|
||||
|
||||
awk '
|
||||
function trim(s) {
|
||||
sub(/^[[:space:]]+/, "", s)
|
||||
sub(/[[:space:]]+$/, "", s)
|
||||
return s
|
||||
}
|
||||
|
||||
function escape_markup(s) {
|
||||
gsub(/&/, "\\&", s)
|
||||
gsub(/</, "\\<", s)
|
||||
gsub(/>/, "\\>", s)
|
||||
return s
|
||||
}
|
||||
|
||||
function print_group_header(name) {
|
||||
if (printed_any_group) {
|
||||
print ""
|
||||
}
|
||||
|
||||
pretty_group = escape_markup(name)
|
||||
printf "<span foreground=\"#f9e2af\"><b>%s</b></span>\n", pretty_group
|
||||
printed_any_group = 1
|
||||
}
|
||||
|
||||
function parse_first_arg(s, depth, in_string, out, i, c, prev) {
|
||||
depth = 0
|
||||
in_string = 0
|
||||
out = ""
|
||||
|
||||
for (i = 1; i <= length(s); i++) {
|
||||
c = substr(s, i, 1)
|
||||
prev = (i > 1 ? substr(s, i - 1, 1) : "")
|
||||
|
||||
if (c == "\"" && prev != "\\") {
|
||||
in_string = !in_string
|
||||
}
|
||||
|
||||
if (!in_string) {
|
||||
if (c == "(") depth++
|
||||
else if (c == ")") depth--
|
||||
else if (c == "," && depth == 0) break
|
||||
}
|
||||
|
||||
out = out c
|
||||
}
|
||||
|
||||
return trim(out)
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
in_keybinds = 0
|
||||
group = ""
|
||||
last_group = ""
|
||||
mainMod = "mainMod"
|
||||
printed_any_group = 0
|
||||
}
|
||||
|
||||
{
|
||||
line = $0
|
||||
|
||||
if (match(line, /^[[:space:]]*local[[:space:]]+mainMod[[:space:]]*=[[:space:]]*"[^"]+"/)) {
|
||||
tmp = line
|
||||
sub(/^[^"]*"/, "", tmp)
|
||||
sub(/".*$/, "", tmp)
|
||||
mainMod = tmp
|
||||
}
|
||||
|
||||
if (line ~ /^[[:space:]]*--[[:space:]]*KeyBinds[[:space:]]*$/) {
|
||||
in_keybinds = 1
|
||||
next
|
||||
}
|
||||
|
||||
if (!in_keybinds)
|
||||
next
|
||||
|
||||
if (line ~ /^[[:space:]]*--[[:space:]]*[^-].*$/) {
|
||||
group = line
|
||||
sub(/^[[:space:]]*--[[:space:]]*/, "", group)
|
||||
group = trim(group)
|
||||
next
|
||||
}
|
||||
|
||||
if (line ~ /hl\.bind[[:space:]]*\(/ && line ~ /--/) {
|
||||
if (group != last_group) {
|
||||
print_group_header(group)
|
||||
last_group = group
|
||||
}
|
||||
|
||||
desc = line
|
||||
sub(/^.*--[[:space:]]*/, "", desc)
|
||||
desc = trim(desc)
|
||||
|
||||
bind = line
|
||||
sub(/^[[:space:]]*hl\.bind[[:space:]]*\(/, "", bind)
|
||||
|
||||
key = parse_first_arg(bind)
|
||||
|
||||
gsub(/[[:space:]]*\.\.[[:space:]]*/, "", key)
|
||||
gsub(/"/, "", key)
|
||||
gsub(/mainMod/, mainMod, key)
|
||||
key = trim(key)
|
||||
|
||||
pretty_key = escape_markup(key)
|
||||
pretty_desc = escape_markup(desc)
|
||||
|
||||
printf " <span foreground=\"#cba6f7\">%s</span> <span foreground=\"#a6adc8\">— %s</span>\n", pretty_key, pretty_desc
|
||||
}
|
||||
}
|
||||
' "$file" | rofi -dmenu -markup-rows -i -p "Keybinds" >/dev/null
|
||||
@@ -9,4 +9,4 @@ while ! hyprctl activewindow | grep -q "Vivaldi"; do
|
||||
sleep 0.05
|
||||
done
|
||||
|
||||
hyprctl dispatch sendshortcut CTRL,F11,activewindow
|
||||
hyprctl dispatch 'hl.dsp.send_shortcut({mods = "CTRL", key = "F11", window = "activewindow"})'
|
||||
|
||||
Reference in New Issue
Block a user