From 9b4dbdd92b657d8e8fa2a4815de488f8fe5db881 Mon Sep 17 00:00:00 2001 From: coolnsx Date: Thu, 18 Jan 2024 21:33:08 +0530 Subject: [PATCH] first blush --- download | 46 +++++++++++++++++++++++++++++++++++++++++++++- torrent | 22 +++++++++++++--------- 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/download b/download index 9fe6431..1134b78 100755 --- a/download +++ b/download @@ -18,6 +18,50 @@ notify_linux() { notify-send "$1" -h "string:x-canonical-private-synchronous:${0##*/}" } +conv_to_octal(){ + base=$2 + i=0 + res=0 + for key in $(printf "%s" "$1" | rev | sed 's/./&\n/g'); do + if [ "$key" -ne 0 ];then + j=$i + tmp=1 + while [ "$j" -ne 0 ];do + : $((tmp *= base)) + : $((j-=1)) + done + res=$((res + (key * tmp))) + fi + : $((i+=1)) + done + + res=$(printf '%03o' "$((res-${3}))") + printf "\\$res" | sed 's/[\/&]/\\&/g' +} + +instagram() { + info "Using Alternate Site" "Instagram" "$2" + sed_file="${TMPDIR:-/tmp}/${0##*/}-sed-file" + response=$(curl -s "https://snapinsta.app" -o /dev/null -c - | curl -s 'https://snapinsta.app/action2.php' -e 'https://snapinsta.app/' -A 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' -b - -F "url=$1" -F 'action=post' -F 'lang=' --compressed | sed -nE 's|.*\}\(([^\)]*)\).*|\1|p' | tr -d '"' | tr ',' '\n') + + n=$(printf "%s" "$response" | sed -n '3p') + t=$(printf "%s" "$response" | sed -n '4p') + e=$(printf "%s" "$response" | sed -n '5p') + printf '%s' "$n" | cut -c-"$e" | sed 's/./&\n/g' | tr -s '\n' | nl -nln -v0 | sed -nE 's|^([0-9]*)[[:space:]]*(.*)|s\/\2\/\1\/g|p' > "$sed_file" + printf 's/%s/\\n/g' "$(printf "%s" "$n" | cut -c"$((e+1))")" >> "$sed_file" + + data=$(printf "%s" "$response" | head -1 | sed -f "$sed_file" | sed -n '1200,2500p') + + info "Decoding JS" "Instagram" "$2" + printf "" > "$sed_file" + for num in $(printf "%s" "$data" | sort -u); do + printf 's/^%s$/%s/g\n' "$num" "$(conv_to_octal "$num" "$e" "$t")" >> "$sed_file" & + done + wait + + video_url=$(printf "%s" "$data" | sed -f "$sed_file" -e 's/\\//g' | tr -d '\n' | sed -nE 's|.*a href="([^"]*)".*|\1|p') +} + #main link="$1" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" @@ -52,7 +96,7 @@ case "$link" in info "Fetching Video URL" "$app" "$id" video_url=$(curl -s "https://i.instagram.com/api/v1/web/get_ruling_for_content/?content_type=MEDIA&target_id=$res" -H "x-ig-app-id:936619743392459" -H "x-ig-www-claim:0" -A "$agent" -c - -o /dev/null | curl -A "$agent" -s -G "https://www.instagram.com/graphql/query/" -H "content-type:application/json" --data-urlencode 'query_hash=9f8827793ef34641b2fb195d4d41151c' --data-urlencode 'variables={"shortcode":"'"$id"'","include_reel":false,"include_logged_out":false}' -e "$link" -b - | tr '{}' '\n' | sed -nE 's|.*video_url":"([^"]*)".*|\1|p' | sed 's/\u0026/\&/g;s/\\//g') - printf "%s" "$video_url" | grep -qE 'instagram.*mp4' || fallback=1 + printf "%s" "$video_url" | grep -qE 'instagram.*mp4' || instagram "$link" "$id" ;; *youtu*) app="Youtube" diff --git a/torrent b/torrent index 17d6b50..c342040 100755 --- a/torrent +++ b/torrent @@ -1,5 +1,7 @@ #!/bin/sh +#shellcheck disable=SC2059 + c_red="\033[1;31m" c_green="\033[1;32m" c_yellow="\033[1;33m" @@ -9,7 +11,8 @@ c_reset="\033[0m" down() { tput reset info_$os "Torrent: Downloading" - aria2c --file-allocation=trunc -d Softwares --select-file=$2 --seed-time=0 $1 && info_$os "Torrent: Download complete" && rm -f $file || error_$os "Torrent: Error!!" + aria2c --file-allocation=trunc -d "$download_dir" --select-file="$2" --seed-time=0 "$1" && info_$os "Torrent: Download complete" && return 0 + error_$os "Torrent: Error!!" } magnet="$*" @@ -21,16 +24,16 @@ if [ "$(uname -o)" = "Android" ]; then else os="linux" script_dir="$HOME/repos_scripts" - download_dir="Downloads" + download_dir="$HOME/Softwares" [ -z "$magnet" ] && magnet="$(wl-paste)" fi #import generic functions -. $script_dir/.functions +# shellcheck source=./.functions +. "$script_dir/.functions" #check if the url is magnet ! printf "%s" "$magnet" | grep -qE "magnet:\?xt=urn:btih:|torrent" && error_$os "Not a valid magnet link!" && exit 0 -trap "rm -f $HOME/.cache/*.torrent;exit 0" INT HUP 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_reset}\n\tenter choice:" @@ -40,13 +43,14 @@ case $ch in down "$magnet" ;; p) - aria2c --dir=$HOME/.cache --bt-metadata-only=true --bt-save-metadata=true "$magnet" + file=$(printf "%s" "$magnet" | sed -nE 's|.*urn:btih:([^&]*).*|\1|p' | tr '[:upper:]' '[:lower:]') + aria2c --dir="$HOME/.cache" --bt-metadata-only=true --bt-save-metadata=true "$magnet" tput reset - aria2c --show-files=true $HOME/.cache/*.torrent - info_$os "Enter file idx(default=all):" + aria2c --show-files=true "$HOME/.cache/$file.torrent" + printf "${c_cyan}Enter file idx(default=all): " read -r ind - down "$HOME/.cache/*.torrent" "$ind" - rm -f $HOME/.cache/*.torrent + down "$HOME/.cache/$file.torrent" "$ind" + rm -f "$HOME/.cache/$file.torrent" ;; q) exit 0