CopyLaRadio sbotc zenyta command
This commit is contained in:
parent
02cb67d2b5
commit
72a6a7bef6
|
@ -0,0 +1,38 @@
|
|||
#!/bin/bash
|
||||
ARTIST=$1
|
||||
SONG=$2
|
||||
|
||||
echo '
|
||||
__
|
||||
__ _____ ______________ ___ __ / /
|
||||
/ / / / _ \/ ___/ ___/ __ `/ / / / / /
|
||||
/ /_/ / __(__ |__ ) /_/ / /_/ / /_/
|
||||
\__, /\___/____/____/\__,_/\__, / (_)
|
||||
/____/ /____/
|
||||
|
||||
identifying'
|
||||
echo $ARTIST
|
||||
echo $SONG
|
||||
# WHOAMI=$(sbotc whoami | jq -r .id)
|
||||
# sbotc query.read '{"query":[{"$filter":{"value":{"author": "'"$WHOAMI"'", "content":{"type":"zenyta"}}}}]}' | jq -r .value?.content?.text | tail -n 1
|
||||
# this command is reagularly is run in cron_MINUTE.sh so your stations then take cae to miammiam.sh your youtube search
|
||||
#
|
||||
# We must transform that input information into link to copy from
|
||||
# We are going to use youtube-dl dry run.
|
||||
|
||||
# http://golly.sourceforge.net/
|
||||
# [@Christian Bundy](@+oaWWDs8g73EZFUMfW37R/ULtFEjwKN/DczvdYihjbU=.ed25519)
|
||||
# thanks for your security hole spotting..
|
||||
# I know that this could become a badly used account...
|
||||
|
||||
# It will be introduced as a learning account. (being able to regenerate).
|
||||
# the above algo rythm is calibrated on the "game of life" mixed with angel problem solution.
|
||||
# will it produce "speeders shapings" i hope...
|
||||
# %EDlmG9QW2U2wYnvIIKf//GrDxYoQWGL/Jk3Nw0obi8M=.sha256
|
||||
# http://golly.sourceforge.net/
|
||||
mysearch="$ARTIST $SONG"
|
||||
youtube-dl --default-search ytsearch1: --download-archive /home/pi/.ytdl.list --continue --no-overwrites --metadata-from-title "$artist - %(title)s" --add-metadata --embed-thumbnail --ignore-errors -f m4a --extract-audio -o "/home/pi/.zen/music/${artist}/${song}/%(id)s.%(title)s.%(uploader_id)s.%(ext)s" "$mysearch" >> /tmp/youtube-dl.log 2>&1
|
||||
|
||||
# Finaly this is made directly....
|
||||
# so it is not put on ipfs... zenTag must attach contracts...
|
||||
|
Binary file not shown.
|
@ -0,0 +1,99 @@
|
|||
#!/bin/bash
|
||||
### _shell.sh's are used ONLY with pi USER (change it if you want)
|
||||
###
|
||||
MY_PATH="`dirname \"$0\"`" # relative
|
||||
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
||||
|
||||
# Clean /tmp/ytdl.list
|
||||
#echo > /tmp/ytdl.list
|
||||
|
||||
|
||||
## Accents and different languages needed to create encodings. on 8, 16, 32, 64 bits ...
|
||||
# it is a big mess/// so we remove accent until someone take care of making it better. TODO???
|
||||
#
|
||||
function replace_accents (){
|
||||
INPUT="$1"
|
||||
declare -a acc
|
||||
declare -a noa
|
||||
acc=('$' 'è' 'ê' 'é' 'À' 'Á' 'Â' 'Ã' 'Ä' 'Å' 'Æ' 'Ç' 'È' 'É' 'Ê' 'Ë' 'Ì' 'Í' 'Î' 'Ï' 'Ð' 'Ñ' 'Ò' 'Ó' 'Ô' 'Õ' 'Ö' 'Ø' 'Ù' 'Ú' 'Û' 'Ü' 'Ý' 'ß' 'à' 'á' 'â' 'ã' 'ä' 'å' 'æ' 'ç' 'è' 'é' 'ê' 'ë' 'ì' 'í' 'î' 'ï' 'ñ' 'ò' 'ó' 'ô' 'õ' 'ö' 'ø' 'ù' 'ú' 'û' 'ü' 'ý' 'ÿ' 'Ā' 'ā' 'Ă' 'ă' 'Ą' 'ą' 'Ć' 'ć' 'Ĉ' 'ĉ' 'Ċ' 'ċ' 'Č' 'č' 'Ď' 'ď' 'Đ' 'đ' 'Ē' 'ē' 'Ĕ' 'ĕ' 'Ė' 'ė' 'Ę' 'ę' 'Ě' 'ě' 'Ĝ' 'ĝ' 'Ğ' 'ğ' 'Ġ' 'ġ' 'Ģ' 'ģ' 'Ĥ' 'ĥ' 'Ħ' 'ħ' 'Ĩ' 'ĩ' 'Ī' 'ī' 'Ĭ' 'ĭ' 'Į' 'į' 'İ' 'ı' 'IJ' 'ij' 'Ĵ' 'ĵ' 'Ķ' 'ķ' 'Ĺ' 'ĺ' 'Ļ' 'ļ' 'Ľ' 'ľ' 'Ŀ' 'ŀ' 'Ł' 'ł' 'Ń' 'ń' 'Ņ' 'ņ' 'Ň' 'ň' 'ʼn' 'Ō' 'ō' 'Ŏ' 'ŏ' 'Ő' 'ő' 'Œ' 'œ' 'Ŕ' 'ŕ' 'Ŗ' 'ŗ' 'Ř' 'ř' 'Ś' 'ś' 'Ŝ' 'ŝ' 'Ş' 'ş' 'Š' 'š' 'Ţ' 'ţ' 'Ť' 'ť' 'Ŧ' 'ŧ' 'Ũ' 'ũ' 'Ū' 'ū' 'Ŭ' 'ŭ' 'Ů' 'ů' 'Ű' 'ű' 'Ų' 'ų' 'Ŵ' 'ŵ' 'Ŷ' 'ŷ' 'Ÿ' 'Ź' 'ź' 'Ż' 'ż' 'Ž' 'ž' 'ſ' 'ƒ' 'Ơ' 'ơ' 'Ư' 'ư' 'Ǎ' 'ǎ' 'Ǐ' 'ǐ' 'Ǒ' 'ǒ' 'Ǔ' 'ǔ' 'Ǖ' 'ǖ' 'Ǘ' 'ǘ' 'Ǚ' 'ǚ' 'Ǜ' 'ǜ' 'Ǻ' 'ǻ' 'Ǽ' 'ǽ' 'Ǿ' 'ǿ');
|
||||
noa=('S' 'e' 'e' 'e' 'A' 'A' 'A' 'A' 'A' 'A' 'AE' 'C' 'E' 'E' 'E' 'E' 'I' 'I' 'I' 'I' 'D' 'N' 'O' 'O' 'O' 'O' 'O' 'O' 'U' 'U' 'U' 'U' 'Y' 's' 'a' 'a' 'a' 'a' 'a' 'a' 'ae' 'c' 'e' 'e' 'e' 'e' 'i' 'i' 'i' 'i' 'n' 'o' 'o' 'o' 'o' 'o' 'o' 'u' 'u' 'u' 'u' 'y' 'y' 'A' 'a' 'A' 'a' 'A' 'a' 'C' 'c' 'C' 'c' 'C' 'c' 'C' 'c' 'D' 'd' 'D' 'd' 'E' 'e' 'E' 'e' 'E' 'e' 'E' 'e' 'E' 'e' 'G' 'g' 'G' 'g' 'G' 'g' 'G' 'g' 'H' 'h' 'H' 'h' 'I' 'i' 'I' 'i' 'I' 'i' 'I' 'i' 'I' 'i' 'IJ' 'ij' 'J' 'j' 'K' 'k' 'L' 'l' 'L' 'l' 'L' 'l' 'L' 'l' 'l' 'l' 'N' 'n' 'N' 'n' 'N' 'n' 'n' 'O' 'o' 'O' 'o' 'O' 'o' 'OE' 'oe' 'R' 'r' 'R' 'r' 'R' 'r' 'S' 's' 'S' 's' 'S' 's' 'S' 's' 'T' 't' 'T' 't' 'T' 't' 'U' 'u' 'U' 'u' 'U' 'u' 'U' 'u' 'U' 'u' 'U' 'u' 'W' 'w' 'Y' 'y' 'Y' 'Z' 'z' 'Z' 'z' 'Z' 'z' 's' 'f' 'O' 'o' 'U' 'u' 'A' 'a' 'I' 'i' 'O' 'o' 'U' 'u' 'U' 'u' 'U' 'u' 'U' 'u' 'U' 'u' 'A' 'a' 'AE' 'ae' 'O' 'o');
|
||||
|
||||
OUTPUT=""
|
||||
i=0
|
||||
length=${#INPUT}
|
||||
while [[ $i -lt $length ]]; do./zen/_CopyLaRadio/copy.sh:
|
||||
char=${INPUT:$i:1};
|
||||
#echo $i:$char
|
||||
j=0
|
||||
for letter in "${acc[@]}"
|
||||
do
|
||||
if [[ "$letter" == "$char" ]]; then
|
||||
char="${noa[$j]}"
|
||||
fi
|
||||
((j++))
|
||||
done
|
||||
((i++))
|
||||
OUTPUT=$OUTPUT$char
|
||||
done
|
||||
echo $OUTPUT
|
||||
}
|
||||
|
||||
# BASH CAN MAKE INFINTE LOOP LOOKING FOR A NEW LINE APPEERING IN A FILE.
|
||||
# this technique can transmit FIFO command between process
|
||||
# This code is from www.copylaradio.com and RUN youtube-dl search and copy from the use of a button.
|
||||
#
|
||||
tail -fn 1 /tmp/ytdl.list | while read -r line
|
||||
do
|
||||
#################################################
|
||||
radio=$(echo $line | cut -d "|" -f 1)
|
||||
artist=$(echo $line | cut -d "|" -f 2)
|
||||
song=$(echo $line | cut -d "|" -f 3)
|
||||
echo "######## $radio ########" >> /tmp/youtube-dl.log 2>&1
|
||||
echo $(date) >> /tmp/youtube-dl.log 2>&1
|
||||
echo ${line} >> /tmp/youtube-dl.log 2>&1
|
||||
|
||||
#################################################
|
||||
# YOUTUBE-DL SEARCH & COPY : "radio|artist|song"
|
||||
if [[ "$artist" != "" && "$song" != "" && "$radio" != "" && "$radio" != "$song" && "$radio" != "undefined" && "$artist" != "$song" ]]; then
|
||||
mkdir -p "/home/pi/.zen/music/${artist}/${song}"
|
||||
$MY_PATH/parle.sh "Démarrage Enregistrement $radio."
|
||||
$MY_PATH/parle.sh "$artist" "en-US"
|
||||
$MY_PATH/parle.sh "$song" "en-US"
|
||||
echo "Copy youtube-dl: $artist | $song ($radio)" >> /tmp/youtube-dl.log 2>&1
|
||||
# Clean search string
|
||||
mysearch=$(replace_accents "$artist $song")
|
||||
if [[ "$mysearch" == "" ]]; then ~/parle.sh "Aucune recherche reçue!"; continue; fi
|
||||
# Search & Download bestaudio from 1st video result (ogg / opus / m4a): MEDIUM CPU
|
||||
# OPTION: --embed-thumbnail --metadata-from-title "%(artist)s - %(title)s" --add-metadata
|
||||
youtube-dl --default-search ytsearch1: --download-archive /home/pi/.ytdl.list --continue --no-overwrites --metadata-from-title "$artist - %(title)s" --add-metadata --embed-thumbnail --ignore-errors -f m4a --extract-audio -o "/home/pi/music/${artist}/${song}/%(id)s.%(title)s.%(uploader_id)s.%(ext)s" "$mysearch" >> /tmp/youtube-dl.log 2>&1
|
||||
# TODO: CHOOSE --metadata-from-title "$artist - %(title)s" or --metadata-from-title %(title)s"
|
||||
# Update mpd playlist
|
||||
curl -b "currenthost=Default;player_backend=mpd" http://localhost/albums.php?rebuild=yes > /dev/null
|
||||
$MY_PATH/parle.sh "Enregistrement $radio terminé!"
|
||||
######################################################
|
||||
#### COPY LINK : "CopyLaRadio||https://link2media.url"
|
||||
elif [[ "$radio" != "" && "$artist" == "" && "$song" != "" ]]; then
|
||||
# LINK COPY
|
||||
$MY_PATH/parle.sh "Copie du lien!"
|
||||
echo "Copy LINK: $song" >> /tmp/youtube-dl.log 2>&1
|
||||
mkdir -p /home/pi/download/
|
||||
youtube-dl --download-archive /home/pi/.ytdl.list --continue --no-overwrites --embed-thumbnail --metadata-from-title "%(artist)s - %(title)s" --add-metadata -o "/home/pi/download/%(title)s.%(ext)s" "$song" >> /tmp/youtube-dl.log 2>&1
|
||||
$MY_PATH/parle.sh "Enregistrement du lien terminé!"
|
||||
######################################################
|
||||
#### COPY LINK : "radio||"
|
||||
elif [[ "$radio" != "" && "$artist" == "" && "$song" == "" ]]; then
|
||||
# EXTERNAL PARSER: ADD SCRAPERS IN ./libradio
|
||||
$MY_PATH/parle.sh "Recherche RADIO ${radio}"
|
||||
echo "External search: ${radio}" >> /tmp/youtube-dl.log 2>&1
|
||||
if [[ -f $MY_PATH/libradio/${radio}.php ]]; then
|
||||
$MY_PATH/parle.sh "Module existant"
|
||||
php "$MY_PATH/libradio/${radio}.php"
|
||||
else
|
||||
$MY_PATH/parle.sh "Aucun module de décodage pour cette radio."
|
||||
fi
|
||||
#### NOTHING GOOD
|
||||
else
|
||||
$MY_PATH/parle.sh "Rien à copier"
|
||||
fi
|
||||
done
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
# May run on ElementaryOS try it and tell us @Attilax!
|
||||
sudo add-apt-repository ppa:obsproject/obs-studio
|
||||
sudo apt update
|
||||
sudo apt install obs-studio -y
|
||||
sudo apt install simplescreenrecorder mixxx geany -y
|
||||
|
||||
sudo add-apt-repository ppa:peek-developers/stable
|
||||
sudo apt update
|
||||
sudo apt install peek
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/*
|
||||
################################################################################
|
||||
# FROM CopyLaRadio MODULE_TEMPLATE_0.1
|
||||
# Author: Fred (support@qo-op.com)
|
||||
# Date: 2019 04 01
|
||||
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
||||
################################################################################
|
||||
*/
|
||||
// VARS INIT
|
||||
$obj=$title=$artist=$emission=$ERR=$ontheair="";
|
||||
///////////////////////////
|
||||
// SET TO 1 DURING DEVLT
|
||||
$debug=0;
|
||||
///////////////////////////
|
||||
// MODULE RADIO PARAMETERS
|
||||
///////////////////////////
|
||||
$RADIO = "FIP Electro";
|
||||
$referer = "https://www.fip.fr/";
|
||||
$radiourl = 'https://www.fip.fr/latest/api/graphql?operationName=Now&variables=%7B%22bannerPreset%22%3A%221400x1400%22%2C%22stationId%22%3A74%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%229551487ee4a6810ec4afa35e70dd1c204fa84db3519d39eb3176e5a3a8b0e482%22%7D%7D';
|
||||
|
||||
// TWEEK CLIENT & REFERER
|
||||
ini_set('user_agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0');
|
||||
$ctx = stream_context_create(array(
|
||||
'http' => array(
|
||||
'header'=>array("Referer: ".$referer.PHP_EOL),
|
||||
'timeout' => 5
|
||||
)
|
||||
)
|
||||
);
|
||||
///////////////////////////
|
||||
// LOAD RADIO PAGE INTO PARSER
|
||||
$ontheair = file_get_contents($radiourl); // JSON CONTENT
|
||||
$ontheair = utf8_encode($ontheair);
|
||||
$obj = json_decode($ontheair, true);
|
||||
|
||||
|
||||
// GET TRACK INFO: ADAPT WITH DATA STRUCTURE
|
||||
// ADPAPT HERE
|
||||
$current = $obj['data']['now']['playing_item'];
|
||||
// GET TRACK INFO
|
||||
if ( $current ) {
|
||||
// ADPAPT HERE
|
||||
$artist = ucwords(strtolower($current['title']));
|
||||
$title = ucwords(strtolower($current['subtitle']));
|
||||
|
||||
if ( $debug != 0 ) $ERR .= "\nTITRE = ".print_r($title, true);
|
||||
if ( $debug != 0 ) $ERR .= "\nARTISTE = ".print_r($artist, true);
|
||||
|
||||
}
|
||||
///////////////////////////
|
||||
// PREPARE COPY COMMAND
|
||||
$cmd = $RADIO.'|'.$artist.'|'.$title;
|
||||
|
||||
///////////////////////////
|
||||
// DEBUG OR PROD
|
||||
if($debug == 1) {
|
||||
print_r($obj);
|
||||
print_r($cmd);
|
||||
} else {
|
||||
if( $artist != "" && $title != "" ) {
|
||||
// TODO Clean strings?!
|
||||
if (! exec('grep '.escapeshellarg($cmd).' /tmp/ytdl.list')) {
|
||||
file_put_contents("/tmp/youtube-dl.log", "ARTIST: ".$artist.". SONG: ".$title, FILE_APPEND);
|
||||
file_put_contents("/tmp/ytdl.list","$cmd\n", FILE_APPEND);
|
||||
} else {
|
||||
file_put_contents("/tmp/youtube-dl.log", "ALREADY THERE!", FILE_APPEND);
|
||||
file_put_contents("/tmp/ytdl.list","||".PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
} else {
|
||||
file_put_contents("/tmp/youtube-dl.log", "NO TRACK. TRY PODCAST!", FILE_APPEND);
|
||||
file_put_contents("/tmp/ytdl.list","||".PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -0,0 +1 @@
|
|||
radionova.php
|
|
@ -0,0 +1 @@
|
|||
FIP autour de llectro.php
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/*
|
||||
################################################################################
|
||||
# FROM CopyLaRadio MODULE_TEMPLATE_0.1
|
||||
# Author: Fred (support@qo-op.com)
|
||||
# Date: 2019 04 01
|
||||
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
||||
################################################################################
|
||||
*/
|
||||
// VARS INIT
|
||||
$obj=$title=$artist=$emission=$ERR=$ontheair="";
|
||||
///////////////////////////
|
||||
// SET TO 1 DURING DEVLT
|
||||
$debug=0;
|
||||
///////////////////////////
|
||||
// MODULE RADIO PARAMETERS
|
||||
///////////////////////////
|
||||
$RADIO = "RADIO NOVA";
|
||||
$referer = "http://www.nova.fr/";
|
||||
$radiourl = 'http://www.nova.fr/radio/19577/player';
|
||||
|
||||
// TWEEK CLIENT & REFERER
|
||||
ini_set('user_agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0');
|
||||
$ctx = stream_context_create(array(
|
||||
'http' => array(
|
||||
'header'=>array("Referer: ".$referer.PHP_EOL),
|
||||
'timeout' => 5
|
||||
)
|
||||
)
|
||||
);
|
||||
///////////////////////////
|
||||
// LOAD RADIO PAGE INTO PARSER
|
||||
$ontheair = file_get_contents($radiourl); // JSON CONTENT
|
||||
$ontheair = utf8_encode($ontheair);
|
||||
$obj = json_decode($ontheair, true);
|
||||
|
||||
|
||||
// GET TRACK INFO: ADAPT WITH DATA STRUCTURE
|
||||
// ADPAPT HERE
|
||||
if ( $obj['currentTrack'] ) {
|
||||
|
||||
// ADPAPT HERE
|
||||
$title = ucwords(strtolower($obj['currentTrack']['title']));
|
||||
$artist = ucwords(strtolower($obj['currentTrack']['artist']));
|
||||
|
||||
if ( $debug != 0 ) $ERR .= "\nTITRE = ".print_r($title, true);
|
||||
if ( $debug != 0 ) $ERR .= "\nARTISTE = ".print_r($artist, true);
|
||||
|
||||
}
|
||||
///////////////////////////
|
||||
// PREPARE COPY COMMAND
|
||||
$cmd = $RADIO.'|'.$artist.'|'.$title;
|
||||
|
||||
///////////////////////////
|
||||
// DEBUG OR PROD
|
||||
if($debug == 1) {
|
||||
print_r($obj);
|
||||
print_r($cmd);
|
||||
} else {
|
||||
if( $artist != "" && $title != "" ) {
|
||||
// TODO Clean strings?!
|
||||
if (! exec('grep '.escapeshellarg($cmd).' /tmp/ytdl.list')) {
|
||||
file_put_contents("/tmp/youtube-dl.log", "ARTIST: ".$artist.". SONG: ".$title, FILE_APPEND);
|
||||
file_put_contents("/tmp/ytdl.list","$cmd\n", FILE_APPEND);
|
||||
} else {
|
||||
file_put_contents("/tmp/youtube-dl.log", "ALREADY THERE!", FILE_APPEND);
|
||||
file_put_contents("/tmp/ytdl.list","||".PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
} else {
|
||||
file_put_contents("/tmp/youtube-dl.log", "NO TRACK. TRY PODCAST!", FILE_APPEND);
|
||||
file_put_contents("/tmp/ytdl.list","||".PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
f=$(echo "$1" | sed 's/ //g' )
|
||||
echo "parle.sh: $1 | $2 = $f" >> /tmp/youtube-dl.log 2>&1
|
||||
if [[ "$2" == "" ]]; then
|
||||
lang="fr-FR"
|
||||
else
|
||||
lang="en-US"
|
||||
fi
|
||||
if [[ ! -f "/tmp/$lang_${f}.wav" ]]; then
|
||||
pico2wave -l $lang -w /tmp/$lang_${f}.wav "$1"
|
||||
fi
|
||||
aplay -q /tmp/$lang_${f}.wav
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
# John Horton Conway
|
||||
sbotc publish '{"type":"zenyta","text":"'"$1"'"}'
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
sbotc publish '{"type":"zenyta","text":"'"$1"'"}'
|
|
@ -0,0 +1,212 @@
|
|||
#!/bin/bash
|
||||
# BUTTONS GPIO NUMBERS FOR PHAT BEAT
|
||||
# https://pinout.xyz/pinout/phat_beat#
|
||||
# ADD TO /etc/local for autostart
|
||||
#
|
||||
ONOFF=12
|
||||
VOLUP=16
|
||||
VOLDO=26
|
||||
BCK=13
|
||||
PLAY=6
|
||||
FWD=5
|
||||
|
||||
# ADD YOUR DEFAULT RADIO STREAM / PLAYLIST HERE - TRACK INFORMATION FOR RECORDING ;)
|
||||
PLAYLIST="/home/pi/playlists/default.m3u"
|
||||
|
||||
function trim() {
|
||||
local var="$*"
|
||||
# remove slashes
|
||||
var=$(echo "$var" | sed 's/\// /g')
|
||||
var=${var//[^a-zA-Z0-9_\. ]/}
|
||||
# remove leading whitespace characters
|
||||
var="${var#"${var%%[![:space:]]*}"}"
|
||||
# remove trailing whitespace characters
|
||||
var="${var%"${var##*[![:space:]]}"}"
|
||||
|
||||
echo -n "$var"
|
||||
}
|
||||
|
||||
function button() {
|
||||
pin=$1
|
||||
gpio -g mode $pin in # make sure pin is configured as an input
|
||||
gpio -g mode $pin up # enable pull-up resistor
|
||||
boucle=0
|
||||
|
||||
while :; do
|
||||
gpio -g wfi $pin falling # wait for a button action
|
||||
sleep 0.2
|
||||
echo $pin
|
||||
while [[ $(gpio -g read $pin) -eq 0 ]]
|
||||
do
|
||||
aplay bip.wav
|
||||
sleep 0.5 # COUNT 1/2 SECOND PRESSED
|
||||
boucle=$(bc -l <<< "$boucle + 1")
|
||||
done
|
||||
if [[ $boucle -gt 0 ]]; then
|
||||
echo "LP-$pin-$boucle"
|
||||
fi
|
||||
boucle=0
|
||||
done
|
||||
}
|
||||
|
||||
boucle=0
|
||||
|
||||
# --- main loop ---
|
||||
while :; do
|
||||
read numbut
|
||||
|
||||
# WHAT IS ON AIR
|
||||
watch="$(mpc | head -1):"
|
||||
|
||||
# EXTRACT ($radio :) $artist - $song
|
||||
radio=$(echo "$watch" | cut -d ":" -f 1 | xargs)
|
||||
if [[ "$radio" != "$watch" && $radio != "volume" && $radio != "http" ]]; then RADIO="$radio"; else radio="$watch"; RADIO=""; fi
|
||||
play=$(echo "$watch" | cut -d ":" -f 2)
|
||||
artist=$(echo "$play" | cut -d "-" -f 1)
|
||||
artist=$(trim "$artist")
|
||||
song=$(echo "$play" | cut -d "-" -f 2)
|
||||
song=$(trim "$song")
|
||||
if [[ "$song" == "" ]]; then
|
||||
song=$(echo "$play" | cut -d " " -f 2)
|
||||
song=$(trim "$song")
|
||||
fi
|
||||
|
||||
# TODO: ADAPT BEHAVIOUR TO EACH RADIO STREAM
|
||||
# NOVA RADIO PATCH
|
||||
if [[ "$radio" == "Nova zz" ]]; then
|
||||
artist=""
|
||||
song=""
|
||||
fi
|
||||
|
||||
echo "(CLICK $numbut) $RADIO: $artist / $song"
|
||||
|
||||
case "$numbut" in
|
||||
$ONOFF)
|
||||
echo "REC"
|
||||
# BUTTON QUICK RELEASE
|
||||
if [[ $(gpio -g read $ONOFF) -eq 1 ]]; then
|
||||
# RECORD STREAMING SONG::GENERIC
|
||||
if [[ "$RADIO" != "" && "$artist" != "" && "$song" != "" && "$artist" != "$song" ]]; then
|
||||
what=$(grep "$RADIO|$artist|$song" /tmp/ytdl.list)
|
||||
if [[ "$what" == "" ]]; then
|
||||
~/parle.sh "Enregistrement ajouté."
|
||||
echo "$RADIO|$artist|$song" >> /tmp/ytdl.list
|
||||
else
|
||||
~/parle.sh "Enregistrement déjà existant!"
|
||||
fi
|
||||
elif [[ "$artist" == "$song" ]]; then
|
||||
~/parle.sh "Enregistrement $radio"
|
||||
# USE COPY & MODULE FIFO
|
||||
echo "$radio||" >> /tmp/ytdl.list # TODO REMOVE
|
||||
else
|
||||
~/parle.sh "Podcast ou Fichier local. Enregistrement inopérant."
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
LP-$ONOFF-*)
|
||||
# LONG PRESS TRACK IDENTIFICATION
|
||||
playing=$(mpc | head -1 | cut -d ":" -f 1 | cut -d "/" -f 1 | xargs)
|
||||
playing=$(trim "$playing")
|
||||
~/parle.sh "$playing"
|
||||
if [[ "$RADIO" != "" && "$artist" != "" && "$song" != "" && "$artist" != "$song" ]]; then
|
||||
~/parle.sh "$artist - $song"
|
||||
fi
|
||||
;;
|
||||
$PLAY)
|
||||
echo "PLAY"
|
||||
if [[ $(gpio -g read $PLAY) -eq 1 ]]; then
|
||||
mpc toggle
|
||||
fi
|
||||
;;
|
||||
LP-$PLAY-*)
|
||||
sec=$(echo "$numbut" | cut -d "-" -f 3)
|
||||
case "$sec" in
|
||||
1)
|
||||
# 1SEC
|
||||
# Check if USB drive connected
|
||||
if [[ -b /dev/sda1 ]]; then
|
||||
~/parle.sh "Synchronisation musique sur clé U S B. Veuillez patienter"
|
||||
sudo mount /dev/sda1 /mnt
|
||||
sudo mkdir -p /mnt/CopyLaRadio
|
||||
sudo rsync -rtgoDv /home/pi/music/ /mnt/CopyLaRadio
|
||||
sudo umount /dev/sda1
|
||||
~/parle.sh "Transfert terminé. Vous pouvez débrancher votre clé..."
|
||||
else
|
||||
# STOP MUSIC
|
||||
~/parle.sh "STOP"
|
||||
mpc stop
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
# 2SEC = CHANGE MODE SHUFFLE LOCAL / DEFAULT PLAYLIST
|
||||
if [[ "$RADIO" != "" && "$mode" == "" ]]; then
|
||||
mode="LOCAL"
|
||||
~/parle.sh "Lecture musique locale"
|
||||
mpc clear
|
||||
mpc listall | mpc add
|
||||
mpc shuffle
|
||||
~/parle.sh "Aléatoire"
|
||||
mpc play
|
||||
else
|
||||
mode=""
|
||||
mpc clear
|
||||
mpc load default
|
||||
~/parle.sh "Lecture liste par défaut"
|
||||
mpc play
|
||||
fi
|
||||
;;
|
||||
3)
|
||||
# 3 SEC = HALT SYSTEM
|
||||
~/parle.sh "Arrêt RAIQUE MACHINE"
|
||||
sudo halt
|
||||
;;
|
||||
*)
|
||||
# > 3 SEC = REBOOT SYSTEM
|
||||
~/parle.sh "Redémarrage RAIQUE MACHINE"
|
||||
sudo reboot
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
$BCK)
|
||||
echo "BCK"
|
||||
mpc -q prev
|
||||
;;
|
||||
$FWD)
|
||||
echo "FWD"
|
||||
mpc -q next
|
||||
;;
|
||||
$VOLUP)
|
||||
echo "VOLUP"
|
||||
if [[ $(gpio -g read $VOLUP) -eq 1 ]]; then
|
||||
mpc -q volume +10
|
||||
vol=$(mpc volume | cut -f 2 -d ":")
|
||||
vol=$(trim "$vol")
|
||||
if [ "$vol" == "100%" ]; then ~/parle.sh "VOLUME MAXIMUM"; fi
|
||||
fi
|
||||
;;
|
||||
LP-$VOLUP-*)
|
||||
sec=$(echo "$numbut" | cut -d "-" -f 3)
|
||||
sec=+$(bc -l <<< "$sec * 10")
|
||||
mpc -q volume $sec
|
||||
;;
|
||||
$VOLDO)
|
||||
echo "VOLDO"
|
||||
if [[ $(gpio -g read $VOLDO) -eq 1 ]]; then
|
||||
mpc -q volume -10
|
||||
vol=$(mpc volume | cut -f 2 -d ":")
|
||||
vol=$(trim "$vol")
|
||||
if [ "$vol" == "0%" ]; then ~/parle.sh "VOLUME MINIMUM"; fi
|
||||
fi
|
||||
;;
|
||||
LP-$VOLDO-*)
|
||||
sec=$(echo "$numbut" | cut -d "-" -f 3)
|
||||
sec=-$(bc -l <<< "$sec * 10")
|
||||
mpc -q volume $sec
|
||||
;;
|
||||
*)
|
||||
echo $numbut
|
||||
;;
|
||||
esac
|
||||
|
||||
done < <( button $ONOFF & button $VOLUP & button $VOLDO & button $BCK & button $PLAY & button $FWD & ) # buttons on GPIOs to monitor
|
||||
|
Loading…
Reference in New Issue