minor changes

This commit is contained in:
coolnsx
2023-07-03 22:50:31 +05:30
parent 31b2570cf3
commit 9287e03f41
9 changed files with 333 additions and 340 deletions

View File

@@ -1,49 +1,49 @@
#!/bin/sh #!/bin/sh
menu_droid() { menu_droid() {
fzf --prompt="$1" $2 fzf --prompt="$1" $2
} }
menu_linux() { menu_linux() {
bemenu --fn 'Cascadia Mono 15' -i -c -W 0.6 -B 3 -l 25 -p "$1" bemenu --fn 'Cascadia Mono 15' -i -c -W 0.6 -B 3 -l 25 -p "$1"
} }
search_droid() { search_droid() {
printf "%s" "$1" && read -r query printf "%s" "$1" && read -r query
} }
search_linux() { search_linux() {
query=$(: | menu_linux "$1 ") query=$(: | menu_linux "$1 ")
} }
torrent_linux() { torrent_linux() {
setsid -f "$TERMINAL" -e "$HOME/repos_scripts/torrent" "$1" setsid -f "$TERMINAL" -e "$HOME/repos_scripts/torrent" "$1"
} }
torrent_droid() { torrent_droid() {
"$HOME/torrent" "$1" "$HOME/torrent" "$1"
} }
info_droid() { info_droid() {
printf "\n\r\033[1;36m%s" "$1" printf "\n\r\033[1;36m%s" "$1"
} }
info_linux() { info_linux() {
notify-send "$1" -r '10' -i "$2" notify-send "$1" -r '10' -i "$2"
} }
error_droid() { error_droid() {
printf "\33[2K\r\033[1;31m%s" "$1" printf "\33[2K\r\033[1;31m%s" "$1"
} }
error_linux() { error_linux() {
notify-send -u "critical" "$1" -r '10' notify-send -u "critical" "$1" -r '10'
} }
player_droid() { player_droid() {
am start --user 0 -a android.intent.action.VIEW -d "$1" -n is.xyz.mpv/.MPVActivity >/dev/null 2>&1 am start --user 0 -a android.intent.action.VIEW -d "$1" -n is.xyz.mpv/.MPVActivity >/dev/null 2>&1
} }
player_linux() { player_linux() {
setsid -f mpv "$1" --force-media-title="$2" setsid -f mpv "$1" --force-media-title="$2"
} }

105
ani-new
View File

