G1sms/_CopyLaRadio/copy.sh

93 lines
5.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
source $MY_PATH/../.install/.GPATH
# Clean /tmp/ytdl.list
#echo > /tmp/ytdl.list
function replace_accents (){
INPUT="$1"
declare -a acc
declare -a noa
acc=('$' 'è' 'ê' 'é' 'À' 'Á' 'Â' 'Ã' 'Ä' 'Å' 'Æ' 'Ç' 'È' 'É' 'Ê' 'Ë' 'Ì' 'Í' 'Î' 'Ï' 'Ð' 'Ñ' 'Ò' 'Ó' 'Ô' 'Õ' 'Ö' 'Ø' 'Ù' 'Ú' 'Û' 'Ü' 'Ý' 'ß' 'à' 'á' 'â' 'ã' 'ä' 'å' 'æ' 'ç' 'è' 'é' 'ê' 'ë' 'ì' 'í' 'î' 'ï' 'ñ' 'ò' 'ó' 'ô' 'õ' 'ö' 'ø' 'ù' 'ú' 'û' 'ü' 'ý' 'ÿ' 'Ā' 'ā' 'Ă' 'ă' 'Ą' 'ą' 'Ć' 'ć' 'Ĉ' 'ĉ' 'Ċ' 'ċ' 'Č' 'č' 'Ď' 'ď' 'Đ' 'đ' 'Ē' 'ē' 'Ĕ' 'ĕ' 'Ė' 'ė' 'Ę' 'ę' 'Ě' 'ě' 'Ĝ' 'ĝ' 'Ğ' 'ğ' 'Ġ' 'ġ' 'Ģ' 'ģ' 'Ĥ' 'ĥ' 'Ħ' 'ħ' 'Ĩ' 'ĩ' 'Ī' 'ī' 'Ĭ' 'ĭ' 'Į' 'į' 'İ' 'ı' 'IJ' 'ij' 'Ĵ' 'ĵ' 'Ķ' 'ķ' 'Ĺ' 'ĺ' 'Ļ' 'ļ' 'Ľ' 'ľ' 'Ŀ' 'ŀ' 'Ł' 'ł' 'Ń' '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' '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
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
}
# SCAN NEW LINE IN NEW RECORD LIST AND RUN youtube-dl search and copy
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/music/${artist}/${song}"
~/parle.sh "Démarrage Enregistrement $radio."
~/parle.sh "$artist" "en-US"
~/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
~/parle.sh "Enregistrement $radio terminé!"
######################################################
#### COPY LINK : "CopyLaRadio||https://link2media.url"
elif [[ "$radio" != "" && "$artist" == "" && "$song" != "" ]]; then
# LINK COPY
~/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
~/parle.sh "Enregistrement du lien terminé!"
######################################################
#### COPY LINK : "radio||"
elif [[ "$radio" != "" && "$artist" == "" && "$song" == "" ]]; then
# EXTERNAL PARSER: ADD SCRAPERS IN ./libradio
~/parle.sh "Recherche RADIO ${radio}"
echo "External search: ${radio}" >> /tmp/youtube-dl.log 2>&1
if [[ -f $GPATH/_CopyLaRadio/libradio/${radio}.php ]]; then
~/parle.sh "Module existant"
php "$GPATH/_CopyLaRadio/libradio/${radio}.php"
else
~/parle.sh "Aucun module de décodage pour cette radio."
fi
#### NOTHING GOOD
else
~/parle.sh "Rien à copier"
fi
done