Feat: No more Discord Rich presence in yt-music, bois

This commit is contained in:
coolnsx
2024-07-22 13:49:49 +05:30
parent f4ee1b8859
commit eb327b465c
5 changed files with 30 additions and 82 deletions

View File

@@ -7,7 +7,7 @@ menu_droid() {
} }
menu_linux() { menu_linux() {
bemenu --fn 'Cascadia Mono 15' -i -c -W "0.${3:-6}" -B 3 -l 25 -p "$1" --bdr="#$GLOBAL_ACCENT" --tf="#$GLOBAL_ACCENT" --hf="#$GLOBAL_ACCENT" bemenu --fn 'Cascadia Mono 15' -i -c -W "0.${3:-6}" -B 3 -l 25 -p "$1" --bdr="#$GLOBAL_ACCENT" --tf="#$GLOBAL_ACCENT" --hf="#$GLOBAL_ACCENT" -R 20
} }
search_droid() { search_droid() {

View File

@@ -65,7 +65,7 @@ instagram() {
#main #main
link="$1" link="$1"
agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/12$(head /dev/urandom | tr -dc '3-6' | cut -c1).0.0.0 Safari/537.36" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/12$(head /dev/urandom | tr -dc '4-7' | cut -c1).0.0.0 Safari/537.36"
case $(uname -o) in case $(uname -o) in
*ndroid*) *ndroid*)
@@ -98,13 +98,14 @@ case "$link" in
info "Fetching Video URL" "$app" "$id" 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') 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' || instagram "$link" "$id" printf "%s" "$video_url" | grep -qE 'instagram.*mp4' || instagram "$link" "$id"
[ -z "$video_url" ] && fallback=1
;; ;;
*youtu*) *youtu*)
app="Youtube" app="Youtube"
id=$(printf "%s" "$link" | cut -d"=" -f2 | cut -d"/" -f4) id=$(printf "%s" "$link" | cut -d"=" -f2 | cut -d"/" -f4)
[ -z "$id" ] && error "Unable to extract ID" "$app" "$id" [ -z "$id" ] && error "Unable to extract ID" "$app" "$id"
info "Fetching Video URL" "$app" "$id" info "Fetching Video URL" "$app" "$id"
yt_ver="2.20231219.04.00" yt_ver="2.20240624.06.00"
json="{ json="{
\"context\": { \"context\": {
\"client\": { \"client\": {

16
screen
View File

@@ -52,7 +52,7 @@ record() {
stop() { stop() {
pgrep -af wf-recorder >/dev/null && killall -s SIGINT wf-recorder 2>/dev/null || return 0 pgrep -af wf-recorder >/dev/null && killall -s SIGINT wf-recorder 2>/dev/null || return 0
info "" "" "Recording Stopped" info "" "" "Recording Stopped"
case $(printf "upload to discord\nupload to nextcloud\nupload to oshi\nsave locally" | menu "Post-Record:" '3') in case $(printf "upload to matrix\nupload to nextcloud\nupload to oshi\nsave locally" | menu "Post-Record:" '3') in
*oshi) *oshi)
info "icloud" "" "Uploading to Oshi" info "icloud" "" "Uploading to Oshi"
out=$(curl -sk https://oshi.at -F shorturl=0 -F "f=@$tmp_file") out=$(curl -sk https://oshi.at -F shorturl=0 -F "f=@$tmp_file")
@@ -78,19 +78,7 @@ stop() {
curl -u "$NC_USER:$NC_TOKEN" -s "$NC_URL/ocs/v2.php/apps/files_sharing/api/v1/shares" -H 'content-type: application/json' -H 'accept: application/json, text/plain, */*' -H 'OCS-APIRequest: true' --data-raw '{"path":"'"${NC_SHARE_PATH}/$cloudname"'","shareType":3,"expireDate":"'"$expire_date"'"}' | sed -nE 's|.*"url":"([^"]*)".*|\1|p' | sed 's/\\//g' | wl-copy && info "com.github.davidmhewitt.clipped" "2000" "Share Link Created and copied to clipboard" curl -u "$NC_USER:$NC_TOKEN" -s "$NC_URL/ocs/v2.php/apps/files_sharing/api/v1/shares" -H 'content-type: application/json' -H 'accept: application/json, text/plain, */*' -H 'OCS-APIRequest: true' --data-raw '{"path":"'"${NC_SHARE_PATH}/$cloudname"'","shareType":3,"expireDate":"'"$expire_date"'"}' | sed -nE 's|.*"url":"([^"]*)".*|\1|p' | sed 's/\\//g' | wl-copy && info "com.github.davidmhewitt.clipped" "2000" "Share Link Created and copied to clipboard"
;; ;;
*discord) *matrix)
#shellcheck disable=SC1091
. "$HOME"/.config/.env
channel=$(curl -s "$DISCORD_URL/guilds/$DISCORD_SERVER_ID/channels" -H "Authorization: $DISCORD_TOKEN" | tr '{}' '\n' | sed -nE 's|.*"id":"([^"]*)".*last_message_id.*"name":"([^"]*)".*|\1\t\2|p' | menu "Select Channel: ")
channel_name=$(printf "%s" "$channel" | cut -f2)
channel_id=$(printf "%s" "$channel" | cut -f1)
[ "$(du -m "$tmp_file" | cut -f1)" -gt 25 ] && compress #compressing file if greater than 25 MB
info "discord" "" "Uploading to Discord in $channel_name"
content="${tmp_file##*/} ($(du -h "$tmp_file" | cut -f1)) uploaded by coolans"
curl -s "$DISCORD_URL/channels/$channel_id/messages" -H "Authorization: $DISCORD_TOKEN" -H "Accept: application/json" -H "Content-Type: multipart/form-data" -X POST -F "file=@$tmp_file" -F 'payload_json={"content":"'"${content}"'"}' && info "" "2000" "Uploaded $tmp_file ($(du -h "$tmp_file" | cut -f1)) to $channel_name in Discord" && return 0
filename="screenrecord-$(date +"%F_%H-%M-%S").mp4"
mv "$tmp_file" "$HOME/$filename" && info "" "2000" "Unable to upload to Discord,file moved to your home folder as $filename"
;; ;;
save*) save*)

