Compare commits

...

5 Commits

Author SHA1 Message Date
coolnsx
cf4b2095eb hacky sack 2025-10-22 22:31:28 +05:30
coolnsx
5f5d065c18 Spinning up the hamster... 2025-10-22 15:56:36 +05:30
coolnsx
870fb04c8e fixes 2025-10-22 15:55:17 +05:30
coolnsx
0338c5c80c ALL SORTS OF THINGS 2025-09-11 16:54:24 +05:30
coolnsx
b4e63b41ab Fix edge, single client, error case 2025-09-10 13:00:57 +05:30
7 changed files with 130 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
#shellcheck disable=SC2086 #shellcheck disable=SC2086,SC2068
menu_droid() { menu_droid() {
fzf --prompt="$1" $2 fzf --prompt="$1" $2
@@ -20,11 +20,11 @@ search_linux() {
} }
torrent_linux() { torrent_linux() {
setsid -f "$TERMINAL" -e "$(dirname "$0")/torrent" "$1" setsid -f "$TERMINAL" -e "${0%/*}/torrent" $@
} }
torrent_droid() { torrent_droid() {
"$(dirname "$0")/torrent" "$1" "${0%/*}/torrent" $@
} }
info_droid() { info_droid() {

View File

@@ -1,25 +1,59 @@
#!/bin/sh #!/bin/sh
# script for downloading videos/audios from sites... # script for downloading videos/audios from sites...
#shellcheck disable=SC2317 #shellcheck disable=SC2317,SC2329
info() { info() {
printf "\033[1;36m[ %s ] [ %s ] %s\033[0m\n" "$2" "$3" "$1" printf "\033[1;36m%s\033[0m\n" "$2" "$3" "$1"
}
error() {
printf "\033[1;31m[ %s ] [ %s ] %s\033[0m\n" "$2" "$3" "$1"
} }
notify_droid() { notify_droid() {
info "$1"
termux-notification -c "$1" termux-notification -c "$1"
} }
notify_linux() { notify_linux() {
info "$1"
notify-send -e "$1" -h "string:x-canonical-private-synchronous:${0##*/}" notify-send -e "$1" -h "string:x-canonical-private-synchronous:${0##*/}"
} }
send_matrix_msg() {
# file existance
[ -f "$1" ] || return 1
# upload file and get URI
file_uri=$(curl "$MX_URL/_matrix/media/v3/upload?filename=$filename" -sX POST -H 'Content-Type: application/octet-stream' -H "Authorization: Bearer $MX_TOKEN" -T "$1" | sed -nE 's|.*"content_uri":"([^"]*)".*|\1|p')
#extract specific data from metadata
filename="${1##*/}"
metadata=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -show_format "$1")
width=$(printf '%s' "$metadata" | sed -nE 's|^width=([^$]*)|\1|p')
height=$(printf '%s' "$metadata" | sed -nE 's|^height=([^$]*)|\1|p')
duration=$(printf '%s' "$metadata" | sed -nE 's|^duration=([^$]*)|\1|p' | tr -d '.' | sed 's/...$//')
durationMSec=$(printf '%d' "$duration")
size=$(printf '%s' "$metadata" | sed -nE 's|^size=([^$]*)|\1|p')
# generate unique key for message
uuid=$(uuidgen)
json='{
"msgtype": "m.video",
"body": "'"$filename"'",
"info": {
"size": "'"$size"'",
"mimetype": "video/mp4",
"duration": "'"$durationMSec"'",
"w": "'"$width"'",
"h": "'"$height"'"
},
"url": "'"$file_uri"'"
}'
# send a message with media URI
curl -sX PUT "$MX_URL/_matrix/client/v3/rooms/${2:-$MX_ROOM}/send/m.room.message/$uuid" -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: Bearer $MX_TOKEN" -d "$json"
}
#main #main
link="$1" link="$1"
yt_dlp_logs="${TMPDIR:-/tmp}/${0##*/}-logs"
case $(uname -o) in case $(uname -o) in
*ndroid*) *ndroid*)
@@ -34,9 +68,28 @@ case $(uname -o) in
;; ;;
esac esac
printf "\033[1;34m Video link :\033[0m %s\n" "$link" printf "\033[1;34m Video link :\033[0m %s" "$link"
yt-dlp --no-skip-unavailable-fragments --fragment-retries infinite -N 16 -t mp4 "$link" -o "$download_dir/%(title)s.%(ext)s" info "Downloading Video.."
notify_$os "Video Downloaded" truncate -s0 "$yt_dlp_logs" # truncate file if exists, creates if doesn't exists
yt-dlp --no-skip-unavailable-fragments --fragment-retries infinite -N 16 -t mp4 "$link" -o "$download_dir/%(title)s.%(ext)s" | tee "$yt_dlp_logs"
filepath=$(sed -nE "s|.*($download_dir.*\.mp4).*|\1|p" "$yt_dlp_logs" | head -1)
#shellcheck disable=SC1091
. "$HOME"/.config/.env
# load matrix creds
matrix_creds
send_matrix_msg "$filepath"
# unload matrix creds
matrix_creds "unload"
notify_$os "Video Sent to Matrix"
rm -f "$filepath"
exit 0 exit 0