@@ -1,59 +1,63 @@
#!/bin/sh #!/bin/sh
down() { down() {
info_$os "$3 links fetched.." [ -n "$debug" ] && printf "\033[1;32m %s\033[0m : %s\n" "$3" "$2" && return 0
choice=$(printf "stream\ndownload\ncast\nnext mirror" | menu_$os "??") info_$os "$3 links fetched.."
[ -z "$choice" ] && exit 0 choice=$(printf "stream\ndownload\ncast\nnext mirror" | menu_$os "??")
[ "$choice" = "stream" ] && player_$os "$2" "$title" && info_$os "opening $title" "mpv" && exit 0 [ -z "$choice" ] && exit 0
[ "$choice" = "cast" ] && info_$os "casting $title" "podcast" && catt cast "$2" && exit 0 [ "$choice" = "stream" ] && player_$os "$2" "$title" && info_$os "opening $title" "mpv" && exit 0
[ "$choice" = "next mirror" ] && return 0 [ "$choice" = "cast" ] && info_$os "casting $title" "podcast" && catt cast "$2" && exit 0
info_$os "Downloading $title" "downloader" [ "$choice" = "next mirror" ] && return 0
case $2 in info_$os "Downloading $title" "downloader"
*m3u*) $terminal hls -n 300 -ro "$download_dir/$title" "$2" || (error_$os "Downloading failed $title" && exit 0) ;; case $2 in
*) $terminal aria2c -U "$agent" --check-certificate=false -d "$download_dir" --summary-interval=0 -x 16 -s 16 --referer="$1" "$2" -o "$title.mp4" --download-result=hide || (error_$os "Downloading failed $title" && exit 0) ;; *m3u*) $terminal hls -n 300 -ro "$download_dir/$title" "$2" || (error_$os "Downloading failed $title" && exit 0) ;;
esac *) $terminal aria2c -U "$agent" --check-certificate=false -d "$download_dir" --summary-interval=0 -x 16 -s 16 --referer="$1" "$2" -o "$title.mp4" --download-result=hide || (error_$os "Downloading failed $title" && exit 0) ;;
info_$os "Episode Downloaded $title" esac
exit 0 info_$os "Episode Downloaded $title"
exit 0
} }
decrypt_allanime() { decrypt_allanime() {
for hex in $(printf '%s' "$1" | sed 's/../&\n/g'); do printf "%s" "$-" | grep -q 'x' && set +x
dec=$(printf '%d' "0x$hex") for hex in $(printf '%s' "$1" | sed 's/../&\n/g'); do
xor=$((dec ^ 48)) dec=$(printf '%d' "0x$hex")
oct=$(printf "%03o" "$xor") xor=$((dec ^ 48))
#shellcheck disable=SC2059 oct=$(printf "%03o" "$xor")
printf "\\$oct" #shellcheck disable=SC2059
done printf "\\$oct"
done
printf "%s" "$-" | grep -q 'x' || set -x
} }
provider_run() { provider_run() {
info_$os "Fetching $1 links" info_$os "Fetching $1 links"
provider_id="$(decrypt_allanime "$(printf "%s" "$data" | sed -n "$2" | head -1 | cut -d':' -f2)" | sed "s/\/clock/\/clock\.json/")" provider_id="$(decrypt_allanime "$(printf "%s" "$data" | sed -n "$2" | head -1 | cut -d':' -f2)" | sed "s/\/clock/\/clock\.json/")"
[ -z "$provider_id" ] && return 0 [ -z "$provider_id" ] && return 0
provider_video=$(curl -s "https://embed.ssbcontent.site$provider_id" | sed 's|},{|\n|g' | sed -nE 's|.*link":"([^"]*)".*"resolutionStr":"([^"]*)".*|\1|p;s|.*hls","url":"([^"]*)".*"hardsub_lang":"en-US".*|\1|p' | head -1) provider_video=$(curl -s "https://embed.ssbcontent.site$provider_id" | sed 's|},{|\n|g' | sed -nE 's|.*link":"([^"]*)".*"resolutionStr":"([^"]*)".*|\1|p;s|.*hls","url":"([^"]*)".*"hardsub_lang":"en-US".*|\1|p')
[ -z "$provider_video" ] && return 0 [ -z "$provider_video" ] && return 0
[ -n "$3" ] && printf "%s : %s\n" "$1" "$provider_video" && return 0 case $provider_video in
case $provider_video in *repackager.wixmp.com*) down "$base_url" "$(printf %s "$provider_video" | head -1 | cut -d',' -f1,2 | tr -d ',' | sed 's|repackager.wixmp.com/||g')/mp4/file.mp4" "$1" ;;
*repackager.wixmp.com*) down "$base_url" "$(printf %s "$provider_video" | cut -d',' -f1,2 | tr -d ',' | sed 's|repackager.wixmp.com/||g')/mp4/file.mp4" "$1" ;; *rmbl.ws*) down "$base_url" "$(printf %s "$provider_video" | tail -1)" "$1" ;;
*) down "$base_url" "$provider_video" "$1" ;; *) down "$base_url" "$(printf %s "$provider_video" | head -1)" "$1" ;;
esac esac
} }
base_url="https://api.allanime.day" base_url="https://api.allanime.day"
agent="Mozilla/5.0" agent="Mozilla/5.0"
[ -n "$2" ] && debug=1
case $(uname -o) in case $(uname -o) in
*ndroid*) *ndroid*)
os="droid" os="droid"
download_dir="/sdcard" download_dir="/sdcard"
script_dir="$HOME" script_dir="$HOME"
;; ;;
*) *)
os="linux" os="linux"
download_dir="$HOME/Downloads" download_dir="$HOME/Downloads"
terminal="foot -e" terminal="foot -e"
script_dir="$HOME/repos_scripts" script_dir="$HOME/repos_scripts"
;; ;;
esac esac
# shellcheck source=./.functions # shellcheck source=./.functions
@@ -83,21 +87,10 @@ provider_run "wetransfer" "/Kir :/p" "$2"
#sharepoint links #sharepoint links
provider_run "sharepoint" "/S-mp4 :/p" "$2" provider_run "sharepoint" "/S-mp4 :/p" "$2"
#rumble links
provider_run "rumble" "/Rab :/p" "$2"
#gogoplay links #gogoplay links
provider_run "gogoplay" "/Luf-mp4 :/p" "$2" provider_run "gogoplay" "/Luf-mp4 :/p" "$2"
id=$(printf "%s" "$data" | sed -nE 's/Vid-mp4 :.*?id=([^&]*).*/\1/p') [ -z "$2" ] && error_$os "no more mirror links..sorry" && exit 0
[ -z "$id" ] && error_$os "no more mirror links..sorry" && exit 0
resp="$(curl -A "$agent" -s "https://playtaku.net/streaming.php?id=$id" | sed -nE 's/.*data-status="1".*data-video="(.*)">.*/\1/p')"
info_$os "Fetching mp4upload links"
mp4up_link=$(printf "%s" "$resp" | grep "mp4upload")
[ -z "$mp4up_link" ] || mp4up_video=$(curl -A "$agent" -s "$mp4up_link" -H "DNT: 1" | sed -nE 's_.*embed\|(.*)\|.*blank.*\|(.*)\|(.*)\|(.*)\|(.*)\|src.*_https://\1.mp4upload.com:\5/d/\4/\3.\2_p')
[ -z "$mp4up_video" ] || down "$mp4up_link" "$mp4up_video" "mp4upload"
info_$os "Fetching xstreamcdn links"
fb_id=$(printf "%s" "$resp" | sed -n "s_.*fembed.*/v/__p")
[ -z "$fb_id" ] || fb_video=$(curl -A "$agent" -s -X POST "https://fembed-hd.com/api/source/$fb_id" -H "x-requested-with:XMLHttpRequest" | sed -e 's/\\//g' -e 's/.*data"://' | tr "}" "\n" | sed -nE 's/.*file":"(.*)","label.*/\1/p' | tail -1)
[ -z "$fb_video" ] || down "https://fembed-hd.com/v/$fb_id" "$fb_video" "xstreamcdn"
error_$os "no more mirror links..sorry" && exit 0

242
fap-cli
View File