23
torrent
View File

@@ -32,8 +32,17 @@ fi
# shellcheck source=./.functions # shellcheck source=./.functions
. "$script_dir/.functions" . "$script_dir/.functions"
filepath="$HOME/.cache"
#check if the url is magnet #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 ! printf "%s" "$magnet" | grep -qE "magnet:\?xt=urn:btih:|\.torrent$" && error_$os "Not a valid magnet link!" && exit 0
# check if the variable is actuall magnet-link or file
if printf '%s' "$magnet" | grep -qE "\.torrent$";then
filepath="$(dirname "$magnet")"
file="$(basename "$magnet")"
is_file=1
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:"
@@ -43,14 +52,16 @@ case $ch in
down "$magnet" down "$magnet"
;; ;;
p) p)
file=$(printf "%s" "$magnet" | sed -nE 's|.*urn:btih:([^&]*).*|\1|p' | tr '[:upper:]' '[:lower:]') if [ -z "$is_file" ];then
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:]').torrent"
{ [ -f "$filepath/$file" ] && [ ! -f "$filepath/$file.aria2" ]; } || aria2c --dir="$filepath" --bt-metadata-only=true --bt-save-metadata=true "$magnet" -o "$file"
fi
tput reset tput reset
aria2c --show-files=true "$HOME/.cache/$file.torrent" aria2c --show-files=true "$filepath/$file"
printf "${c_cyan}Enter file idx(default=all): " printf "${c_cyan}Enter file idx(default=all): "
read -r ind read -r ind
down "$HOME/.cache/$file.torrent" "$ind" down "$filepath/$file" "$ind"
rm -f "$HOME/.cache/$file.torrent" rm -f "$filepath/$file"
;; ;;
q) q)
exit 0 exit 0

View File

