[CBLX] YouTube_to_MP3 Was: script wYTv - wget YT videos |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/carrefourblinux Archives
]
Didier, je mets pour toi et les autres le script youtube_to_mp3 en pj,
il utilise youtube-dl dont je mets le bin dans ~/bin
mais on peut modifier dans la config;
mon but etait de voir si le binaire de yt-dl.org fonctionne plus que celui
du pack installé sous pip de Ubuntu.
(j'ai une version qui fais la maj et une qui le fais pas intempestivement).
Aldo.
#!/bin/bash
#
# YouTube_to_MP3-script - orig. by L. Berger - modified ver. by O. La Rosa
# 2020.04.17
clear
## Inst. dir + YT base-URL + YT-DL binary name var
#InstRepo="/usr/local/bin/"
InstRepo="$HOME/bin/"
#YTDLName="youtube-dl"
YTDLName="yt-dl"
#YTBURL="http://youtu.be/"
YTBURL="http://www.youtube.com/watch?v="
#YTBURL="https://www.youtube.com/watch?v="
## Go !
echo "YouTube_to_MP3-script ! "
#echo "Positional parameters"
#echo '$0 = ' $0
#echo '$1 = ' $1
## Output
#OUTPUT="/home/${USER}/Music"
#OUTPUT="/home/${USER}/Musique"
#OUTPUT="/home/${USER}/Muziek"
#OUTPUT="/home/${USER}/Downloads"
OUTPUT="/home/${USER}/yt-dl"
mkdir -p $OUTPUT
echo "
Binary name & destination is : $InstRepo$YTDLName
YouTube download repository is : $OUTPUT "
echo " YT base URL (to download from) is : $YTBURL"
## Date
NOWSHORT=`date +%Y%m%d`
#http://man7.org/linux/man-pages/man1/date.1.html
#NOWSHORT=`date '+%Y%m%d%H%M%S'`
#NOWSHORT=`date '+%Y%m%d-%H%M%S'`
#NOWSHORT=`date '+%Y%m%d.%H%M%S'`
echo " Today : $NOWSHORT "
echo " "
## Download a full mix play list
## How to download YouTube playlist in Linux
## http://xmodulo.com/how-to-download-youtube-playlist-in-linux.html
## YT-DL(.org) bin installation
#sudo curl -L https://yt-dl.org/latest/youtube-dl -o $InstRepo$YTDLName
#curl -L https://yt-dl.org/latest/youtube-dl -o $InstRepo$YTDLName
#sudo chmod a+rx $InstRepo$YTDLName
#chmod a+rx $InstRepo$YTDLName
ls -l $InstRepo$YTDLName
echo " "
#read -p "Press a key to continue ... "
#clear
## Updating ...
#$InstRepo$YTDLName -U
echo " "
#read -p "Press a key to continue ... "
#clear
## Added --exec touch in place !!
## https://superuser.com/questions/731227/how-to-extract-the-filename-without-the-extension-from-a-full-path
#FILENAME=${1%.*}
# help ==================
if [ -z $1 ]; then
echo "Version `$YTDLName --version`"
# echo "Usage : $(basename $0) youtube_full_address (keep)"
echo "Usage : $(basename $0) youtube ID (11 chars) (keep)"
echo " If 'keep' is specified, it will keep a copy of the orig. files"
# echo "Example: youtube_to_mp3 https://www.youtube.com/watch?v=cFMnG4cSVJM"
# echo "Example: youtube_to_mp3 https://www.youtube.com/watch?v=cFMnG4cSVJM keep"
echo "Example: youtube_to_mp3 cFMnG4cSVJM"
echo "Example: youtube_to_mp3 cFMnG4cSVJM keep"
echo " "
exit 1
fi
# help ==================
echo "
---------------------------------------------------------------------------"
echo "Date is : $NOWSHORT"
echo "Making dir $NOWSHORT (if not exist) to store new files ..."
mkdir -p $OUTPUT/$NOWSHORT
#echo "--- $OUTPUT/$NOWSHORT ---"
echo "--- URL $YTBURL$1 @ $OUTPUT/$NOWSHORT ---"
echo " "
#read -p "Press a key to continue ... "
clear
echo "YouTube_to_MP3-script !
"
echo Downloading
echo and converting to
echo " $OUTPUT/$NOWSHORT"
echo "(Please note, file's date is NOT today : Search by file name.) "
echo ....... Busy .......
echo $FILENAME
cd $OUTPUT/$NOWSHORT
echo " "
#read -p "Press a key to continue ... "
#clear
## --audio-quality QUALITY Specify ffmpeg/avconv audio quality,
## Insert a value between 0 (better) and 9
if [ "$2" == "keep" ]; then
echo "Will keep source video ´$1´"
# $InstRepo$YTDLName --exec touch {} -i -x -k --audio-quality 0 --audio-format mp3 $1
# $InstRepo$YTDLName --exec touch {} -i -x -k --audio-quality 0 --audio-format mp3 $YTBURL$1
$InstRepo$YTDLName --exec touch {} -i -x -k --no-check-certificate --audio-quality 0 --audio-format mp3 $YTBURL$1
else
# $YTDLName --exec touch {} -i -x --audio-quality 0 --audio-format mp3 $1
# $YTDLName --exec touch {} -i -x --audio-quality 0 --audio-format mp3 $YTBURL$1
$YTDLName --exec touch {} -i -x --no-check-certificate --audio-quality 0 --audio-format mp3 $YTBURL$1
fi
echo "
---------------------------------------------------------------------------"
#touch $FILENAME".mp3"
cd $OUTPUT/$NOWSHORT
ls -lrt
echo " "
read -p "Press a key to continue / CTRL+C to quit now without reupdating youtube-dl ... "
#clear
echo "--- Updating youtube-dl (yt-dl) : Please type root / sudo pwd (if required) ---"
#sudo YTDLName --update
$InstRepo$YTDLName --update
echo "--- End updating youtube-dl ($InstRepo$YTDLName) ---"
echo "------ Done youtube_to_mp3 -----------------------------------------"
echo " "
## End of script !
exit
#!/bin/bash
#
# YouTube_to_MP3-script - orig. by L. Berger - modified ver. by O. La Rosa
# 2020.04.17
clear
## Inst. dir + YT base-URL + YT-DL binary name var
#InstRepo="/usr/local/bin/"
InstRepo="$HOME/bin/"
#YTDLName="youtube-dl"
YTDLName="yt-dl"
#YTBURL="http://youtu.be/"
#YTBURL="http://www.youtube.com/watch?v="
YTBURL="https://www.youtube.com/watch?v="
## Go !
echo "YouTube_to_MP3-script ! "
#echo "Positional parameters"
#echo '$0 = ' $0
#echo '$1 = ' $1
## Output
#OUTPUT="/home/${USER}/Music"
#OUTPUT="/home/${USER}/Musique"
#OUTPUT="/home/${USER}/Muziek"
#OUTPUT="/home/${USER}/Downloads"
OUTPUT="/home/${USER}/yt-dl"
mkdir -p $OUTPUT
echo "
Binary name & destination is : $InstRepo$YTDLName
YouTube download repository is : $OUTPUT "
echo " YT base URL (to download from) is : $YTBURL"
## Date
#NOWSHORT=`date +%Y%m%d`
#http://man7.org/linux/man-pages/man1/date.1.html
#NOWSHORT=`date '+%Y%m%d%H%M%S'`
#NOWSHORT=`date '+%Y%m%d-%H%M%S'`
NOWSHORT=`date '+%Y%m%d.%H%M%S'`
echo " Today : $NOWSHORT "
echo " "
## Download a full mix play list
## How to download YouTube playlist in Linux
## http://xmodulo.com/how-to-download-youtube-playlist-in-linux.html
## YT-DL(.org) bin installation
#sudo curl -L https://yt-dl.org/latest/youtube-dl -o $InstRepo$YTDLName
#curl -L https://yt-dl.org/latest/youtube-dl -o $InstRepo$YTDLName
#sudo chmod a+rx $InstRepo$YTDLName
#chmod a+rx $InstRepo$YTDLName
ls -l $InstRepo$YTDLName
echo " "
#read -p "Press a key to continue ... "
#clear
## Updating ...
#$InstRepo$YTDLName -U
echo " "
#read -p "Press a key to continue ... "
#clear
## Added --exec touch in place !!
## https://superuser.com/questions/731227/how-to-extract-the-filename-without-the-extension-from-a-full-path
#FILENAME=${1%.*}
# help ==================
if [ -z $1 ]; then
echo "Version `$YTDLName --version`"
# echo "Usage : $(basename $0) youtube_full_address (keep)"
echo "Usage : $(basename $0) youtube ID (11 chars) (keep)"
echo " If 'keep' is specified, it will keep a copy of the orig. files"
# echo "Example: youtube_to_mp3 https://www.youtube.com/watch?v=cFMnG4cSVJM"
# echo "Example: youtube_to_mp3 https://www.youtube.com/watch?v=cFMnG4cSVJM keep"
echo "Example: youtube_to_mp3 cFMnG4cSVJM"
echo "Example: youtube_to_mp3 cFMnG4cSVJM keep"
echo " "
exit 1
fi
# help ==================
echo "
---------------------------------------------------------------------------"
echo "Date is : $NOWSHORT"
echo "Making dir $NOWSHORT (if not exist) to store new files ..."
mkdir -p $OUTPUT/$NOWSHORT
#echo "--- $OUTPUT/$NOWSHORT ---"
echo "--- URL $YTBURL$1 @ $OUTPUT/$NOWSHORT ---"
echo " "
#read -p "Press a key to continue ... "
clear
echo "YouTube_to_MP3-script !
"
echo Downloading
echo and converting to
echo " $OUTPUT/$NOWSHORT"
echo "(Please note, file's date is NOT today : Search by file name.) "
echo ....... Busy .......
echo $FILENAME
cd $OUTPUT/$NOWSHORT
echo " "
#read -p "Press a key to continue ... "
#clear
## --audio-quality QUALITY Specify ffmpeg/avconv audio quality,
## Insert a value between 0 (better) and 9
if [ "$2" == "keep" ]; then
echo "Will keep source video ´$1´"
# $InstRepo$YTDLName --exec touch {} -i -x -k --audio-quality 0 --audio-format mp3 $1
# $InstRepo$YTDLName --exec touch {} -i -x -k --audio-quality 0 --audio-format mp3 $YTBURL$1
$InstRepo$YTDLName --exec touch {} -i -x -k --no-check-certificate --audio-quality 0 --audio-format mp3 $YTBURL$1
else
# $YTDLName --exec touch {} -i -x --audio-quality 0 --audio-format mp3 $1
# $YTDLName --exec touch {} -i -x --audio-quality 0 --audio-format mp3 $YTBURL$1
$YTDLName --exec touch {} -i -x --no-check-certificate --audio-quality 0 --audio-format mp3 $YTBURL$1
fi
echo "
---------------------------------------------------------------------------"
#touch $FILENAME".mp3"
cd $OUTPUT/$NOWSHORT
ls -lrt
echo " "
read -p "Press a key to continue / CTRL+C to quit now without reupdating youtube-dl ... "
#clear
echo "--- Updating youtube-dl (yt-dl) : Please type root / sudo pwd (if required) ---"
#sudo YTDLName --update
$InstRepo$YTDLName --update
echo "--- End updating youtube-dl ($InstRepo$YTDLName) ---"
echo "------ Done youtube_to_mp3 -----------------------------------------"
echo " "
## End of script !
exit