From 33fad01b6603859e1bc3b7216533b6aa2a182bce Mon Sep 17 00:00:00 2001 From: coolnsx Date: Thu, 10 Aug 2023 12:30:42 +0530 Subject: [PATCH] need another beer --- .functions | 5 ++-- ani-new | 2 +- readme.md | 2 +- rss | 2 +- screen | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tor-bay | 2 +- tor-cli | 2 +- torrent | 2 +- youtube | 21 ++++++++++---- yt-music | 21 +++++++------- 10 files changed, 116 insertions(+), 23 deletions(-) create mode 100755 screen diff --git a/.functions b/.functions index 29ddf52..277e45f 100644 --- a/.functions +++ b/.functions @@ -5,7 +5,8 @@ menu_droid() { } menu_linux() { - bemenu --fn 'Cascadia Mono 15' -i -c -W 0.6 -B 3 -l 25 -p "$1" + [ -z "$3" ] && width="0.6" || width="$3" + bemenu --fn 'Cascadia Mono 15' -i -c -W "$width" -B 3 -l 25 -p "$1" } search_droid() { @@ -29,7 +30,7 @@ info_droid() { } info_linux() { - notify-send "$1" -r '10' -i "$2" + notify-send "$1" -r '10' -i "$2" $3 } error_droid() { diff --git a/ani-new b/ani-new index 786ef34..8f0b8d7 100755 --- a/ani-new +++ b/ani-new @@ -50,7 +50,7 @@ case $(uname -o) in *ndroid*) os="droid" download_dir="/sdcard" - script_dir="$HOME" + script_dir="" ;; *) os="linux" diff --git a/readme.md b/readme.md index 552dbd8..bcfb91e 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,7 @@ [bkmark.webm](https://user-images.githubusercontent.com/76195824/207424619-dd64a520-877d-4d3e-a1ad-f3b400be68eb.webm) -## setwall +## setwall (removed as It works on system-level) (coming soon for hyprland) - Caution: don't blindly run this script as it edits the file on system level, read the actual code before proceeding - this only works for St and bspwm (hyprland with foot coming soon) diff --git a/rss b/rss index b2d1034..096638b 100755 --- a/rss +++ b/rss @@ -2,7 +2,7 @@ if [ "$(uname -o)" = "Android" ]; then os="droid" - script_dir="$HOME" + script_dir="" else os="linux" script_dir="$HOME/repos_scripts" diff --git a/screen b/screen new file mode 100755 index 0000000..099ea87 --- /dev/null +++ b/screen @@ -0,0 +1,80 @@ +#!/bin/sh + +# script for screeen recording with either mic or speaker +# ability to record both mic and speaker at same time is coming soon + +info() { + notify-send -h "string:x-canonical-private-synchronous:${0##*/}" -i "$1" -t "${2:-5000}" "$3" "$4" +} + +menu() { + bemenu --fn 'IBM Plex Sans 15' -i -c -W "0.${2:-5}" -B 3 -p "$1" -l 26 +} + +record (){ + rm -f "$tmp_file" "$process_file" + source=$(printf "screen only\nspeaker\nmic" | menu "Audio Source:" "3") + monitor=$(hyprctl monitors | sed -nE 's|Monitor ([^ ]*).*|\1|p') + [ "$(printf '%s\n' "$monitor" | wc -l)" -gt 1 ] && monitor=$(printf '%s' "$monitor" | menu "Choose Monitor:" "3") + [ -z "$source" ] && info "" "2000" "No option Selected" && return 0 + info "simplescreenrecorder" "700" "Recording Started" "Capturing $monitor($source)" + sleep 0.3 + [ "$source" = "screen only" ] && setsid -f wf-recorder -t -m "mp4" -f "$tmp_file" >/dev/null 2>&1 && return 0 + pactl set-default-source "$(eval "printf \$$source")" + setsid -f wf-recorder -a -t -m "mp4" -f "$tmp_file" --output "$monitor" >/dev/null 2>&1 +} + +compress() { + duration=$(ffprobe -hide_banner -i "$tmp_file" 2>&1 | sed -nE 's|.*Duration: ([^,]*).*|\1|p') + i=19 + + while :;do + ffmpeg -loglevel error -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -i "$tmp_file" -vf 'format=nv12,hwupload' -c:v h264_vaapi -qp "$i" "$process_file" -y -progress - | while read -r line; + do + complete=$(printf "%s\n" "$line" | sed -nE 's|out_time=(.*)|\1|p') + [ -n "$complete" ] && info "ffmpeg" "700" "Compressing File under 25 MB Using Quality Preset : $i.." "$complete out of $duration ($(du -m "$process_file" | cut -f1) MB)" + [ "$(du -m "$process_file" | cut -f1)" -gt 25 ] && killall -s KILL ffmpeg && break + done + [ "$(du -m "$process_file" | cut -f1)" -lt 25 ] && break + : $((i+=1)) + done + info "ffmpeg" "1000" "File Successfully compressed with Quality Preset : $i" + [ -f "$process_file" ] && tmp_file=$process_file +} + +stop (){ + pgrep -af wf-recorder >/dev/null && killall -s SIGINT wf-recorder 2>/dev/null || return 0 + info "" "" "Recording Stopped" + case $(printf "save locally\nupload to oshi\nupload to discord" | menu "Post-Record:" '3') in + *oshi) + info "icloud" "" "Uploading to Oshi" + out=$(curl -sk https://oshi.at -F shorturl=0 -F "f=@$tmp_file") + [ -z "$out" ] && info "" "2000" "Unable to upload to oshi,moved the file from temp to your home folder as .mp4" && mv "$tmp_file" "$HOME/$(date +%s).mp4" && return 1 + printf "%s" "$out" | sed -nE 's|DL: (.*)|\1|p' | wl-copy && info "com.github.davidmhewitt.clipped" "2000" "Uploaded and Copied link to clipboard" + ;; + *discord) + [ "$(du -m "$tmp_file" | cut -f1)" -gt 25 ] && compress #compressing file if greater than 25 MB + #will push discord code in next commit + ;; + save*) + filename=$(: | menu "Enter Filename (default: screenrecord.mp4):") + mv "$tmp_file" "$HOME/$filename" + ;; + *) + rm -f "$tmp_file" "$process_file" && info "user-trash" "2000" "Temporary File Deleted" + ;; + esac + +} + +tmp_file="/tmp/screenrecord.mp4" +process_file="/tmp/processed.mp4" +#shellcheck disable=SC2034 +mic="alsa_input.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_6__source" #It is called in eval on line 9 +#shellcheck disable=SC2034 +speaker="alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink.monitor" #It is called in eval on line 9 + +# shellcheck source=./.functions +. "$script_dir/.functions" + +$1 "$2" diff --git a/tor-bay b/tor-bay index d7fae03..0cee3cb 100755 --- a/tor-bay +++ b/tor-bay @@ -15,7 +15,7 @@ display() { case $(uname -o) in *ndroid*) os="droid" - script_dir="$HOME" + script_dir="" ;; *) os="linux" diff --git a/tor-cli b/tor-cli index 973ec72..79cb2ce 100755 --- a/tor-cli +++ b/tor-cli @@ -3,7 +3,7 @@ case $(uname -o) in *ndroid*) os="droid" - script_dir="$HOME" + script_dir="" ;; *) os="linux" diff --git a/torrent b/torrent index eae5679..171d2f9 100755 --- a/torrent +++ b/torrent @@ -14,7 +14,7 @@ down() { if [ "$(uname -o)" = "Android" ]; then os="droid" - script_dir="$HOME" + script_dir="" else os="linux" script_dir="$HOME/repos_scripts" diff --git a/youtube b/youtube index b9e337a..a90f119 100755 --- a/youtube +++ b/youtube @@ -14,20 +14,31 @@ part() { read start printf "${c_yellow}Enter Upto Seconds:${c_cyan}" 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" "$download_dir/$(date +%s).$2" } +case $(uname -o) in + *ndroid*) + download_dir="/sdcard" + x=$(termux-clipboard-get) + ;; + *) + download_dir="$HOME" + x=$(wl-paste) + ;; +esac + #program starts from here.. -x=$(termux-clipboard-get) -[ "$1" = "v" ] && yt-dlp "$x" -o "/sdcard/%(title)s.%(ext)s" && termux-notification -c "video downloaded" && exit 0 +[ -n "$1" ] && x=$1 +[ "$1" = "v" ] && yt-dlp "$x" -o "$download_dir/%(title)s.%(ext)s" && termux-notification -c "video downloaded" && exit 0 printf "\n${c_blue} video link :${c_magenta}$x\n" printf "${c_yellow}Download>>\n${c_blue}[a]Audio only\n${c_magenta}[f]part of Audio only\n${c_green}[v]Full video\n${c_cyan}[p]Part of video\n${c_red}[q]Quit" printf "\n${c_reset}Enter choice:${c_green}" read choice 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 "$download_dir/%(title)s.%(ext)s" && 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 "$download_dir/%(title)s.%(ext)s" && termux-notification -c "video downloaded" ;; p) part "$x" "mp4" "b" && termux-notification -c "video downloaded" ;; q) exit 0 ;; esac diff --git a/yt-music b/yt-music index b90c0b7..86e1712 100755 --- a/yt-music +++ b/yt-music @@ -55,7 +55,7 @@ help() { } 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" -d "$2" -b "$cookie" -e "$base_url/$3" -c "$cookie" } loop() { @@ -88,13 +88,14 @@ play() { [ -z "$id" ] && printf "[ youtube ] Invalid link\n" && exit 1 #get song's audio url - 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" + random_no=$(head /dev/urandom | tr -dc '1-2' | cut -c1) + andy_yt_ver="6.13.52" + droid_agent="com.google.android.apps.youtube.music/$andy_yt_ver (Linux; U; Android 1$random_no) gzip" json="{ \"context\": { \"client\": { - \"clientName\": \"ANDROID\", - \"clientVersion\": \"18.10.36\", + \"clientName\": \"ANDROID_MUSIC\", + \"clientVersion\": \"$andy_yt_ver\", \"androidSdkVersion\": $((random_no + 29)), \"userAgent\": \"$droid_agent\", \"hl\": \"en\", @@ -103,7 +104,6 @@ play() { } }, \"videoId\": \"$id\", - \"params\": \"8AEB\", \"playbackContext\": { \"contentPlaybackContext\": { \"html5Preference\": \"HTML5_PREF_WANTS\" @@ -113,7 +113,8 @@ play() { \"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=AIzaSyAOghZGza2MQSZkY_zfZ370N-PUdXEo8AI&prettyPrint=false" -H "content-type:application/json" -d "$json" -H "x-youtube-client-version:$andy_yt_ver" -H "x-youtube-client-name:21" | sed -nE 's_.*itag":251,"url":"([^"]*)".*_\1_p') + [ -z "$audio_url" ] && return 0 if [ -n "$2" ]; then printf "Name >> %s\n" "$title" printf "videoID >> %s\n" "$id" @@ -136,7 +137,7 @@ play() { \"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" & - pgrep -f "yt-music loop" || setsid -f $HOME/repos_scripts/yt-music loop + pgrep -f "yt-music loop" >/dev/null || setsid -f "$HOME"/repos_scripts/yt-music loop } search_play() { @@ -144,8 +145,8 @@ search_play() { #call this by "script-name" "search_play" "search_query" [ -z "$1" ] && query=$(: | menu "Yt-music [Search]:") || query="$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" + printf '{"client":{"clientName":"WEB_REMIX","clientVersion":"1.20230731.00.00"}}' >"$logdir/context" json_search="{ \"context\" : $(cat "$logdir/context"), \"query\": \"$query\", @@ -171,7 +172,7 @@ base_url="https://music.youtube.com" [ -d "$logdir" ] || mkdir "$logdir" cookie="$logdir/cookies" next_data="$logdir/next" -agent="Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/110.0" +agent="Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0" #call this script by script-name "function_name" "query" [ -z "$1" ] && help "$@"