mirror of
https://github.com/CoolnsX/repos_scripts.git
synced 2025-12-20 07:15:20 +05:30
Feat : remove duplicates logic in yt-music
This commit is contained in:
@@ -5,7 +5,7 @@ menu_droid() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
menu_linux() {
|
menu_linux() {
|
||||||
bemenu --fn 'Cascadia Mono 15' -i -c -W "0.${3:-6}" -B 3 -l 25 -p "$1"
|
bemenu --fn 'Cascadia Mono 15' -i -c -W "0.${3:-6}" -B 3 -l 25 -p "$1" --fixed-height 25
|
||||||
}
|
}
|
||||||
|
|
||||||
search_droid() {
|
search_droid() {
|
||||||
|
|||||||
13
screen
13
screen
@@ -8,7 +8,7 @@ info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
menu() {
|
menu() {
|
||||||
bemenu --fn 'IBM Plex Sans 15' -i -c -W "0.${2:-5}" -B 3 -p "$1" -l 26
|
bemenu --fn 'IBM Plex Sans 15' -i -c -W "0.${2:-5}" -B 3 -p "$1" -l 26 --accept-single
|
||||||
}
|
}
|
||||||
|
|
||||||
compress() {
|
compress() {
|
||||||
@@ -36,13 +36,16 @@ record() {
|
|||||||
#shellcheck disable=SC2034
|
#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
|
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')
|
|
||||||
[ "$(printf '%s\n' "$monitor" | wc -l)" -gt 1 ] && monitor=$(printf '%s' "$monitor" | menu "Choose Monitor:" "3")
|
|
||||||
#shellcheck disable=SC2089
|
|
||||||
[ -z "$source" ] && info "" "2000" "No option Selected" && return 0
|
[ -z "$source" ] && info "" "2000" "No option Selected" && return 0
|
||||||
|
|
||||||
|
monitor=$(hyprctl monitors | sed -nE 's|Monitor ([^ ]*).*|\1|p' | menu "Choose Monitor:" "3")
|
||||||
|
|
||||||
|
[ -z "$monitor" ] && info "" "2000" "No option Selected" && return 0
|
||||||
|
|
||||||
[ "$source" != "screen only" ] && pactl set-default-source "$(eval "printf \$$source")" && arg=-a
|
[ "$source" != "screen only" ] && pactl set-default-source "$(eval "printf \$$source")" && arg=-a
|
||||||
#shellcheck disable=SC2086,SC2090
|
#shellcheck disable=SC2086,SC2090
|
||||||
info "simplescreenrecorder" "1000" "Select Region" "Tap/Click to select full" && setsid -f wf-recorder -x yuv420p -f /tmp/screenrecord.mp4 --output eDP-1 $arg -g "$(slurp)" >/dev/null 2>&1
|
info "simplescreenrecorder" "1000" "Select Region" "Tap/Click to select full" && setsid -f wf-recorder -x yuv420p -f /tmp/screenrecord.mp4 --output "$monitor" $arg -g "$(slurp)" >/dev/null 2>&1
|
||||||
info "simplescreenrecorder" "700" "Recording Started" "Capturing $monitor($source)"
|
info "simplescreenrecorder" "700" "Recording Started" "Capturing $monitor($source)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
40
yt-music
40
yt-music
@@ -82,8 +82,9 @@ get_music_list(){
|
|||||||
\"isAudioOnly\": true,
|
\"isAudioOnly\": true,
|
||||||
\"context\": $(cat "$logdir/context")
|
\"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"
|
next_data=$(get_data "next" "$json_next" | sed 's/playlistPanelVideoRenderer/\n/g;s/hasPersistentPlaylistPanel/\n/g' | sed -nE 's|.*text":"(.*)"}.*longBylineText":\{"runs":\[\{"text":"([^"]*)","navigationEndpoint.*videoId":"([^"]*)".*|\1 - \2\t\3|p;s|.*nextRadioContinuationData":\{([^,]*).*|\1,|p')
|
||||||
sed -nE 's|.*nextRadioContinuationData":\{([^,]*).*|\1,|p' "$logdir/extract_continuation" > "$logdir/continue_token"
|
printf '%s' "$next_data" | sed -e "$(cut -f2 "/tmp/yt-music/next" | sed 's|^|/|g;s|$|/d|g')" -e '/"continuation"/d' >> "$logdir/next"
|
||||||
|
printf '%s' "$next_data" | sed -n '/"continuation"/p' > "$logdir/continue_token"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_song_lyrics() {
|
get_song_lyrics() {
|
||||||
@@ -125,17 +126,17 @@ loop() {
|
|||||||
trap cleanup_shit INT HUP TERM
|
trap cleanup_shit INT HUP TERM
|
||||||
while :; 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 - "$socket" | sed -nE 's_.*data":([^\.]*).*_\1_p')
|
||||||
while [ -n "$pos" ]; do
|
while [ -n "$pos" ]; do
|
||||||
pos=$(echo '{ "command": ["get_property", "time-remaining"]}' | socat - /tmp/mpvsocket | sed -nE 's_.*data":([^\.]*).*_\1_p')
|
pos=$(echo '{ "command": ["get_property", "time-remaining"]}' | socat - "$socket" | sed -nE 's_.*data":([^\.]*).*_\1_p')
|
||||||
[ -z "$1" ] || printf "\033[2K\rnext music in $pos second(s)%s" "$(echo '{ "command": ["get_property", "pause"]}' | socat - /tmp/mpvsocket | sed -nE 's_.*data":([^,]*).*_\1_p' | sh && printf " (paused)")"
|
[ -z "$1" ] || printf "\033[2K\rnext music in $pos second(s)%s" "$(echo '{ "command": ["get_property", "pause"]}' | socat - "$socket" | sed -nE 's_.*data":([^,]*).*_\1_p' | sh && printf " (paused)")"
|
||||||
[ -z "$pos" ] && printf "\033[2K\r\n"
|
[ -z "$pos" ] && printf "\033[2K\r\n"
|
||||||
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 - "$socket" | sed -nE 's_.*data":([^\.]*).*_\1_p')
|
||||||
pgrep -f "mpvsocket" >/dev/null || cleanup_shit
|
pgrep -f "$socket" >/dev/null || cleanup_shit
|
||||||
#shellcheck disable=SC2030,SC2031
|
#shellcheck disable=SC2030,SC2031
|
||||||
[ -z "$pos" ] && i=$(cat "$logdir/counter") && : $((i+=1)) && pgrep -f "mpvsocket" >/dev/null && [ -n "$(cat "$logdir/next")" ] && play "$(sed -n "$((i+=1))p" "$logdir/next")" "$1" && printf '%s' "$i" > "$logdir/counter"
|
[ -z "$pos" ] && i=$(cat "$logdir/counter") && : $((i+=1)) && pgrep -f "$socket" >/dev/null && [ -n "$(cat "$logdir/next")" ] && play "$(sed -n "$((i+=1))p" "$logdir/next")" "$1" && printf '%s' "$i" > "$logdir/counter"
|
||||||
tail -1 "$logdir/next" | grep -q "$(cut -d'>' -f2 < "$logdir/current")" && get_music_list
|
tail -1 "$logdir/next" | grep -q "$(cut -d'>' -f2 < "$logdir/current")" && get_music_list
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@@ -184,20 +185,23 @@ play() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
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
|
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 "$socket" >/dev/null || (setsid -f mpv --really-quiet --input-ipc-server="$socket" --idle --quiet >/dev/null && sleep 1)
|
||||||
echo "{ \"command\": [\"loadfile\", \"$audio_url\", \"replace\"] }" | socat - /tmp/mpvsocket
|
echo "{ \"command\": [\"loadfile\", \"$audio_url\", \"replace\"] }" | socat - "$socket"
|
||||||
printf "currently playing : %s >%s\n" "$title" "$id" >"$logdir/current"
|
printf "currently playing : %s >%s\n" "$title" "$id" >"$logdir/current"
|
||||||
|
|
||||||
|
#self explainatory
|
||||||
|
get_song_lyrics "$id" &
|
||||||
|
|
||||||
#next songs data
|
#next songs data
|
||||||
[ -n "$3" ] && get_music_list &
|
[ -n "$3" ] && get_music_list &
|
||||||
get_song_lyrics "$id" &
|
|
||||||
pgrep -f "yt-music loop" >/dev/null || setsid -f "$0" loop
|
pgrep -f "${0##*/} loop" >/dev/null || setsid -f "$0" 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]:" "" "60") || query="$1"
|
||||||
[ -z "$query" ] && notify-send "Err.. Search query empty" -u critical -h "string:x-canonical-private-synchronous:${0##*/}" && exit 1
|
[ -z "$query" ] && notify-send "Err.. Search query empty" -u critical -h "string:x-canonical-private-synchronous:${0##*/}" && exit 1
|
||||||
|
|
||||||
#storing context
|
#storing context
|
||||||
@@ -225,7 +229,7 @@ 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"
|
||||||
pgrep -f "mpvsocket" || return 0
|
pgrep -f "$socket" || return 0
|
||||||
i=$(cat "$logdir/counter")
|
i=$(cat "$logdir/counter")
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
: $((i+=1))
|
: $((i+=1))
|
||||||
@@ -234,19 +238,21 @@ play_next() {
|
|||||||
else
|
else
|
||||||
notify-send -h "string:x-canonical-private-synchronous:${0##*/}" -i "$logdir/default.jpg" "$(cut -d">" -f1 "$logdir/current" | tr ':' '\n')"
|
notify-send -h "string:x-canonical-private-synchronous:${0##*/}" -i "$logdir/default.jpg" "$(cut -d">" -f1 "$logdir/current" | tr ':' '\n')"
|
||||||
#shellcheck disable=SC2031
|
#shellcheck disable=SC2031
|
||||||
next=$(nl -n'ln' -v0 "$logdir/next" | sed "s/^$i /& /" | menu "YT-music [play-next]: ")
|
next=$(nl -n'ln' -v0 "$logdir/next" | sed "s/^$i /& /" | menu "YT-music [play-next]: " "$i")
|
||||||
[ -z "$next" ] && return 0
|
[ -z "$next" ] && return 0
|
||||||
i=$(printf '%s' "$next" | sed 's///g' | cut -f1 | tr -d ' ')
|
i=$(printf '%s' "$next" | sed 's///g' | cut -f1 | tr -d ' ')
|
||||||
play "$(printf '%s' "$next" | cut -f2-)" "verbose"
|
play "$(printf '%s' "$next" | cut -f2-)" "verbose"
|
||||||
fi
|
fi
|
||||||
printf '%s' "$i" > "$logdir/counter"
|
printf '%s' "$i" > "$logdir/counter"
|
||||||
|
tail -1 "$logdir/next" | grep -q "$(cut -d'>' -f2 < "$logdir/current")" && get_music_list
|
||||||
}
|
}
|
||||||
|
|
||||||
menu() {
|
menu() {
|
||||||
bemenu --fn 'IBM Plex Sans 15' -i -c -W 0.5 -B 3 -p "$1" -l 26
|
bemenu --fn 'IBM Plex Sans 15' -i -c -W 0.5 -B 3 -p "$1" -l 25 -I "${2:-0}" -P ">>"
|
||||||
}
|
}
|
||||||
|
|
||||||
logdir="/tmp/yt-music"
|
logdir="/tmp/${0##*/}"
|
||||||
|
socket="$logdir/${0##*/}-mpvsocket"
|
||||||
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user