It works on my computer

This commit is contained in:
coolnsx
2023-09-02 14:27:51 +05:30
parent a737a0de56
commit b20ca5f107
4 changed files with 151 additions and 59 deletions

19
ani-new
View File

@@ -42,6 +42,10 @@ provider_run() {
esac esac
} }
allanime_curl() {
curl -e 'https://allanime.to' -sL --cipher AES256-SHA256 -G "${base_url}/api" -A "$agent" --data-urlencode "$1" --data-urlencode "$2"
}
base_url="https://api.allanime.day" base_url="https://api.allanime.day"
agent="Mozilla/5.0" agent="Mozilla/5.0"
[ -n "$2" ] && debug=1 [ -n "$2" ] && debug=1
@@ -55,7 +59,7 @@ case $(uname -o) in
*) *)
os="linux" os="linux"
download_dir="$HOME/Downloads" download_dir="$HOME/Downloads"
terminal="foot -e" terminal="$TERMINAL -e"
script_dir="$HOME/repos_scripts" script_dir="$HOME/repos_scripts"
;; ;;
esac esac
@@ -65,8 +69,9 @@ esac
trap "exit 0" INT HUP trap "exit 0" INT HUP
info_$os "Parsing $base_url.. Please wait..." info_$os "Parsing $base_url.. Please wait..."
query="query( \$search: SearchInput \$limit: Int \$page: Int \$translationType: VaildTranslationTypeEnumType \$countryOrigin: VaildCountryOriginEnumType ) { shows( search: \$search limit: \$limit page: \$page translationType: \$translationType countryOrigin: \$countryOrigin ) { edges { _id name lastEpisodeInfo __typename } }}" #shellcheck disable=SC2016
[ -z "$1" ] && url=$(curl -e 'https://allanime.to' -s --cipher 'AES256-SHA256' -G "${base_url}/api" -d "variables=%7B%22search%22%3A%7B%22sortBy%22%3A%22Recent%22%2C%22allowAdult%22%3Atrue%2C%22allowUnknown%22%3Atrue%7D%2C%22limit%22%3A40%2C%22page%22%3A1%2C%22translationType%22%3A%22sub%22%2C%22countryOrigin%22%3A%22JP%22%7D" --data-urlencode "query=$query" -A "$agent" | sed 's|Show|\n|g' | sed -nE 's|.*_id":"([^"]*)","name":"([^"]*)".*sub":\{"episodeString":"([^"]*)".*|\1\t\2 Episode \3|p' | menu_$os "Select Anime: " '--with-nth 2..' | tr ':' ' ' | tr -s ' ') || url=$(printf "%s" "$1" | sed -nE 's|.*/watch/(.*)-sub|\1|p') query='query($search: SearchInput $limit: Int $page: Int $translationType: VaildTranslationTypeEnumType $countryOrigin: VaildCountryOriginEnumType) { shows( search: $search limit: $limit page: $page translationType: $translationType countryOrigin: $countryOrigin ) {edges { _id name lastEpisodeInfo __typename}}}'
[ -z "$1" ] && url=$(allanime_curl "query=$query" 'variables={"search":{"sortBy":"Recent","allowAdult":true,"allowUnknown":true},"limit":40,"page":1,"translationType":"sub","countryOrigin":"JP"}' | sed 's|Show|\n|g' | sed -nE 's|.*_id":"([^"]*)","name":"([^"]*)".*sub":\{"episodeString":"([^"]*)".*|\1\t\2 Episode \3|p' | menu_$os "Select Anime: " '--with-nth 2..' | tr ':' ' ' | tr -s ' ') || url=$(printf "%s" "$1" | sed -nE 's|.*/watch/(.*)-sub|\1|p')
[ -z "$url" ] && error_$os "No anime selected" && exit 0 [ -z "$url" ] && error_$os "No anime selected" && exit 0
title=$(printf "%s" "$url" | cut -f2-) title=$(printf "%s" "$url" | cut -f2-)
@@ -74,8 +79,9 @@ id=$(printf "%s" "$url" | cut -f1)
ep_no=$(printf "%s" "$url" | sed 's/.*Episode //g') ep_no=$(printf "%s" "$url" | sed 's/.*Episode //g')
info_$os "Loading Episode $title.." info_$os "Loading Episode $title.."
episode_embed_gql="query (\$showId: String!, \$translationType: VaildTranslationTypeEnumType!, \$episodeString: String!) { episode( showId: \$showId translationType: \$translationType episodeString: \$episodeString ) { episodeString sourceUrls }}" #shellcheck disable=SC2016
data=$(curl -e https://allanime.to -sL --cipher AES256-SHA256 -G "{$base_url}/api" --data-urlencode "variables={\"showId\":\"$id\",\"translationType\":\"sub\",\"countryOrigin\":\"ALL\",\"episodeString\":\"$ep_no\"}" --data-urlencode "query=$episode_embed_gql" -A 'Mozilla/5.0 (Windows NT 6.1; Win64; rv:109.0) Gecko/20100101 Firefox/109.0' | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":"--([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p') episode_embed_gql='query ($showId: String!, $translationType: VaildTranslationTypeEnumType!, $episodeString: String!) { episode( showId: $showId translationType: $translationType episodeString: $episodeString ) { episodeString sourceUrls }}'
data=$(allanime_curl "variables={\"showId\":\"$id\",\"translationType\":\"sub\",\"countryOrigin\":\"ALL\",\"episodeString\":\"$ep_no\"}" "query=$episode_embed_gql" | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":"--([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p')
info_$os "Fetching Embed links" info_$os "Fetching Embed links"
#dropbox links #dropbox links
@@ -87,9 +93,6 @@ 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"

View File

@@ -15,7 +15,7 @@ download_apk(){
[ -z "$download_url" ] && info "[ $app ][ v$version ] Unable to Fetch Download URL.." "31" && exit 1 [ -z "$download_url" ] && info "[ $app ][ v$version ] Unable to Fetch Download URL.." "31" && exit 1
info "[ $app ][ v$version ] Downloading App.." info "[ $app ][ v$version ] Downloading App.."
aria2c -x16 -s16 "${apk_provider_url}${download_url}" --user-agent="$agent" -d "$tmp_dir" -o "$app-$version.apk" --allow-overwrite=true --check-certificate=false --download-result=hide --summary-interval=0 && info "[ $app ][ v$version ] App Downloaded.." && return 0 aria2c -x16 -s16 "${apk_provider_url}${download_url}" --user-agent="$agent" -d "$tmp_dir" -o "$app-$version.apk" --allow-overwrite=true --check-certificate=false --download-result=hide --summary-interval=0 && info "[ $app ][ v$version ] App Downloaded.." && return 0
info "[ $app ][ v$version ] Unable to Download.." "31" info "[ $app ][ v$version ] Unable to Download.." "31" && exit 1
} }
tmp_dir="/tmp/revanced" tmp_dir="/tmp/revanced"
@@ -30,11 +30,12 @@ rv_inte="integrations-$date.apk"
[ -d "$tmp_dir" ] || mkdir "$tmp_dir" [ -d "$tmp_dir" ] || mkdir "$tmp_dir"
#pre-requisite #pre-requisite
if [ ! -f "$tmp_dir/$rv_cli" ] || [ ! -f "$tmp_dir/$rv_patch" ] || [ ! -f "$tmp_dir/$rv_inte" ];then if [ ! -f "$tmp_dir/$rv_cli.aria2" ] && [ ! -f "$tmp_dir/$rv_patch.aria2" ] && [ ! -f "$tmp_dir/$rv_inte.aria2" ] && [ -f "$tmp_dir/$rv_cli" ] && [ -f "$tmp_dir/$rv_patch" ] && [ -f "$tmp_dir/$rv_inte" ];then
info "revanced-cli,revanced-patches,revanced-integrations already downloaded" "32"
else
rm -f "$tmp_dir"/*.aria2
info "Downloading revanced-cli,revanced-patches,revanced-integrations.." info "Downloading revanced-cli,revanced-patches,revanced-integrations.."
printf "%s\n%s\n%s" "$(curl -s "https://api.github.com/repos/revanced/revanced-cli/releases/latest" -L -A "$agent" | sed -nE "s|.*browser_download_url\": \"([^\"]*.jar)\"|\1\n\tout=$rv_cli|p")" "$(curl -s "https://api.github.com/repos/revanced/revanced-patches/releases/latest" -L -A "$agent" | sed -nE "s|.*browser_download_url\": \"([^\"]*.jar)\"|\1\n\tout=$rv_patch|p")" "$(curl -s "https://api.github.com/repos/revanced/revanced-integrations/releases/latest" -L -A "$agent" | sed -nE "s|.*browser_download_url\": \"([^\"]*.apk)\"|\1\n\tout=$rv_inte|p")" | aria2c -j3 -x16 -s16 -i - --check-certificate=false --download-result=hide --summary-interval=0 --allow-overwrite=true -d "$tmp_dir" && info "Downloaded revanced-cli,revanced-patches,revanced-integrations at $tmp_dir" printf "%s\n%s\n%s" "$(curl -s "https://api.github.com/repos/revanced/revanced-cli/releases/latest" -L -A "$agent" | sed -nE "s|.*browser_download_url\": \"([^\"]*.jar)\"|\1\n\tout=$rv_cli|p")" "$(curl -s "https://api.github.com/repos/revanced/revanced-patches/releases/latest" -L -A "$agent" | sed -nE "s|.*browser_download_url\": \"([^\"]*.jar)\"|\1\n\tout=$rv_patch|p")" "$(curl -s "https://api.github.com/repos/revanced/revanced-integrations/releases/latest" -L -A "$agent" | sed -nE "s|.*browser_download_url\": \"([^\"]*.apk)\"|\1\n\tout=$rv_inte|p")" | aria2c -j3 -x16 -s16 -i - --check-certificate=false --download-result=hide --summary-interval=0 --allow-overwrite=true -d "$tmp_dir" && info "Downloaded revanced-cli,revanced-patches,revanced-integrations at $tmp_dir"
else
info "revanced-cli,revanced-patches,revanced-integrations already downloaded" "32"
fi fi
#choose your app #choose your app
@@ -46,14 +47,14 @@ fi
case $app in case $app in
youtube) youtube)
arch="universal" arch="universal"
version=$(curl -s "https://api.revanced.app/v2/patches/latest" | sed -nE 's|.*"compatiblePackages":\[\{"name":"com.google.android.youtube","versions":\[(.*[^\]]).*|\1|p' | tr -d ']}"' | tr ',' '\n' | tail -1 | tr '.' '-') [ -z "$2" ] && version=$(curl -s "https://api.revanced.app/v2/patches/latest" | sed -nE 's|.*"compatiblePackages":\[\{"name":"com.google.android.youtube","versions":\[(.*[^\]]).*|\1|p' | tr -d ']}"' | tr ',' '\n' | tail -1) || version=$2
exclude_patch_list="always-autorepeat,disable-auto-captions,disable-zoom-haptics,enable-debugging,external-downloads,hide-autoplay-button,hide-captions-button,hide-cast-button,hide-floating-microphone-button,hide-layout-components,hide-load-more-button,hide-player-buttons,hide-player-overlay,hide-seekbar,hide-timestamp,hide-video-action-buttons,navigation-buttons,player-flyout-menu,remove-player-controls-background,spoof-app-version,swipe-controls" exclude_patch_list="always-autorepeat,disable-auto-captions,disable-zoom-haptics,enable-debugging,external-downloads,hide-autoplay-button,hide-captions-button,hide-cast-button,hide-floating-microphone-button,hide-layout-components,hide-load-more-button,hide-player-buttons,custom-player-overlay-opacity,hide-seekbar,hide-timestamp,hide-video-action-buttons,navigation-buttons,player-flyout-menu,remove-player-controls-background,spoof-app-version,swipe-controls"
out="yt-revanced-$version.apk" out="yt-revanced-$version.apk"
;; ;;
youtube-music) youtube-music)
arch="arm64-v8a" arch="arm64-v8a"
[ -z "$2" ] && version="6-10-53" || version=$2 [ -z "$2" ] && version="6.10.53" || version=$2
exclude_patch_list="dummy-patch" exclude_patch_list=""
out="yt-music-revanced-$version.apk" out="yt-music-revanced-$version.apk"
;; ;;
esac esac
@@ -66,12 +67,12 @@ else
fi fi
info "Checking Patches for excluding.." info "Checking Patches for excluding.."
patch_list=$(java -jar "$tmp_dir/$rv_cli" -b "$tmp_dir/$rv_patch" -a "$tmp_dir/$app-$version.apk" -l --with-packages) patch_list=$(java -jar "$tmp_dir/$rv_cli" list-patches "$tmp_dir/$rv_patch" --with-descriptions=false)
if [ -n "$exclude_patch_list" ];then if [ -n "$exclude_patch_list" ];then
info "Excluding Patches.." "33" info "Excluding Patches.." "33"
for i in $(printf "%s" "$exclude_patch_list" | tr ',' '\n');do for i in $(printf "%s" "$exclude_patch_list" | tr ',' '\n');do
if printf "%s" "$patch_list" | grep -q "$i";then if printf "%s" "$patch_list" | grep -iq "$(printf '%s' "$i" | tr '-' ' ')";then
res="32m ✓" res="32m ✓"
else else
res="31m " res="31m "
@@ -79,15 +80,15 @@ if [ -n "$exclude_patch_list" ];then
fi fi
printf "\033[2K\r\033[1;%s %s\n" "$res" "$i" printf "\033[2K\r\033[1;%s %s\n" "$res" "$i"
done done
exclude_patches=$(printf "%s" "$exclude_patch_list" | tr ',' '\n' | sed 's|^|-e |g' | tr '\n' ' ') exclude_patches=$(printf "%s" "$exclude_patch_list" | tr ',' '\n' | sed 's|^|--exclude |g' | tr '\n' ' ')
else else
info "Nothing to Exclude.." "32" info "Nothing to Exclude.." "32"
fi fi
[ -n "$check" ] && info "Some of the patches are not Excluded,Check all failed patches using :" "31" && info "java -jar '$tmp_dir/$rv_cli' -b '$tmp_dir/$rv_patch' -a '$tmp_dir/$app-$version.apk' -l --with-packages" "33" && exit 1 [ -n "$check" ] && info "Some of the patches are not Excluded,Check all failed patches using :" "31" && info "java -jar '$tmp_dir/$rv_cli' list-patches '$tmp_dir/$rv_patch' --with-packages" "33" && exit 1
info "All listed Patches Excluded" info "All listed Patches Excluded"
info "Patching $app-$version.apk.." info "Patching $app-$version.apk.."
#shellcheck disable=SC2086 #shellcheck disable=SC2086
java -jar "$tmp_dir/$rv_cli" -a "$tmp_dir/$app-$version.apk" -b "$tmp_dir/$rv_patch" -m "$tmp_dir/$rv_inte" -o "$HOME/$out" --temp-dir="$tmp_dir/build" $exclude_patches java -jar "$tmp_dir/$rv_cli" patch --patch-bundle "$tmp_dir/$rv_patch" --merge "$tmp_dir/$rv_inte" --out "$HOME/$out" --resource-cache "$tmp_dir/revanced-resource-cache" "$tmp_dir/$app-$version.apk" $exclude_patches

42
screen
View File

@@ -13,15 +13,19 @@ menu() {
record() { record() {
rm -f "$tmp_file" "$process_file" rm -f "$tmp_file" "$process_file"
#shellcheck disable=SC2034
mic="$(pactl list sources | grep -B1 'node.nick = "Digital Microphone"' | sed -nE 's|.*node.name = "([^"]*)"|\1.monitor|p')" #It is called in eval on line 9
#shellcheck disable=SC2034
speaker="$(pactl list sources | grep -B1 'node.nick = "Speaker + Headphones"' | sed -nE 's|.*node.name = "([^"]*)"|\1.monitor|p')" #It is called in eval on line 9
source=$(printf "screen only\nspeaker\nmic" | menu "Audio Source:" "3") source=$(printf "screen only\nspeaker\nmic" | menu "Audio Source:" "3")
monitor=$(hyprctl monitors | sed -nE 's|Monitor ([^ ]*).*|\1|p') 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") [ "$(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 [ -z "$source" ] && info "" "2000" "No option Selected" && return 0
info "simplescreenrecorder" "700" "Recording Started" "Capturing $monitor($source)" info "simplescreenrecorder" "700" "Recording Started" "Capturing $monitor($source)"
sleep 0.3 sleep 0.3
[ "$source" = "screen only" ] && setsid -f wf-recorder -t -m "mp4" -f "$tmp_file" >/dev/null 2>&1 && return 0 [ "$source" != "screen only" ] && pactl set-default-source "$(eval "printf \$$source")" && arg=-a
pactl set-default-source "$(eval "printf \$$source")" #shellcheck disable=SC2086
setsid -f wf-recorder -a -t -m "mp4" -f "$tmp_file" --output "$monitor" >/dev/null 2>&1 setsid -f wf-recorder -t -m "mp4" -f "$tmp_file" --output "$monitor" $arg >/dev/null 2>&1
} }
compress() { compress() {
@@ -31,8 +35,9 @@ compress() {
while :; do 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 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') 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)" size=$(du -m "$process_file" | cut -f1)
[ "$(du -m "$process_file" | cut -f1)" -gt 25 ] && killall -s KILL ffmpeg && break [ -n "$complete" ] && info "ffmpeg" "700" "Compressing File under 25 MB Using Quality Preset : $i.." "$complete / $duration ($size MB)"
[ "$size" -gt 25 ] && killall -s KILL ffmpeg && break
done done
[ "$(du -m "$process_file" | cut -f1)" -lt 25 ] && break [ "$(du -m "$process_file" | cut -f1)" -lt 25 ] && break
: $((i += 1)) : $((i += 1))
@@ -51,14 +56,30 @@ stop() {
[ -z "$out" ] && info "" "2000" "Unable to upload to oshi,moved the file from temp to your home folder as <unix_timestamp>.mp4" && mv "$tmp_file" "$HOME/$(date +%s).mp4" && return 1 [ -z "$out" ] && info "" "2000" "Unable to upload to oshi,moved the file from temp to your home folder as <unix_timestamp>.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" printf "%s" "$out" | sed -nE 's|DL: (.*)|\1|p' | wl-copy && info "com.github.davidmhewitt.clipped" "2000" "Uploaded and Copied link to clipboard"
;; ;;
*discord) *discord)
base_url="https://discord.com/api/v10"
#shellcheck disable=SC1091
. "$HOME"/.secrets
channel=$(curl -s "$base_url/guilds/$SERVER_ID/channels" -H "Authorization: $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 [ "$(du -m "$tmp_file" | cut -f1)" -gt 25 ] && compress #compressing file if greater than 25 MB
#will push discord code in next commit info "discord" "" "Uploading to Discord in $channel_name"
content="${tmp_file##*/} ($(du -h "$tmp_file" | cut -f1)) uploaded by coolans"
curl -s "$base_url/channels/$channel_id/messages" -H "Authorization: $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*)
filename=$(: | menu "Enter Filename (default: screenrecord.mp4):") defaultname="screenrecord-$(date +"%F_%H-%M-%S").mp4"
filename=$(: | menu "Enter Filename (default: $defaultname):")
[ -z "$filename" ] && filename=$defaultname
mv "$tmp_file" "$HOME/$filename" mv "$tmp_file" "$HOME/$filename"
;; ;;
*) *)
rm -f "$tmp_file" "$process_file" && info "user-trash" "2000" "Temporary File Deleted" rm -f "$tmp_file" "$process_file" && info "user-trash" "2000" "Temporary File Deleted"
;; ;;
@@ -68,9 +89,6 @@ stop() {
tmp_file="/tmp/screenrecord.mp4" tmp_file="/tmp/screenrecord.mp4"
process_file="/tmp/processed.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.3.HiFi__hw_sofhdadsp__sink.monitor" #It is called in eval on line 9
$1 "$2"
[ "$#" -gt 0 ] && $1 "$2"

122
yt-music
View File

@@ -54,8 +54,64 @@ help() {
exit 0 exit 0
} }
cleanup_shit(){
rm -rdf "$logdir"
exit 0
}
get_cookies() {
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=%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"
}
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" -d "$2" -b "$cookie" -e "$base_url/$3" -c "$cookie" 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=""
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"
}
get_music_list(){
json_next="{
\"enablePersistentPlaylistPanel\": true,
\"tunerSettingValue\": \"AUTOMIX_SETTING_NORMAL\",
\"playlistId\": \"RDAMVM$(cat "$logdir/start")\",
\"params\": \"wAEB\",
$([ -e "$logdir/continue_token" ] && cat "$logdir/continue_token")
\"isAudioOnly\": true,
\"context\": $(cat "$logdir/context")
}"
get_data "next" "$json_next" | tee "$logdir/extract_continuation" | sed 's/playlistPanelVideoRenderer/\n/g' | sed -nE 's_.*text":"(.*)"}.*longBylineText":\{"runs":\[\{"text":"([^"]*)","navigationEndpoint.*videoId":"([^"]*)".*_\1 - \2\t\3_p' | sed '$d' >> "$logdir/next"
sed -nE 's|.*nextRadioContinuationData":\{([^,]*).*|\1,|p' "$logdir/extract_continuation" > "$logdir/continue_token"
}
get_song_lyrics() {
json_next="{
\"enablePersistentPlaylistPanel\": true,
\"tunerSettingValue\": \"AUTOMIX_SETTING_NORMAL\",
\"videoId\": \"$1\",
\"isAudioOnly\": true,
\"context\": $(cat "$logdir/context")
}"
browseId=$(get_data "next" "$json_next" | sed -nE 's|.*"browseId":"(MPLYt[^"]*)".*TRACK_LYRICS.*|\1|p')
if [ -n "$browseId" ]; then
json_lyrics="{
\"context\": {
\"client\": {
\"clientName\": \"ANDROID_MUSIC\",
\"clientVersion\": \"$andy_yt_ver\",
\"androidSdkVersion\": $(( random_no + extra_up + 29 )),
\"userAgent\": \"$droid_agent\",
\"hl\": \"en\",
\"timeZone\": \"UTC\",
\"utcOffsetMinutes\": 0
}
},
\"browseId\": \"$browseId\"
}"
get_data "browse" "$json_lyrics" "$droid_agent" "AIzaSyAOghZGza2MQSZkY_zfZ370N-PUdXEo8AI" | sed 's/metadata"/\n/g' | sed -nE 's|.*lyricLine":"([^"]*)","cueRange":\{"startTimeMilliseconds":"([^"]*)","endTimeMilliseconds":"([^"]*)".*|\3\t\1|p' > "$logdir/lyrics"
fi
} }
loop() { loop() {
@@ -63,8 +119,8 @@ loop() {
#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 cleanup_shit INT HUP TERM
while true; do while :; 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
@@ -74,8 +130,9 @@ loop() {
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 || cleanup_shit
[ -z "$pos" ] && pgrep -f "mpvsocket" >/dev/null && [ -n "$(cat "$logdir/next")" ] && play "$(shuf -n1 "$logdir/next")" "$1" [ -z "$pos" ] && i=$(cat "$logdir/counter") && : $((i+=1)) && pgrep -f "mpvsocket" >/dev/null && [ -n "$(cat "$logdir/next")" ] && play "$(sed -n "${i}p" "$logdir/next")" "$1" && printf '%s' "$i" > "$logdir/counter"
[ "$(cat "$logdir/counter")" -ge "$(wc -l "$logdir/next" | cut -d' ' -f1)" ] && get_music_list
done done
} }
@@ -88,15 +145,16 @@ play() {
[ -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 '1-2' | cut -c1) random_no=$(head /dev/urandom | tr -dc '0-4' | cut -c1)
andy_yt_ver="6.13.52" andy_yt_ver="6.16.52"
extra_up=$((random_no >= 2))
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="{
\"context\": { \"context\": {
\"client\": { \"client\": {
\"clientName\": \"ANDROID_MUSIC\", \"clientName\": \"ANDROID_MUSIC\",
\"clientVersion\": \"$andy_yt_ver\", \"clientVersion\": \"$andy_yt_ver\",
\"androidSdkVersion\": $((random_no + 29)), \"androidSdkVersion\": $(( random_no + extra_up + 29 )),
\"userAgent\": \"$droid_agent\", \"userAgent\": \"$droid_agent\",
\"hl\": \"en\", \"hl\": \"en\",
\"timeZone\": \"UTC\", \"timeZone\": \"UTC\",
@@ -113,7 +171,7 @@ play() {
\"racyCheckOk\": true \"racyCheckOk\": true
}" }"
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') audio_url=$(get_data "player" "$json" "$droid_agent" "AIzaSyAOghZGza2MQSZkY_zfZ370N-PUdXEo8AI" | sed -nE 's_.*itag":251,"url":"([^"]*)".*_\1_p')
[ -z "$audio_url" ] && return 0 [ -z "$audio_url" ] && return 0
if [ -n "$2" ]; then if [ -n "$2" ]; then
printf "Name >> %s\n" "$title" printf "Name >> %s\n" "$title"
@@ -121,46 +179,59 @@ 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 -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 -h "string:x-canonical-private-synchronous:${0##*/}" -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"
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="{ [ -n "$3" ] && get_music_list &
\"enablePersistentPlaylistPanel\": true, get_song_lyrics "$id" "" &
\"tunerSettingValue\": \"AUTOMIX_SETTING_NORMAL\", pgrep -f "yt-music loop" >/dev/null || setsid -f "$0" loop
\"playlistId\": \"RDAMVM$id\",
\"isAudioOnly\": true,
\"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" >/dev/null || 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 -h "string:x-canonical-private-synchronous:${0##*/}" && exit 1
#storing context
printf '{"client":{"clientName":"WEB_REMIX","clientVersion":"1.20230731.00.00"}}' >"$logdir/context" printf '{"client":{"clientName":"WEB_REMIX","clientVersion":"1.20230731.00.00"}}' >"$logdir/context"
#json for song search
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]:")
[ -z "$res" ] || play "$res" "verbose" #extracting your cookies so that the song list are according to your taste
get_cookies
printf "0" > "$logdir/counter"
printf '' > "$logdir/next"
res=$(get_data "search" "$json_search" "$agent" | sed 's/watchEndpoint"/\n/g' | sed -nE 's_.*videoId":"([^"]*)",.*label":"Play ([^"]*)".*_\2\t\1_p' | menu "Yt-music [Play]:")
printf "%s" "$res" | cut -f2 > "$logdir/start"
[ -z "$res" ] || play "$res" "verbose" "1"
} }
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") pgrep -f "mpvsocket" || return 0
i=$(cat "$logdir/counter")
if [ -z "$1" ]; then
: $((i+=1))
play "$(sed -n "${i}p" "$logdir/next")" "$1"
else
notify-send -h "string:x-canonical-private-synchronous:${0##*/}" -i "$logdir/default.jpg" "$(cut -d">" -f1 "$logdir/current" | tr ':' '\n')"
next=$(nl -n'ln' "$logdir/next" | sed "s/^$i /& /" | menu "YT-music [play-next]: ")
[ -z "$next" ] && return 0
i=$(printf '%s' "$next" | sed 's///g' | cut -f1 | tr -d ' ')
play "$(printf '%s' "$next" | cut -f2-)" "verbose"
fi
printf '%s' "$i" > "$logdir/counter"
} }
menu() { menu() {
@@ -171,7 +242,6 @@ logdir="/tmp/yt-music"
base_url="https://music.youtube.com" base_url="https://music.youtube.com"
[ -d "$logdir" ] || mkdir "$logdir" [ -d "$logdir" ] || mkdir "$logdir"
cookie="$logdir/cookies" cookie="$logdir/cookies"
next_data="$logdir/next"
agent="Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.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" #call this script by script-name "function_name" "query"