@@ -12,7 +12,7 @@ help() {
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), for only id prefix it with ID:"
;; ;;
loop) loop)
name="loop" name="loop"
@@ -57,8 +57,6 @@ help() {
} }
cleanup_shit() { cleanup_shit() {
pkill -f "nc -U $discord_ipc" >/dev/null
pkill -f "tail -f $presence" >/dev/null
rm -rdf "$logdir" rm -rdf "$logdir"
exit 0 exit 0
} }
@@ -72,12 +70,14 @@ get_cookies() {
return 0 return 0
fi fi
for i in $(sqlite3 "$HOME/.config/google-chrome/Default/Cookies" "SELECT name,REPLACE(base64(SUBSTR(encrypted_value,4)),CHAR(10),'') FROM cookies WHERE host_key='.youtube.com';"); do for i in $(sqlite3 "$HOME/.config/google-chrome/Default/Cookies" "SELECT name,REPLACE(base64(SUBSTR(encrypted_value,4)),CHAR(10),'') FROM cookies WHERE host_key='.youtube.com';"); do
printf "%s" "$i" | grep -qE "VISITOR_INFO1_LIVE|VISITOR_PRIVACY_METADATA" && continue
printf "%s=%s; " "$(printf '%s' "$i" | cut -d'|' -f1)" "$(printf '%s' "$i" | cut -d'|' -f2 | base64 -d | openssl enc -d -aes-128-cbc -K fd621fe5a2b402539dfa147ca9272778 -iv 20202020202020202020202020202020)" printf "%s=%s; " "$(printf '%s' "$i" | cut -d'|' -f1)" "$(printf '%s' "$i" | cut -d'|' -f2 | base64 -d | openssl enc -d -aes-128-cbc -K fd621fe5a2b402539dfa147ca9272778 -iv 20202020202020202020202020202020)"
done >"$cookie" done >"$cookie"
} }
get_data() { get_data() {
grep -q "SAPISID" "$logdir/cookies" 2>/dev/null && sapisid_header="Authorization: SAPISIDHASH $(printf '%s_%s' "$(date +%s)" "$(printf '%s %s %s' "$(date +%s)" "$(sed -nE 's|.*SAPISID=([^;]*);.*|\1|p' "$logdir/cookies")" "$base_url" | sha1sum | cut -d' ' -f1)")" || sapisid_header="" lol=$(date +%s)
grep -q "SAPISID" "$logdir/cookies" 2>/dev/null && sapisid_hash=$(printf '%s_%s' "$lol" "$(printf '%s %s %s' "$lol" "$(sed -nE 's|.*SAPISID=([^;]*);.*|\1|p' "$logdir/cookies")" "$base_url" | sha1sum | cut -d' ' -f1)") && sapisid_header="Authorization: SAPISIDHASH $sapisid_hash" || sapisid_header=""
curl -X POST -A "${3:-$agent}" -s "$base_url/youtubei/v1/$1?key=${4:-AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30}&prettyPrint=false" -H "content-type:application/json" -d "$2" -b "$(cat "$cookie")" -e "$base_url" -H "$sapisid_header" curl -X POST -A "${3:-$agent}" -s "$base_url/youtubei/v1/$1?key=${4:-AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30}&prettyPrint=false" -H "content-type:application/json" -d "$2" -b "$(cat "$cookie")" -e "$base_url" -H "$sapisid_header"
} }
@@ -151,44 +151,6 @@ loop() {
cleanup_shit cleanup_shit
} }
#discord rich presence written in a nut-shell code
set_activity() {
#length of payload
len=${#1}
#outputs opcode in little endian encoding
printf "\\001\\000\\000\\000"
#loop for length to encode in little endian encoding
for i in 0 8 16 24; do
len=$((len >> i))
#shellcheck disable=SC2059
printf "\\$(printf "%03o" "$len")"
done
#print the payload that need to be sent
printf "%s" "$1"
}
start_rich_presence() {
rm -f "$handshook" >/dev/null
tail -f "$presence" | nc -U "$discord_ipc" >"/tmp/ipclog"
}
update_rich_presence() {
title=$1
id=$2
#dur=$3
#start=$(date +%s)
#payload='{"cmd": "SET_ACTIVITY", "args": {"activity": {"details": "'$(printf "%s" "$title" | sed 's|[^-]*$||;s|-$||;s| $||;s|^ ||')'", "state": "'$(printf "%s" "$title" | sed 's_.* - __;s| $||')'", "timestamps": {"start": '"$start"',"end": '"$((start + dur))"'}, "assets": {"large_image": "https://i.ytimg.com/vi/'$id'/mqdefault.jpg","large_text":"Checkmate Premium Users"},"buttons": [{"label":"Listen Song", "url": "https://music.youtube.com/watch?v='$id'"}]},"pid":786}, "nonce": "1"}' #pid needs to be set and constant so discord knows which application to update
payload='{"cmd": "SET_ACTIVITY", "args": {"activity": {"details": "'$(printf "%s" "$title" | sed 's|[^-]*$||;s|-$||;s| $||;s|^ ||')'", "state": "'$(printf "%s" "$title" | sed 's_.* - __;s| $||')'", "assets": {"large_image": "https://i.ytimg.com/vi/'$id'/mqdefault.jpg","large_text":"Checkmate Premium Users","small_image":"https://upload.wikimedia.org/wikipedia/commons/7/73/Mpv_logo_%28official%29.png"},"buttons": [{"label":"Listen Song", "url": "https://music.youtube.com/watch?v='$id'"}]},"pid":786}, "nonce": "'$(date +%s%N)'"}' #pid needs to be set and constant so discord knows which application to update
if [ ! -e "$handshook" ]; then
handshake='{"v":1,"client_id":"'$presence_client_id'"}'
# handshake with opcode
printf "\\000\\000\\000\\000\\$(printf "%03o" "${#handshake}")\\000\\000\\000%s" "$handshake" >"$presence"
sleep 2
touch "$handshook"
fi
set_activity "$payload" >"$presence"
}
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
@@ -198,7 +160,7 @@ play() {
#get song's audio url #get song's audio url
random_no=$(head /dev/urandom | tr -dc '0-4' | cut -c1) random_no=$(head /dev/urandom | tr -dc '0-4' | cut -c1)
andy_yt_ver="7.05.54" andy_yt_ver="7.08.53"
extra_up=$((random_no > 1)) extra_up=$((random_no > 1))
droid_agent="com.google.android.apps.youtube.music/$andy_yt_ver (Linux; U; Android 1$random_no) gzip" droid_agent="com.google.android.apps.youtube.music/$andy_yt_ver (Linux; U; Android 1$random_no) gzip"
json="{ json="{
@@ -231,23 +193,14 @@ play() {
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 -e -h "string:x-canonical-private-synchronous:${0##*/}" -i "$logdir/default.jpg" "Now Playing" "$title" -t 5000 curl -s "https://i.ytimg.com/vi/$id/hqdefault.jpg" -o - | magick convert - -crop 270x270+105+45 "$logdir/default.jpg" && notify-send -e -h "string:x-canonical-private-synchronous:${0##*/}" -i "$logdir/default.jpg" "Now Playing" "$title" -t 5000
pgrep -f "$socket" >/dev/null || (setsid -f mpv --really-quiet --input-ipc-server="$socket" --idle --quiet >/dev/null && sleep 1) pgrep -f "$socket" >/dev/null || (setsid -f mpv --really-quiet --input-ipc-server="$socket" --idle --quiet >/dev/null && sleep 1)
printf '{"command":["loadfile","%s","replace"]}\n' "$audio_url" | socat - "$socket" printf '{"command":["loadfile","%s","replace"]}\n' "$audio_url" | socat - "$socket"
printf "SONG='%s'\nARTIST='%s'\nID='%s'" "$(printf '%s' "$title" | sed 's|[^-]*$||g;s|-$||g;s| $||g;s|^ ||g')" "$(printf '%s' "$title" | sed 's_.* - __;s| $||')" "$id" >"$logdir/current" printf "SONG='%s'\nARTIST='%s'\nID='%s'" "$(printf '%s' "$title" | sed 's|[^-]*$||g;s|-$||g;s| $||g;s|^ ||g')" "$(printf '%s' "$title" | sed 's_.* - __;s| $||')" "$id" >"$logdir/current"
#required for discord rich presence to set end timestamp
duration=$(printf '%s' "$audio_url" | sed -nE 's|.*&dur=([^\.]*).*|\1|p')
#self explainatory #self explainatory
get_song_lyrics "$id" & get_song_lyrics "$id" &
#start the presence
pgrep -f "nc -U $discord_ipc" >/dev/null || setsid -f "$0" start_rich_presence
#update the discord rich presence, requires client id
update_rich_presence "$title" "$id" "$duration" &
#next songs data #next songs data
[ -n "$3" ] && get_music_list & [ -n "$3" ] && get_music_list &
@@ -261,7 +214,7 @@ search_play() {
[ -z "$query" ] && notify-send -e "Err.. Search query empty" -u critical -h "string:x-canonical-private-synchronous:${0##*/}" && exit 1 [ -z "$query" ] && notify-send -e "Err.. Search query empty" -u critical -h "string:x-canonical-private-synchronous:${0##*/}" && exit 1
#storing context #storing context
printf '{"client":{"clientName":"WEB_REMIX","clientVersion":"1.20240501.01.00"}}' >"$logdir/context" printf '{"client":{"clientName":"WEB_REMIX","clientVersion":"1.20240717.01.00"}}' >"$logdir/context"
#extracting your cookies so that the song list are according to your taste #extracting your cookies so that the song list are according to your taste
get_cookies get_cookies
@@ -321,13 +274,8 @@ menu() {
logdir="/tmp/${0##*/}" logdir="/tmp/${0##*/}"
socket="$logdir/${0##*/}-mpvsocket" socket="$logdir/${0##*/}-mpvsocket"
discord_ipc="${XDG_RUNTIME_DIR}/discord-ipc-0"
handshook="$logdir/handshook"
presence="$logdir/${0##*/}-presence"
presence_client_id="1165951947245879316"
base_url="https://music.youtube.com" base_url="https://music.youtube.com"
[ -d "$logdir" ] || mkdir "$logdir" [ -d "$logdir" ] || mkdir "$logdir"
[ -p "$presence" ] || mkfifo "$presence"
cookie="$logdir/cookies" cookie="$logdir/cookies"
agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"