From ce68992aed768d3b586f7b5e4e948b27232b64cb Mon Sep 17 00:00:00 2001 From: Pavel Kirilin <win10@list.ru> Date: Tue, 19 May 2020 15:08:06 +0400 Subject: [PATCH] Added playerctl crawler. Signed-off-by: Pavel Kirilin <win10@list.ru> --- .gitignore | 1 + Makefile | 4 ++ assets/message.ass | 4 +- assets/scripts/playerctl_loader.sh | 64 ++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 assets/scripts/playerctl_loader.sh diff --git a/.gitignore b/.gitignore index 3063948..17d03fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ assets/backgrounds/* assets/sounds/* +radio/* diff --git a/Makefile b/Makefile index bd13d21..8b40b8a 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,10 @@ concat: preview: @mpv "${OUT_DIR}/final.mp4" + +playerctl_load: + @sh ${ASSETS_DIR}/scripts/playerctl_loader.sh + cleanup: @echo "Cleaning up outdir" @rm -rfv "${OUT_DIR}" diff --git a/assets/message.ass b/assets/message.ass index 8cc7da8..e38f5b0 100644 --- a/assets/message.ass +++ b/assets/message.ass @@ -17,5 +17,5 @@ Style: Bottom,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100, [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text -Dialogue: 0,0:00:03.00,0:00:12.00,Center,,0,0,0,,{\pos(190,160)}{\fad(1200, 0)} The stream is offline. {\fad}{\pos} -Dialogue: 0,0:00:05.00,0:00:12.00,Center,,0,0,0,,{\pos(190,200)}{\fad(1200, 0)} Stay tuned on http://s3rius.ddns.net/{\fad}{\pos} +Dialogue: 0,0:00:03.00,0:00:16.00,Center,,0,0,0,,{\pos(190,160)}{\fad(1200, 0)} The stream is online. {\fad}{\pos} +Dialogue: 0,0:00:05.00,0:00:16.00,Center,,0,0,0,,{\pos(190,200)}{\fad(1200, 0)} Listen on http://s3rius.ddns.net/{\fad}{\pos} diff --git a/assets/scripts/playerctl_loader.sh b/assets/scripts/playerctl_loader.sh new file mode 100644 index 0000000..963bda4 --- /dev/null +++ b/assets/scripts/playerctl_loader.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +if [[ !( $(playerctl status) ) ]]; then + echo "Run tuijam or some other player" + exit 1 +fi + +if [[ $(playerctl status) != "Playing" ]]; then + playerctl next +fi + +workdir="$(mktemp -d playlist-XXXXXX)" +pushd "$workdir" + +index=0 + +playlist_title="playlist" + +function cleanup_and_exit() { + rm -fv "current.mp3" "bg.png" "cover.jpg" "cover.png" + ffmpeg -f concat -safe 0 -i concat -c copy "${playlist_title}.mp4" + rm -fv concat + popd +} + +trap "cleanup_and_exit" EXIT + +while [[ "$(playerctl status)" = "Playing" ]];do + title="$(playerctl metadata xesam:title)" + artist="$(playerctl metadata xesam:artist)" + artUrl="$(playerctl metadata mpris:artUrl)" + url="$(playerctl metadata xesam:url)" + + if [[ "${index}" = "0" ]];then + playlist_title="Radio ${artist} - ${title}" + fi + + # Downloading song and album cover + wget "${url}" -O "current.mp3" + wget "${artUrl}" -O "cover.jpg" + + # Processing background + music_bg test "cover.jpg" --output "cover.png" + + convert -background '#0008' -gravity center \ + -fill white -size 800x70 caption:"${artist} - ${title}" \ + "cover.png" +swap -gravity south -geometry +0+200 -composite "bg.png" + + rm -fv "cover.jpg" "cover.png" + + ffmpeg -r 1 -loop 1 -framerate 1 -i "bg.png" -i "current.mp3" \ + -map 0:v -map 1:a \ + -c:v libxvid -pix_fmt yuv420p \ + -c:a aac \ + -vf "scale=-1:720,pad=ceil(iw/2)*2:ceil(ih/2)*2" \ + -shortest -y -strict -2 "${index}.mp4" + + echo "file '${index}.mp4'" >> concat + + index=$((index + 1)) + if ! (playerctl next);then + break + fi +done -- GitLab