@@ -9,106 +9,106 @@ c_cyan="\033[1;36m"
c_reset="\033[0m" c_reset="\033[0m"
help_text() { help_text() {
while IFS= read -r line; do while IFS= read -r line; do
printf "%s\n" "$line" printf "%s\n" "$line"
done <<-EOF done <<-EOF
Usage: Usage:
${0##*/} [-d | -p <download_dir>] [<query>] ${0##*/} [-d | -p <download_dir>] [<query>]
${0##*/} [-v] [<query>] ${0##*/} [-v] [<query>]
${0##*/} -h ${0##*/} -h
Options: Options:
-h show helptext -h show helptext
-d download video -d download video
-p download video to specified directory -p download video to specified directory
-v use VLC as the media player -v use VLC as the media player
EOF EOF
} }
err() { err() {
printf "$c_red%s$c_reset\n" "$*" >&2 printf "$c_red%s$c_reset\n" "$*" >&2
} }
get_query() { get_query() {
[ -z "$*" ] && printf "${c_green}Search>${c_reset} " && read -r query || query=$* [ -z "$*" ] && printf "${c_green}Search>${c_reset} " && read -r query || query=$*
query=$(printf "%s" "$query" | tr " " "+") query=$(printf "%s" "$query" | tr " " "+")
} }
input() { input() {
printf "$c_yellow Episode??(1-%s)>$c_reset " "$1" printf "$c_yellow Episode??(1-%s)>$c_reset " "$1"
read -r x read -r x
while [ -z "$x" ] || ! [ "$x" -eq "$x" ] 2>/dev/null || [ "$x" -lt "1" ] 2>/dev/null || [ "$x" -gt "$1" ] 2>/dev/null; do while [ -z "$x" ] || ! [ "$x" -eq "$x" ] 2>/dev/null || [ "$x" -lt "1" ] 2>/dev/null || [ "$x" -gt "$1" ] 2>/dev/null; do
err "Invalid choice" err "Invalid choice"
printf "$c_yellow Episode??(1-%s)>$c_reset " "$1" printf "$c_yellow Episode??(1-%s)>$c_reset " "$1"
read -r x read -r x
done done
ep_no=$x ep_no=$x
unset x unset x
} }
stream() { stream() {
case $player_fn in case $player_fn in
vlc) vlc)
uname -a | grep -qE "[Aa]ndroid" && am start --user 0 -a android.intent.action.VIEW -d "$1" -n org.videolan.vlc/org.videolan.vlc.gui.video.VideoPlayerActivity -e "title" "$2" >/dev/null 2>&1 || setsid -f "$player_fn" --http-referrer="$base_url" "$1" >/dev/null 2>&1 uname -a | grep -qE "[Aa]ndroid" && am start --user 0 -a android.intent.action.VIEW -d "$1" -n org.videolan.vlc/org.videolan.vlc.gui.video.VideoPlayerActivity -e "title" "$2" >/dev/null 2>&1 || setsid -f "$player_fn" --http-referrer="$base_url" "$1" >/dev/null 2>&1
;; ;;
mpv) mpv)
uname -a | grep -qE "[Aa]ndroid" && am start --user 0 -a android.intent.action.VIEW -d "$1" -n is.xyz.mpv/.MPVActivity >/dev/null 2>&1 || setsid -f "$player_fn" "$1" --referrer="$base_url" --force-media-title="$2" >/dev/null 2>&1 uname -a | grep -qE "[Aa]ndroid" && am start --user 0 -a android.intent.action.VIEW -d "$1" -n is.xyz.mpv/.MPVActivity >/dev/null 2>&1 || setsid -f "$player_fn" "$1" --referrer="$base_url" --force-media-title="$2" >/dev/null 2>&1
;; ;;
esac esac
} }
download() { download() {
printf "${c_blue}Downloading %s${c_reset}\n" "$2" printf "${c_blue}Downloading %s${c_reset}\n" "$2"
case $1 in case $1 in
*m3u8) *m3u8)
hls -n 300 -ro "$download_dir/$2" "$1" hls -n 300 -ro "$download_dir/$2" "$1"
;; ;;
*) *)
aria2c --summary-interval=0 -x 16 -s 16 --referer="$base_url" "$1" --dir=$download_dir -o "$2.mp4" --download-result=hide aria2c --summary-interval=0 -x 16 -s 16 --referer="$base_url" "$1" --dir=$download_dir -o "$2.mp4" --download-result=hide
;; ;;
esac esac
} }
get_show() { get_show() {
printf "${c_blue}Searching query.." printf "${c_blue}Searching query.."
results=$(curl -s "$base_url/?s=$query" | sed -nE 's_^[[:space:]]*<a href="https://hentaimama.io/tvshows/(.*)/">.$_\1_p') results=$(curl -s "$base_url/?s=$query" | sed -nE 's_^[[:space:]]*<a href="https://hentaimama.io/tvshows/(.*)/">.$_\1_p')
[ -z "$results" ] && printf "\33[2K\r${c_red}No search results found${c_reset}" && exit 0 [ -z "$results" ] && printf "\33[2K\r${c_red}No search results found${c_reset}" && exit 0
printf "\33[2K\r${c_green}Results found\n" printf "\33[2K\r${c_green}Results found\n"
result=$(printf "%s" "$results" | fzf --layout="reverse" --border --height=10) result=$(printf "%s" "$results" | fzf --layout="reverse" --border --height=10)
[ -z "$result" ] && err "No hentai selected" && exit 0 [ -z "$result" ] && err "No hentai selected" && exit 0
printf "${c_magenta}selected $result\n${c_blue}Fetching episode list" printf "${c_magenta}selected $result\n${c_blue}Fetching episode list"
ep_list=$(curl -s "$base_url/tvshows/$result/" | sed -nE 's_^[[:space:]]*<a href="https://hentaimama.io/(.*)/">.$_\1_p' | tac) ep_list=$(curl -s "$base_url/tvshows/$result/" | sed -nE 's_^[[:space:]]*<a href="https://hentaimama.io/(.*)/">.$_\1_p' | tac)
noofeps=$(printf "%s\n" "$ep_list" | wc -l) noofeps=$(printf "%s\n" "$ep_list" | wc -l)
printf "\33[2K\r${c_green}Episodes list fetched\n" printf "\33[2K\r${c_green}Episodes list fetched\n"
[ "$noofeps" -eq 1 ] && ep_no=1 || input "$noofeps" [ "$noofeps" -eq 1 ] && ep_no=1 || input "$noofeps"
get_ep_link get_ep_link
} }
get_ep_link() { get_ep_link() {
tput clear tput clear
printf "${c_blue}Loading Episode $ep_no" printf "${c_blue}Loading Episode $ep_no"
ep_id=$(printf "%s" "$ep_list" | sed -n "${ep_no}p") ep_id=$(printf "%s" "$ep_list" | sed -n "${ep_no}p")
id=$(curl -s "$base_url/$ep_id/" | sed -nE "s/.*?p=(.*)'.*/\1/p") id=$(curl -s "$base_url/$ep_id/" | sed -nE "s/.*?p=(.*)'.*/\1/p")
display=$(printf "%s" "$ep_id" | cut -d'/' -f2- | tr "-" " ") display=$(printf "%s" "$ep_id" | cut -d'/' -f2- | tr "-" " ")
[ -z "$id" ] && printf "\33[2K\r${c_red}Episode doesn't exist on this site${c_reset}" || play_link [ -z "$id" ] && printf "\33[2K\r${c_red}Episode doesn't exist on this site${c_reset}" || play_link
} }
play_link() { play_link() {
printf "\33[2K\r${c_blue}Fetching video link" printf "\33[2K\r${c_blue}Fetching video link"
data="$(curl -s "$(curl -s "$base_url/wp-admin/admin-ajax.php" -d "action=get_player_contents&a=$id" -H "X-Requested-With:XMLHttpRequest" | tr -d '\\' | sed -nE 's/.*src="(.*)" width.*,.*/\1/p')")" data="$(curl -s "$(curl -s "$base_url/wp-admin/admin-ajax.php" -d "action=get_player_contents&a=$id" -H "X-Requested-With:XMLHttpRequest" | tr -d '\\' | sed -nE 's/.*src="(.*)" width.*,.*/\1/p')")"
video_link="$(printf "%s" "$data" | sed -nE 's/[[:space:]]*<source src="(.*)" typ.*/\1/p')" video_link="$(printf "%s" "$data" | sed -nE 's/[[:space:]]*<source src="(.*)" typ.*/\1/p')"
[ -z "$video_link" ] && video_link="$(printf "%s" "$data" | sed -nE 's/[[:space:]]*file: "(.*)".$/\1/p')" [ -z "$video_link" ] && video_link="$(printf "%s" "$data" | sed -nE 's/[[:space:]]*file: "(.*)".$/\1/p')"
if [ -z "$video_link" ]; then if [ -z "$video_link" ]; then
printf "\33[2K\r${c_red}Video Url not found${c_reset}\n" printf "\33[2K\r${c_red}Video Url not found${c_reset}\n"
else else
printf "\33[2K\r${c_green}Video link fetched${c_reset}\n" printf "\33[2K\r${c_green}Video link fetched${c_reset}\n"
printf "\n%s\n" "$video_link" printf "\n%s\n" "$video_link"
if [ "$is_download" -eq "0" ]; then if [ "$is_download" -eq "0" ]; then
stream "$video_link" "$display" stream "$video_link" "$display"
else else
download "$video_link" "$display" download "$video_link" "$display"
fi fi
fi fi
} }
trap "exit 0" INT HUP trap "exit 0" INT HUP
@@ -118,22 +118,22 @@ is_download=0
download_dir=. download_dir=.
while getopts 'dhp:v' OPT; do while getopts 'dhp:v' OPT; do
case $OPT in case $OPT in
d) d)
is_download=1 is_download=1
;; ;;
p) p)
is_download=1 is_download=1
download_dir=$OPTARG download_dir=$OPTARG
;; ;;
v) v)
player_fn="vlc" player_fn="vlc"
;; ;;
* | h) * | h)
help_text help_text
exit 0 exit 0
;; ;;
esac esac
done done
shift $((OPTIND - 1)) shift $((OPTIND - 1))
@@ -141,35 +141,35 @@ get_query "$*"
get_show get_show
while :; do while :; do
printf "\n${c_green}Currently playing %s/%s\n" "$display" "$noofeps" printf "\n${c_green}Currently playing %s/%s\n" "$display" "$noofeps"
[ "$ep_no" != "$noofeps" ] && printf "$c_yellow(%s) %s$c_reset\n" "n" "next" [ "$ep_no" != "$noofeps" ] && printf "$c_yellow(%s) %s$c_reset\n" "n" "next"
[ "$ep_no" != "1" ] && printf "$c_cyan(%s) %s$c_reset\n" "p" "previous" [ "$ep_no" != "1" ] && printf "$c_cyan(%s) %s$c_reset\n" "p" "previous"
printf "$c_magenta(%s) %s$c_reset\n" "d" "download current video" printf "$c_magenta(%s) %s$c_reset\n" "d" "download current video"
printf "$c_blue(%s) %s$c_reset\n" "e" "select episode" printf "$c_blue(%s) %s$c_reset\n" "e" "select episode"
printf "$c_red(%s) %s$c_reset\n" "q" "exit" printf "$c_red(%s) %s$c_reset\n" "q" "exit"
printf "${c_green}>$c_reset " printf "${c_green}>$c_reset "
read choice read choice
case $choice in case $choice in
d) d)
download "$video_link" "$display" download "$video_link" "$display"
;; ;;
n) n)
ep_no=$((ep_no + 1)) ep_no=$((ep_no + 1))
[ "$ep_no" -gt "$noofeps" ] && err "Episode out of range" && ep_no=$((ep_no - 1)) || get_ep_link [ "$ep_no" -gt "$noofeps" ] && err "Episode out of range" && ep_no=$((ep_no - 1)) || get_ep_link
;; ;;
p) p)
ep_no=$((ep_no - 1)) ep_no=$((ep_no - 1))
[ "$ep_no" -lt "1" ] && err "Episode out of range" && ep_no=$((ep_no + 1)) || get_ep_link [ "$ep_no" -lt "1" ] && err "Episode out of range" && ep_no=$((ep_no + 1)) || get_ep_link
;; ;;
e) e)
input "$noofeps" input "$noofeps"
get_ep_link get_ep_link
;; ;;
q) q)
break break
;; ;;
*) *)
err "invalid choice" err "invalid choice"
;; ;;
esac esac
done done

