Files
snaptube/snaptube.sh

62 lines
1.4 KiB
Bash
Raw Normal View History

2023-12-19 09:55:30 +01:00
#!/bin/bash
#RIPRODUTTORE SNAPCAST DA LINK YOUTUBE
2023-12-20 16:14:39 +01:00
#set -xu #per debug
2023-12-19 09:55:30 +01:00
cnt=0
trappola() {
stat=1
}
trap trappola SIGINT
#Crea dir 'songs' se non esiste
if [ ! -d "songs" ]; then
mkdir songs
fi
#Inizializza playlist
2023-12-20 16:14:39 +01:00
clear
rm /tmp/snapfifo
touch /tmp/snapfifo
2023-12-19 09:55:30 +01:00
echo -e "\nPlaylist riprodotta:" >> songs/playlist.txt
2023-12-20 16:14:39 +01:00
2
2023-12-19 09:55:30 +01:00
while :
do
#Input
((cnt++))
stat=0
echo -e '\e[37m- Player YouTube snapcast -'
echo -e "\033[90mDigita 'off' per chiudere"
2023-12-20 16:14:39 +01:00
read -p $'\033[97mLink \033[0;31mYoutube\033[97m: ' userInput
#userInput='https://www.youtube.com/watch?v=jm56jeM2b_Y' #per debug
2023-12-19 09:55:30 +01:00
#Scarica audio da link YT
if [ "$userInput" = "off" ]; then
rm songs/play.wav
2023-12-20 16:14:39 +01:00
rm /tmp/snapfifo; touch /tmp/snapfifo
2023-12-19 09:55:30 +01:00
pkill ffmpeg
break
else
title=$(yt-dlp --get-title $userInput)
yt-dlp --extract-audio --audio-format wav -o songs/"${title}".wav $userInput > /dev/null
fi
#Sposta e Suona
echo -e "\033[90mIn riproduzione:"; echo -e "\033[97m$title\n\n"; echo $title >> songs/playlist.txt
clear; echo -e "\033[90mIn riproduzione:"; echo -e "\033[97m$title\n\n"; echo $title >> songs/playlist.txt
ffmpeg -y -loglevel error -hide_banner -i songs/"${title}".wav -f u16le -acodec pcm_s16le -ac 2 -ar 48000 /tmp/snapfifo
clear; echo -e "\033[90mIn riproduzione:"; echo -e "\033[97m$title\n\n"; echo $title >> songs/playlist.txt
done