From 48b2c30cad6de928d20405922d883ff2c306dd90 Mon Sep 17 00:00:00 2001 From: coolnsx Date: Sun, 15 Jan 2023 19:45:28 +0530 Subject: [PATCH] betterer code --- ani-new | 18 ++++++++++-------- bkmark | 4 ++-- tor-cli | 3 ++- yt-music | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ani-new b/ani-new index c3b8117..f3c152e 100755 --- a/ani-new +++ b/ani-new @@ -2,8 +2,8 @@ down () { notify-send "$3 links fetched.." -r "$tmp" - choice=$(printf "download\nwatch\nnext mirror" | bemenu --fn 'Roboto 15' -p "??" -i -c -W 0.4 -B 3 -l 10) - [ "$choice" = "watch" ] && setsid -f mpv --referrer="$1" "$2" --force-media-title="$title" && notify-send -i "$icon_dir/apps/mpv.svg" "opening $title" -r "$tmp" && exit 0 + choice=$(printf "stream\ndownload\nnext mirror" | bemenu --fn 'Roboto 15' -p "??" -i -c -W 0.4 -B 3 -l 10) + [ "$choice" = "stream" ] && setsid -f mpv --referrer="$1" "$2" --force-media-title="$title" && notify-send -i "$icon_dir/apps/mpv.svg" "opening $title" -r "$tmp" && exit 0 [ "$choice" = "next mirror" ] && return 0 notify-send -i "$icon_dir/panel/jdownloader-indicator.svg" "Downloading $title" -r "$tmp" case $2 in @@ -22,8 +22,9 @@ provider_run(){ provider_id=$(printf "%s" "$data" | sed -n "$2" | head -1 | cut -d':' -f2) [ -z "$provider_id" ] && return 0 provider_video=$(curl -s "https://blog.allanime.pro/apivtwo/clock.json?id=$provider_id" | sed 's|},{|\n|g' | sed -nE 's|.*link":"([^"]*)".*"resolutionStr":"([^"]*)".*|\1|p' | head -1) + [ -z "$provider_video" ] && return 0 case $provider_video in - *v.vrv.co*|*crunchyroll*) down "$base_url" "$(curl -s "$provider_video" -A "$agent" | sed 's|^#.*x||g; s|,.*|p|g; /^#/d; $!N; s|\n| >|; s|\/index-v1-a1\.m3u8||g' | grep -q "1080" | cut -d'>' -f2)" "$1" ;; + *v.vrv.co*|*crunchyroll*) down "$base_url" "$(curl -s "$provider_video" -A "$agent" | sed -n '/x1080/{n;p;}')" "$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" ;; *) down "$base_url" "$provider_video" "$1" ;; esac @@ -31,14 +32,15 @@ provider_run(){ icon_dir="/usr/share/icons/Papirus/16x16" base_url="https://allanime.site" -agent="uwu" +agent="Mozilla/5.0" trap "exit 0" INT HUP tmp=$(notify-send "Parsing $base_url.. Please wait..." -t 1500 -p) -[ -z "$*" ] && url=$(curl -s "$base_url/anime" -A uwu | sed -nE 's|.*href="(/watch/[^"]*)" class.*|\1|p' | bemenu --fn 'Roboto 15' -i -c -W 0.6 -B 3 -l 20 -p "Select Anime: ") || url=$* -title=$(printf "%s" "$url" | cut -d'/' -f4- | tr '[:punct:]' ' ') +[ -z "$*" ] && url=$(curl -s "$base_url/allanimeapi?variables=%7B%22search%22%3A%7B%22sortBy%22%3A%22Recent%22%2C%22allowAdult%22%3Afalse%2C%22allowUnknown%22%3Afalse%7D%2C%22limit%22%3A40%2C%22page%22%3A1%2C%22translationType%22%3A%22sub%22%2C%22countryOrigin%22%3A%22JP%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%229c7a8bc1e095a34f2972699e8105f7aaf9082c6e1ccd56eab99c2f1a971152c6%22%7D%7D" -A "$agent" | sed 's|Show|\n|g' | sed -nE 's|.*_id":"([^"]*)","name":"([^"]*)".*sub":\{"episodeString":"([^"]*)".*|\1\t\2\tepisode \3 sub|p' | bemenu --fn 'Roboto 15' -i -c -W 0.6 -B 3 -l 20 -p "Select Anime: " | tr '[:punct:]' ' ' | tr -s ' ' | tr ' \t' '-/') || url=$* +title=$(printf "%s" "$url" | cut -d'/' -f2- | tr '[:punct:]' ' ') +url=$(printf "%s" "$url" | cut -d'/' -f1,3) [ -z "$url" ] && notify-send -u "critical" "No anime selected" -r "$tmp" && exit 0 notify-send "Loading Episode $title.." -r "$tmp" -data=$(curl -A "$agent" -s "${base_url}$url" | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":".*?id=([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p') +data=$(curl -A "$agent" -s "${base_url}/watch/$url" | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":".*?id=([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p') notify-send "Fetching Embed links" -r "$tmp" #pstatic links @@ -62,7 +64,7 @@ resp="$(curl -A "$agent" -s "https://gogohd.pro/streaming.php?id=$id" | sed -nE notify-send "Fetching mp4upload links" -r "$tmp" mp4up_link=$(printf "%s" "$resp" | grep "mp4upload") -[ -z "$mp4up_link" ] || mp4up_video=$(curl -A "$agent" -s "$mp4up_link" -H "DNT: 1" --connect-timeout=10 | sed -nE 's_.*embed\|(.*)\|.*blank.*\|(.*)\|(.*)\|(.*)\|(.*)\|src.*_https://\1.mp4upload.com:\5/d/\4/\3.\2_p') +[ -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" notify-send "Fetching xstreamcdn links" -r "$tmp" diff --git a/bkmark b/bkmark index 8643efd..923328a 100755 --- a/bkmark +++ b/bkmark @@ -16,12 +16,12 @@ if [ "$*" = "add" ];then notify-send "Bookmarked" "$data" fi elif [ "$*" = "rm" ];then - data="$(cat "$file" | sed '/^$/d' | nl -n'ln')" + data="$(sed '/^$/d' "$file" | nl -n'ln')" [ -z "$data" ] && notify-send "Bookmark is empty" && exit 0 del=$(printf "%s" "$data" | bemenu --fn 'Roboto 15' -i -c -W 0.6 -B 3 -l 30 -p "delete-bookmark :" | cut -f1) [ -z "$del" ] || (sed -i "${del}d" "$file" && notify-send "Bookmarked deleted") else - wtype -d 5 "$(cat "$file" | sed '/^$/d' | bemenu --fn 'Roboto 15' -i -c -W 0.6 -B 3 -l 30 -p "Put-bookmark :" | tr '\`' '\n')" + wtype -d 5 "$(sed '/^$/d' "$file" | bemenu --fn 'Roboto 15' -i -c -W 0.6 -B 3 -l 30 -p "Put-bookmark :" | tr '\`' '\n')" fi sed -i '/^$/d' "$file" diff --git a/tor-cli b/tor-cli index 0fd46af..881d685 100755 --- a/tor-cli +++ b/tor-cli @@ -2,5 +2,6 @@ [ -z "$*" ] && query=$(printf "" | bemenu --fn 'Roboto 15' -i -c -W 0.6 -B 3 -p "Search torrent: ") || query=$* [ -z "$query" ] && exit 0 -magnet=$(curl -s "https://thepiratebay0.org/search/$query" | tr '\n' ' ' | sed -e 's__\n_g;s_ \;__g' | sed -nE 's_.*title.*">([^<]*).*a href="(magnet[^"]*)".*Size ([^,]*).*">([^<]*)<.*<.*_\[size:\3,se:\4\]\t\1\t\2_p' | fzf -d'\t' --with-nth ..2 | cut -f3) +query=$(printf "%s" "$query" | tr ' ' '+') +magnet=$(curl -s "https://thepiratebay0.org/s/?page=0&orderby=0&q=$query" | tr '\n' ' ' | sed -e 's__\n_g;s_ \;__g' | sed -nE 's_.*title.*">([^<]*).*a href="(magnet[^"]*)".*Size ([^,]*).*">([^<]*)<.*<.*_\[size:\3,se:\4\]\t\1\t\2_p' | fzf -d'\t' --with-nth ..2 | cut -f3) [ -z "$magnet" ] || setsid -f $TERMINAL -e $HOME/repos_scripts/torrent "$magnet" diff --git a/yt-music b/yt-music index ec67bcf..8f10532 100755 --- a/yt-music +++ b/yt-music @@ -164,7 +164,7 @@ menu(){ bemenu --fn 'Roboto 15' -i -c -W 0.5 -B 3 -p "$1" -l 26 } -logdir="${XDG_CACHE_HOME:-$HOME/.cache/yt-music}" +logdir="/tmp/yt-music" base_url="https://music.youtube.com" [ -d "$logdir" ] || mkdir "$logdir" cookie="$logdir/cookies"