51
esphome Executable file
View File

@@ -0,0 +1,51 @@
#!/bin/sh
#shellcheck disable=SC2162
##########
# Config #
##########
url="<ip_of_ur_esphome_server>:6052"
fifo_file="${TMPDIR:-/tmp}/${0##*/}-fifo"
info() {
#shellcheck disable=SC2059
printf "\033[2K\r\033[1;${2:-36}m${1}\033[0m"
}
err() {
info "$1\n" "31"
}
menu() {
fzf --prompt="[Esphome] $1" --layout=reverse --border -d'\t' --with-nth=1
}
run_command() {
# this is done to make sure the file doesn't have anything stale left
rm -f "$fifo_file" && mkfifo "$fifo_file"
printf "%s\n" "$2" >"$fifo_file" &
tail -f "$fifo_file" | websocat "ws://$url/$1" | while read line; do
printf "%b\n" "$line" | sed -nE 's|.*"data": "(.*)n"}|\1|p' &
# exit this loop if we receive exit from response
printf "%b\n" "$line" | grep -q '"exit"' && pkill -P $$ tail &
done
rm -f "$fifo_file"
}
what_to_do=$(printf "logs\nupdate-all\nupdate" | menu "What to Do? >")
[ -z "$what_to_do" ] && err "Please Select Choice!!" && exit 1
if [ "$what_to_do" = "update-all" ]; then
data='{"type":"spawn"}'
else
device=$(curl -s "http://$url/devices" | tr '{}' '\n' | sed -nE 's|.*"friendly_name": "([^"]*)",.*"configuration": "([^"]*)".*|\1\t\2|p' | menu "Select Device >")
[ -z "$device" ] && err "Please Select a Device!!" && exit 1
dev_name=$(printf "%s" "$device" | cut -f1)
dev_config=$(printf "%s" "$device" | cut -f2)
info "Running $what_to_do for $dev_name...\n"
[ "$what_to_do" = 'update' ] && what_to_do="run"
data='{"type":"spawn","configuration":"'"$dev_config"'","port":"OTA"}'
fi
run_command "$what_to_do" "$data"

View File