8
rss
View File

@@ -1,11 +1,11 @@
#!/bin/sh #!/bin/sh
if [ "$(uname -o)" = "Android" ]; then if [ "$(uname -o)" = "Android" ]; then
os="droid" os="droid"
script_dir="$HOME" script_dir="$HOME"
else else
os="linux" os="linux"
script_dir="$HOME/repos_scripts" script_dir="$HOME/repos_scripts"
fi fi
. $script_dir/.functions . $script_dir/.functions

26
tor-bay
View File

@@ -2,25 +2,25 @@
#this script uses the piratesbay api to search for torrents #this script uses the piratesbay api to search for torrents
cal_size() { cal_size() {
printf "%.03f\n" "$(($1 / 1000))e-6" printf "%.03f\n" "$(($1 / 1000))e-6"
} }
display() { display() {
for i in $(seq $(printf "%s\nlol" "$2" | wc -l)); do for i in $(seq $(printf "%s\nlol" "$2" | wc -l)); do
printf "[%s GB;S:%s\n" "$(cal_size "$(printf "%s" "$1" | sed -n "${i}p")")" "$(printf "%s" "$2" | sed -n "${i}p")" & printf "[%s GB;S:%s\n" "$(cal_size "$(printf "%s" "$1" | sed -n "${i}p")")" "$(printf "%s" "$2" | sed -n "${i}p")" &
done done
wait wait
} }
case $(uname -o) in case $(uname -o) in
*ndroid*) *ndroid*)
os="droid" os="droid"
script_dir="$HOME" script_dir="$HOME"
;; ;;
*) *)
os="linux" os="linux"
script_dir="$HOME/repos_scripts" script_dir="$HOME/repos_scripts"
;; ;;
esac esac
. $script_dir/.functions . $script_dir/.functions

16
tor-cli
View File

@@ -1,14 +1,14 @@
#!/bin/sh #!/bin/sh
case $(uname -o) in case $(uname -o) in
*ndroid*) *ndroid*)
os="droid" os="droid"
script_dir="$HOME" script_dir="$HOME"
;; ;;
*) *)
os="linux" os="linux"
script_dir="$HOME/repos_scripts" script_dir="$HOME/repos_scripts"
;; ;;
esac esac
. $script_dir/.functions . $script_dir/.functions

44
torrent
View File

@@ -7,17 +7,17 @@ c_cyan="\033[1;36m"
c_reset="\033[0m" c_reset="\033[0m"
down() { down() {
tput reset tput reset
info_$os "Torrent: Downloading" info_$os "Torrent: Downloading"
aria2c -d Downloads --select-file=$2 --seed-time=0 $1 && info_$os "Torrent: Download complete" && rm -f $file || error_$os "Torrent: Error!!" aria2c -d Downloads --select-file=$2 --seed-time=0 $1 && info_$os "Torrent: Download complete" && rm -f $file || error_$os "Torrent: Error!!"
} }
if [ "$(uname -o)" = "Android" ]; then if [ "$(uname -o)" = "Android" ]; then
os="droid" os="droid"
script_dir="$HOME" script_dir="$HOME"
else else
os="linux" os="linux"
script_dir="$HOME/repos_scripts" script_dir="$HOME/repos_scripts"
fi fi
. $script_dir/.functions . $script_dir/.functions
@@ -28,19 +28,19 @@ printf "${c_yellow}Download>>\n${c_green}[f]ull torrent\n${c_cyan}[p]artial torr
printf "${c_reset}\n\tenter choice:" printf "${c_reset}\n\tenter choice:"
read -r ch read -r ch
case $ch in case $ch in
f) f)
down "$magnet" down "$magnet"
;; ;;
p) p)
aria2c --dir=$HOME/.cache --bt-metadata-only=true --bt-save-metadata=true "$magnet" aria2c --dir=$HOME/.cache --bt-metadata-only=true --bt-save-metadata=true "$magnet"
tput reset tput reset
aria2c --show-files=true $HOME/.cache/*.torrent aria2c --show-files=true $HOME/.cache/*.torrent
printf "Enter file idx(default=all):" printf "Enter file idx(default=all):"
read -r ind read -r ind
down "$HOME/.cache/*.torrent" "$ind" down "$HOME/.cache/*.torrent" "$ind"
rm -f $HOME/.cache/*.torrent rm -f $HOME/.cache/*.torrent
;; ;;
q) q)
exit 0 exit 0
;; ;;
esac esac

20
youtube
View File

@@ -10,11 +10,11 @@ c_cyan="\033[1;36m"
c_reset="\033[0m" c_reset="\033[0m"
part() { part() {
printf "${c_magenta}Enter Starting Point(hh:mm:ss)or(mm:ss)${c_reset}:" printf "${c_magenta}Enter Starting Point(hh:mm:ss)or(mm:ss)${c_reset}:"
read start read start
printf "${c_yellow}Enter Upto Seconds:${c_cyan}" printf "${c_yellow}Enter Upto Seconds:${c_cyan}"
read dur read dur
ffmpeg -loglevel error -stats -i $(yt-dlp -f "$3" --get-url "$1") -ss $start -t $dur /sdcard/$(date +%s).$2 ffmpeg -loglevel error -stats -i $(yt-dlp -f "$3" --get-url "$1") -ss $start -t $dur /sdcard/$(date +%s).$2
} }
#program starts from here.. #program starts from here..
@@ -25,9 +25,9 @@ printf "${c_yellow}Download>>\n${c_blue}[a]Audio only\n${c_magenta}[f]part of Au
printf "\n${c_reset}Enter choice:${c_green}" printf "\n${c_reset}Enter choice:${c_green}"
read choice read choice
case $choice in case $choice in
a) yt-dlp -f 'ba' -x --audio-format mp3 "$x" -o "/sdcard/%(title)s.%(ext)s" && termux-notification -c "audio downloaded" ;; a) yt-dlp -f 'ba' -x --audio-format mp3 "$x" -o "/sdcard/%(title)s.%(ext)s" && termux-notification -c "audio downloaded" ;;
f) part "$x" "mp3" "ba" && termux-notification -c "audio downloaded" ;; f) part "$x" "mp3" "ba" && termux-notification -c "audio downloaded" ;;
v) yt-dlp "$x" -o "/sdcard/%(title)s.%(ext)s" && termux-notification -c "video downloaded" ;; v) yt-dlp "$x" -o "/sdcard/%(title)s.%(ext)s" && termux-notification -c "video downloaded" ;;
p) part "$x" "mp4" "b" && termux-notification -c "video downloaded" ;; p) part "$x" "mp4" "b" && termux-notification -c "video downloaded" ;;
q) exit 0 ;; q) exit 0 ;;
esac esac

186
yt-music
View File

@@ -1,34 +1,34 @@
#!/bin/sh #!/bin/sh
help() { help() {
case $1 in case $1 in
search*) search*)
name="search_play" name="search_play"
args='"search_query"' args='"search_query"'
description="this function first searches the $args, then opens the menu(fzf,[d|be]menu,[t|r|w]ofi) with the results,then calls the play function to play the music" description="this function first searches the $args, then opens the menu(fzf,[d|be]menu,[t|r|w]ofi) with the results,then calls the play function to play the music"
;; ;;
play) play)
name="play" name="play"
args='"valid_youtube_url_or_id"' args='"valid_youtube_url_or_id"'
description="immediately plays the $args in mpv(audio only)" description="immediately plays the $args in mpv(audio only)"
;; ;;
loop) loop)
name="loop" name="loop"
args='"print"' args='"print"'
description="this function runs in a loop to play the next music if the current music is successfully finished description="this function runs in a loop to play the next music if the current music is successfully finished
this function should be put as background process or put it in startup this function should be put as background process or put it in startup
passing print argument will show the progress to stdout" passing print argument will show the progress to stdout"
;; ;;
play*) play*)
name="play_next" name="play_next"
args='"menu"' args='"menu"'
description="immediately plays the next song stored in $logdir/next file in mpv if argument is empty description="immediately plays the next song stored in $logdir/next file in mpv if argument is empty
passing $args argument will show the $args(fzf,[d|be]menu,[t|r|w]ofi) for selecting what should be played" passing $args argument will show the $args(fzf,[d|be]menu,[t|r|w]ofi) for selecting what should be played"
;; ;;
*) *)
name="[ <function_name> ]" name="[ <function_name> ]"
args="[ <function_arg> ]" args="[ <function_arg> ]"
description=" description="
<function_name> <function_arg> <function_description> <function_name> <function_arg> <function_description>
search_play search_query searches first then plays the music in mpv search_play search_query searches first then plays the music in mpv
@@ -39,58 +39,58 @@ help() {
tip: tip:
type ${0##*/} help <function_name> to get individual help type ${0##*/} help <function_name> to get individual help
" "
;; ;;
esac esac
while read -r line; do while read -r line; do
printf "%s\n" "$line" printf "%s\n" "$line"
done <<-EOF done <<-EOF
Usage : Usage :
${0##*/} $name $args ${0##*/} $name $args
Description : Description :
$description $description
EOF EOF
exit 0 exit 0
} }
get_data() { get_data() {
curl -X POST -A "$agent" -s "$base_url/youtubei/v1/$1?key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30&prettyPrint=false" -H "content-type:application/json" -H "x-youtube-client-name:67" -H "x-youtube-client-version:1.20221128.01.00" -d "$2" -b "$cookie" -e "$base_url/$3" -c "$cookie" curl -X POST -A "$agent" -s "$base_url/youtubei/v1/$1?key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30&prettyPrint=false" -H "content-type:application/json" -H "x-youtube-client-name:67" -H "x-youtube-client-version:1.20221128.01.00" -d "$2" -b "$cookie" -e "$base_url/$3" -c "$cookie"
} }
loop() { loop() {
#this function does exactly what it says, it should run in the background, u can even put this in startup #this function does exactly what it says, it should run in the background, u can even put this in startup
#it plays next song after the current song get played completely,it does nothing until u run the search_play function then this script kicks in #it plays next song after the current song get played completely,it does nothing until u run the search_play function then this script kicks in
#call it by script-name "loop" "print" for printing the remaining time in terminal #call it by script-name "loop" "print" for printing the remaining time in terminal
#call it by script-name "loop" for anonymously #call it by script-name "loop" for anonymously
trap "rm -f $logdir/next;exit" INT HUP TERM trap "rm -f $logdir/next;exit" INT HUP TERM
while true; do while true; do
sleep 4 sleep 4
pos=$(echo '{ "command": ["get_property", "time-remaining"]}' | socat - /tmp/mpvsocket | sed -nE 's_.*data":([^\.]*).*_\1_p') pos=$(echo '{ "command": ["get_property", "time-remaining"]}' | socat - /tmp/mpvsocket | sed -nE 's_.*data":([^\.]*).*_\1_p')
while [ -n "$pos" ]; do while [ -n "$pos" ]; do
pos=$(echo '{ "command": ["get_property", "time-remaining"]}' | socat - /tmp/mpvsocket | sed -nE 's_.*data":([^\.]*).*_\1_p') pos=$(echo '{ "command": ["get_property", "time-remaining"]}' | socat - /tmp/mpvsocket | sed -nE 's_.*data":([^\.]*).*_\1_p')
[ -z "$1" ] || printf "\033[2K\rnext music in $pos second(s)%s" "$(echo '{ "command": ["get_property", "pause"]}' | socat - /tmp/mpvsocket | sed -nE 's_.*data":([^,]*).*_\1_p' | sh && printf " (paused)")" [ -z "$1" ] || printf "\033[2K\rnext music in $pos second(s)%s" "$(echo '{ "command": ["get_property", "pause"]}' | socat - /tmp/mpvsocket | sed -nE 's_.*data":([^,]*).*_\1_p' | sh && printf " (paused)")"
[ -z "$pos" ] && printf "\033[2K\r\n" [ -z "$pos" ] && printf "\033[2K\r\n"
sleep 2 sleep 2
done done
pos=$(echo '{ "command": ["get_property", "time-remaining"]}' | socat - /tmp/mpvsocket | sed -nE 's_.*data":([^\.]*).*_\1_p') pos=$(echo '{ "command": ["get_property", "time-remaining"]}' | socat - /tmp/mpvsocket | sed -nE 's_.*data":([^\.]*).*_\1_p')
pgrep -f "mpvsocket" >/dev/null || exit 0 pgrep -f "mpvsocket" >/dev/null || exit 0
[ -z "$pos" ] && pgrep -f "mpvsocket" >/dev/null && [ -n "$(cat "$logdir/next")" ] && play "$(shuf -n1 "$logdir/next")" "$1" [ -z "$pos" ] && pgrep -f "mpvsocket" >/dev/null && [ -n "$(cat "$logdir/next")" ] && play "$(shuf -n1 "$logdir/next")" "$1"
done done
} }
play() { play() {
#this function does all the heavy lifting of extracting url from given videoId #this function does all the heavy lifting of extracting url from given videoId
#it's also callable, u can use this function to play ur custom youtube URLs #it's also callable, u can use this function to play ur custom youtube URLs
#call it by script-name "play" "valid_youtube_id_or_url" #call it by script-name "play" "valid_youtube_id_or_url"
title=$(printf "%s" "$1" | cut -f1) title=$(printf "%s" "$1" | cut -f1)
id=$(printf "%s" "$1" | cut -f2 | cut -d"=" -f2 | cut -d"/" -f4 | cut -d'&' -f1) id=$(printf "%s" "$1" | cut -f2 | cut -d"=" -f2 | cut -d"/" -f4 | cut -d'&' -f1)
[ -z "$id" ] && printf "[ youtube ] Invalid link\n" && exit 1 [ -z "$id" ] && printf "[ youtube ] Invalid link\n" && exit 1
#get song's audio url #get song's audio url
random_no=$(head /dev/urandom | tr -dc '0-2' | cut -c1) random_no=$(head /dev/urandom | tr -dc '0-2' | cut -c1)
droid_agent="com.google.android.youtube/18.10.36 (Linux; U; Android 1$random_no) gzip" droid_agent="com.google.android.youtube/18.10.36 (Linux; U; Android 1$random_no) gzip"
json="{ json="{
\"context\": { \"context\": {
\"client\": { \"client\": {
\"clientName\": \"ANDROID\", \"clientName\": \"ANDROID\",
@@ -113,57 +113,57 @@ play() {
\"racyCheckOk\": true \"racyCheckOk\": true
}" }"
audio_url=$(curl -X POST -A "$droid_agent" -s "https://www.youtube.com/youtubei/v1/player?key=AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w&prettyPrint=false" -H "content-type:application/json" -d "$json" -b "$cookie" | sed -nE 's_.*itag":251,"url":"([^"]*)".*_\1_p') audio_url=$(curl -X POST -A "$droid_agent" -s "https://www.youtube.com/youtubei/v1/player?key=AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w&prettyPrint=false" -H "content-type:application/json" -d "$json" -b "$cookie" | sed -nE 's_.*itag":251,"url":"([^"]*)".*_\1_p')
if [ -n "$2" ]; then if [ -n "$2" ]; then
printf "Name >> %s\n" "$title" printf "Name >> %s\n" "$title"
printf "videoID >> %s\n" "$id" printf "videoID >> %s\n" "$id"
printf "Audio URL >> %s\n" "$audio_url" printf "Audio URL >> %s\n" "$audio_url"
fi fi
curl -s "https://i.ytimg.com/vi/$id/hqdefault.jpg" -o - | convert - -crop 270x270+105+45 "$logdir/default.jpg" && notify-send -r 5 -i "$logdir/default.jpg" "Now Playing" "$title" -t 5000 curl -s "https://i.ytimg.com/vi/$id/hqdefault.jpg" -o - | convert - -crop 270x270+105+45 "$logdir/default.jpg" && notify-send -r 5 -i "$logdir/default.jpg" "Now Playing" "$title" -t 5000
pgrep -f "mpvsocket" >/dev/null || (setsid -f mpv --really-quiet --input-ipc-server=/tmp/mpvsocket --idle --quiet >/dev/null && sleep 1) pgrep -f "mpvsocket" >/dev/null || (setsid -f mpv --really-quiet --input-ipc-server=/tmp/mpvsocket --idle --quiet >/dev/null && sleep 1)
echo "{ \"command\": [\"loadfile\", \"$audio_url\", \"replace\"] }" | socat - /tmp/mpvsocket echo "{ \"command\": [\"loadfile\", \"$audio_url\", \"replace\"] }" | socat - /tmp/mpvsocket
cut -d':' -f2 "$logdir/current" >"$logdir/prev" cut -d':' -f2 "$logdir/current" >"$logdir/prev"
prev_id=$(cut -d'>' -f2 "$logdir/prev") prev_id=$(cut -d'>' -f2 "$logdir/prev")
printf "currently playing : %s >%s\n" "$title" "$id" >"$logdir/current" printf "currently playing : %s >%s\n" "$title" "$id" >"$logdir/current"
#next songs data #next songs data
json_next="{ json_next="{
\"enablePersistentPlaylistPanel\": true, \"enablePersistentPlaylistPanel\": true,
\"tunerSettingValue\": \"AUTOMIX_SETTING_NORMAL\", \"tunerSettingValue\": \"AUTOMIX_SETTING_NORMAL\",
\"playlistId\": \"RDAMVM$id\", \"playlistId\": \"RDAMVM$id\",
\"isAudioOnly\": true, \"isAudioOnly\": true,
\"context\": $(cat "$logdir/context") \"context\": $(cat "$logdir/context")
}" }"
get_data "next" "$json_next" | sed 's/playlistPanelVideoRenderer/\n/g' | sed -nE 's_.*text":"(.*)"}.*longBylineText":\{"runs":\[\{"text":"([^"]*)","navigationEndpoint.*videoId":"([^"]*)".*_\1 - \2\t\3_p' | sed "/$id/d;/$prev_id/d" >"$next_data" & get_data "next" "$json_next" | sed 's/playlistPanelVideoRenderer/\n/g' | sed -nE 's_.*text":"(.*)"}.*longBylineText":\{"runs":\[\{"text":"([^"]*)","navigationEndpoint.*videoId":"([^"]*)".*_\1 - \2\t\3_p' | sed "/$id/d;/$prev_id/d" >"$next_data" &
pgrep -f "yt-music loop" || setsid -f $HOME/repos_scripts/yt-music loop pgrep -f "yt-music loop" || setsid -f $HOME/repos_scripts/yt-music loop
} }
search_play() { search_play() {
#run this if u r starting the script first time like this #run this if u r starting the script first time like this
#call this by "script-name" "search_play" "search_query" #call this by "script-name" "search_play" "search_query"
[ -z "$1" ] && query=$(: | menu "Yt-music [Search]:") || query="$1" [ -z "$1" ] && query=$(: | menu "Yt-music [Search]:") || query="$1"
[ -z "$query" ] && notify-send "Err.. Search query empty" -u critical -r 5 && exit 1 [ -z "$query" ] && notify-send "Err.. Search query empty" -u critical -r 5 && exit 1
curl -A "$agent" -s "$base_url/" -c "$cookie" | sed -nE 's|.*INNERTUBE_CONTEXT":(.*),"INNERTUBE_CONTEXT_CLIENT_NAME.*|\1|p' >"$logdir/context" curl -A "$agent" -s "$base_url/" -c "$cookie" | sed -nE 's|.*INNERTUBE_CONTEXT":(.*),"INNERTUBE_CONTEXT_CLIENT_NAME.*|\1|p' >"$logdir/context"
json_search="{ json_search="{
\"context\" : $(cat "$logdir/context"), \"context\" : $(cat "$logdir/context"),
\"query\": \"$query\", \"query\": \"$query\",
\"params\": \"EgWKAQIIAWoKEAMQBBAJEAoQBQ%3D%3D\" \"params\": \"EgWKAQIIAWoKEAMQBBAJEAoQBQ%3D%3D\"
}" }"
res=$(get_data "search" "$json_search" "search?q=$(printf "%s" "$1" | tr ' ' '+')" | sed 's/watchEndpoint"/\n/g' | sed -nE 's_.*videoId":"([^"]*)",.*label":"Play ([^"]*)".*_\2\t\1_p' | menu "Yt-music [Play]:") res=$(get_data "search" "$json_search" "search?q=$(printf "%s" "$1" | tr ' ' '+')" | sed 's/watchEndpoint"/\n/g' | sed -nE 's_.*videoId":"([^"]*)",.*label":"Play ([^"]*)".*_\2\t\1_p' | menu "Yt-music [Play]:")
[ -z "$res" ] || play "$res" "verbose" [ -z "$res" ] || play "$res" "verbose"
} }
play_next() { play_next() {
#call this by script-name "play_next" for playing next song immediately #call this by script-name "play_next" for playing next song immediately
#or add "menu" after "play_next" to show menu for selecting and playing next song immediately #or add "menu" after "play_next" to show menu for selecting and playing next song immediately
#like this script-name "play_next" "menu" #like this script-name "play_next" "menu"
[ -z "$1" ] && play "$(shuf -n1 "$logdir/next")" "verbose" || (pgrep -f "mpvsocket" && notify-send -r 5 -i "$logdir/default.jpg" "$(cut -d">" -f1 "$logdir/current" | tr ':' '\n')" && play "$(menu "YT-music [play-next]: " <"$logdir/next")" "verbose") [ -z "$1" ] && play "$(shuf -n1 "$logdir/next")" "verbose" || (pgrep -f "mpvsocket" && notify-send -r 5 -i "$logdir/default.jpg" "$(cut -d">" -f1 "$logdir/current" | tr ':' '\n')" && play "$(menu "YT-music [play-next]: " <"$logdir/next")" "verbose")
} }
menu() { menu() {
bemenu --fn 'IBM Plex Sans 15' -i -c -W 0.5 -B 3 -p "$1" -l 26 bemenu --fn 'IBM Plex Sans 15' -i -c -W 0.5 -B 3 -p "$1" -l 26
} }
logdir="/tmp/yt-music" logdir="/tmp/yt-music"