@@ -93,10 +93,9 @@ mpv_jellyfin() {
[ -z "$1" ] && return 0 [ -z "$1" ] && return 0
[ -z "$2" ] && return 0 [ -z "$2" ] && return 0
ITEM_ID=$(printf '%s' "$1" | sed -E 's/(.{8})(.{4})(.{4})(.{4})(.{12})/\1-\2-\3-\4-\5/')
success "Playing $2 on mpv" success "Playing $2 on mpv"
url="$JF_URL/Items/$1/Download?api_key=$JF_TOKEN" url="$JF_URL/Items/$1/Download?api_key=$JF_TOKEN"
sub="$JF_URL/Videos/$ITEM_ID/$1/Subtitles/0/0/Stream.ass?api_key=$JF_TOKEN" sub="$JF_URL/Videos/$1/$1/Subtitles/0/0/Stream.ass?api_key=$JF_TOKEN"
! curl -s "$sub" | grep -q "Error processing request" && sub_arg="--sub-file=$sub" ! curl -s "$sub" | grep -q "Error processing request" && sub_arg="--sub-file=$sub"
if uname -o | grep -q 'ndroid'; then if uname -o | grep -q 'ndroid'; then
text="Title: $2\nURL: $url" text="Title: $2\nURL: $url"
@@ -109,8 +108,8 @@ mpv_jellyfin() {
fi fi
#shellcheck disable=SC2086 #shellcheck disable=SC2086
nohup mpv --input-ipc-server="$socket" --start="$((playbackPositionTicks / 10000000))" --force-media-title="$2" "$url" $sub_arg >/dev/null 2>&1 & nohup mpv --input-ipc-server="$socket" --start="$((playbackPositionTicks / 10000000))" --force-media-title="$2" "$url" $sub_arg >/dev/null 2>&1 &
skipPositions=$(curl -s "$JF_URL/Episode/$ITEM_ID/IntroSkipperSegments" -H 'Authorization: MediaBrowser Token="'"$JF_TOKEN"'"' -H "Accept: application/json" | sed -nE 's|.*"Introduction".*"IntroStart":([^\.]*).*,"IntroEnd":([^\.]*).*"Credits".*"IntroStart":([^\.]*).*"IntroEnd":([^\.]*).*|op_start=\1;op_end=\2;ed_start=\3;ed_end=\4|p') skipPositions=$(curl -s "$JF_URL/Episode/$1/IntroSkipperSegments" -H 'Authorization: MediaBrowser Token="'"$JF_TOKEN"'"' -H "Accept: application/json" | sed 's|}|\n|g' | sed -nE 's|.*"Introduction".*"IntroStart":([^\.,]*).*,"IntroEnd":([^\.,]*).*|op_start=\1\nop_end=\2|p;s|.*"Credits".*"IntroStart":([^\.,]*).*"IntroEnd":([^\.,]*).*|ed_start=\1\ned_end=\2|p')
track_progress track_progress "$1"
} }
track_progress() { track_progress() {
@@ -137,11 +136,11 @@ while sleep 5;do
position=\$(echo '{"command" :["get_property","playback-time"]}' | socat - "$socket" 2>/dev/null | sed -nE 's_.*data":([^,]*).*_\1_p' | tr -d '.' | sed 's|$|0|g') position=\$(echo '{"command" :["get_property","playback-time"]}' | socat - "$socket" 2>/dev/null | sed -nE 's_.*data":([^,]*).*_\1_p' | tr -d '.' | sed 's|$|0|g')
[ -z "\$position" ] && break [ -z "\$position" ] && break
positionTicks=\$position positionTicks=\$position
positionSec=\$((position / 10000000)) positionSec=\${position::-7}
[ "\$introSkipped" -eq 0 ] && introSkipped=\$(skipPos "\$introSkipped" "\$positionSec" "\$op_start" "\$op_end" "Intro Skipped") [ "\$introSkipped" -eq 0 ] && introSkipped=\$(skipPos "\$introSkipped" "\$positionSec" "\$op_start" "\$op_end" "Intro Skipped")
[ "\$outroSkipped" -eq 0 ] && outroSkipped=\$(skipPos "\$outroSkipped" "\$positionSec" "\$ed_start" "\$ed_end" "Outro Skipped") [ "\$outroSkipped" -eq 0 ] && outroSkipped=\$(skipPos "\$outroSkipped" "\$positionSec" "\$ed_start" "\$ed_end" "Outro Skipped")
done done
[ -n "\$positionTicks" ] && curl -s "$JF_URL/Users/$JF_USER_ID/PlayingItems/$ITEM_ID?positionTicks=\$positionTicks" -X DELETE -H 'Authorization: MediaBrowser Token="'"$JF_TOKEN"'"' -H 'Content-Type: application/json' [ -n "\$positionTicks" ] && curl -s "$JF_URL/Users/$JF_USER_ID/PlayingItems/${1}?positionTicks=\$positionTicks" -X DELETE -H 'Authorization: MediaBrowser Token="$JF_TOKEN"' -H 'Content-Type: application/json'
rm "$socket" rm "$socket"
rm "\$0" rm "\$0"
EOF EOF

2
rss
View File

@@ -15,4 +15,4 @@ name=$(printf "%s" "$data" | sed -nE 's_^.*Please\] (.*)</title>.*size>(.*)</sub
[ -z "$name" ] && exit 0 [ -z "$name" ] && exit 0
id=$(printf "%s" "$name" | sed -nE 's/.*\[(.*)\].*/\1/p') id=$(printf "%s" "$name" | sed -nE 's/.*\[(.*)\].*/\1/p')
magnet=$(printf "%s" "$data" | sed -nE "s_.*<link>(.*$id.*)</link>.*_\1_p" | sed 's/amp;//g') magnet=$(printf "%s" "$data" | sed -nE "s_.*<link>(.*$id.*)</link>.*_\1_p" | sed 's/amp;//g')
torrent_$os "$magnet" torrent_$os "$magnet" "f"

View File

@@ -15,7 +15,7 @@ down() {
error_$os "Torrent: Error!!" error_$os "Torrent: Error!!"
} }
magnet="$*" magnet="$1"
if [ "$(uname -o)" = "Android" ]; then if [ "$(uname -o)" = "Android" ]; then
os="droid" os="droid"
script_dir="$HOME/.shortcuts" script_dir="$HOME/.shortcuts"
@@ -28,7 +28,10 @@ else
[ -z "$magnet" ] && magnet="$(wl-paste)" [ -z "$magnet" ] && magnet="$(wl-paste)"
terminal="${TERMINAL:-foot}" terminal="${TERMINAL:-foot}"
prefix="setsid -f $terminal -e" prefix="setsid -f $terminal -e"
pgrep -af "$0" | grep -q "$terminal" || { $prefix "$0" "$magnet"; exit 0; } pgrep -af "$0" | grep -q "$terminal" || {
$prefix "$0" "$magnet"
exit 0
}
fi fi
#import generic functions #import generic functions
@@ -49,7 +52,7 @@ fi
echo "$magnet" echo "$magnet"
printf "${c_yellow}Download>>\n${c_green}[f]ull torrent\n${c_cyan}[p]artial torrent \n${c_red}[q]uit" printf "${c_yellow}Download>>\n${c_green}[f]ull torrent\n${c_cyan}[p]artial torrent \n${c_red}[q]uit"
printf "${c_reset}\n\tenter choice:" printf "${c_reset}\n\tenter choice:"
read -r ch [ -z "$2" ] && read -r ch || ch=$2
case $ch in case $ch in
f) f)
down "$magnet" down "$magnet"

View File

@@ -291,7 +291,6 @@ yt_agent="com.google.android.youtube/$yt_ver (Linux; U; Android 1$random_no) gzi
yt_music_ver="8.23.51" yt_music_ver="8.23.51"
yt_music_agent="com.google.android.apps.youtube.music/$yt_music_ver (Linux; U; Android 1$random_no) gzip" yt_music_agent="com.google.android.apps.youtube.music/$yt_music_ver (Linux; U; Android 1$random_no) gzip"
#call this script by script-name "function_name" "query" #call this script by script-name "function_name" "query"
[ -z "$1" ] && help "$@" [ -z "$1" ] && help "$@"
$1 "$2" "$3" $1 "$2" "$3"