View previous topic :: View next topic |
Author |
Message |
loopx Advocate
Joined: 01 Apr 2005 Posts: 2787 Location: Belgium / Liège
|
Posted: Sat Jan 02, 2010 6:28 pm Post subject: [script] get des paramètres d'une URL avec Bash (résolu) |
|
|
Bonsoir,
J'aimerais, dans un script, pouvoir récupérer un paramètre d'une URL, en bash ... Seulement, suis un peu nul avec "sed" .. peut être que vous pourriez m'aider. Voici un exemple d'URL :
http://www.youtube.com/watch?v=lbZJXrtr0YY&feature=topvideos
et j'aimerais récupérer le paramèttre "v=" ..
Une idée ? _________________ Mon MediaWiki perso : http://pix-mania.dyndns.org
Last edited by loopx on Sun Jan 03, 2010 2:54 pm; edited 1 time in total |
|
Back to top |
|
|
loopx Advocate
Joined: 01 Apr 2005 Posts: 2787 Location: Belgium / Liège
|
Posted: Sat Jan 02, 2010 6:53 pm Post subject: |
|
|
tiens, c'est étrange, ffmpeg dans un script, il fait rien lors de la convertion, peut être lié à la sortie standard ou quoi ...
Code: | Output #0, avi, to 'tatata.avi':
Stream #0.0: Video: libxvid, yuv420p, 720x480 [PAR 1:1 DAR 3:2], q=2-31, 200 kb/s, 29.92 tbn, 29.92 tbc
Stream #0.1: Audio: libmp3lame, 44100 Hz, stereo, s16, 192 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding
|
puis le script bloque _________________ Mon MediaWiki perso : http://pix-mania.dyndns.org |
|
Back to top |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Sat Jan 02, 2010 7:57 pm Post subject: |
|
|
En général, on montre ce qu'on a fait jusque Ãlà avant d'appeller au secours! Là on n'a rien!
Soit!
Code: | TT='http://www.youtube.com/watch?v=lbZJXrtr0YY&feature=topvideos'
TT=${TT##*[?&]v=}
echo ${TT%%&*=*}
lbZJXrtr0YY
|
Après, tu peux aussi le faire avec sed, voir, awk, mais si c'est suffisant, autant se cantonner à ça. _________________ The End of the Internet! |
|
Back to top |
|
|
Magic Banana Veteran
Joined: 13 Dec 2005 Posts: 1912 Location: Belo Horizonte, Minas Gerais, Brasil
|
Posted: Sat Jan 02, 2010 8:44 pm Post subject: |
|
|
truc wrote: | En général, on montre ce qu'on a fait jusque Ãlà avant d'appeller au secours! Là on n'a rien!
Soit!
Code: | TT='http://www.youtube.com/watch?v=lbZJXrtr0YY&feature=topvideos'
TT=${TT##*[?&]v=}
echo ${TT%%&*=*}
lbZJXrtr0YY
|
Après, tu peux aussi le faire avec sed, voir, awk, mais si c'est suffisant, autant se cantonner à ça. |
J'allais proposer la même chose mais truc m'a grillé.
Je plussoie donc et ajoute que tu peux utiliser un 'while read' si tu veux, comme le fait sed par défaut, appliquer ce traitement sur une liste d'URL (ici lue depuis l'entrée standard) :
Code: | while read TT
do
parameter=${TT##*[?&]v=}
parameter=${parameter%%&*=*}
done |
|
|
Back to top |
|
|
mrpouet Retired Dev
Joined: 29 Jul 2008 Posts: 87 Location: Bordeaux, France
|
Posted: Sat Jan 02, 2010 9:05 pm Post subject: |
|
|
Je ne suis pas un pro de sed, mais quelque chose comme çà devrait faire l'affaire :
Code: |
echo 'http://www.youtube.com/watch?v=lbZJXrtr0YY&feature=topvideos' | sed -e 's#http://[a-zA-Z0-9\./?][a-zA-Z0-9\./?]*=##'
|
PS: celà dit je trouve la solution de truc plus simple |
|
Back to top |
|
|
loopx Advocate
Joined: 01 Apr 2005 Posts: 2787 Location: Belgium / Liège
|
Posted: Sun Jan 03, 2010 1:10 am Post subject: |
|
|
oops, arf, déso, j'y ai pas pensé, here is what you need :
Code: |
#!/bin/bash
# Last update by loopx on 20100102
# Description : this script is used to download (using 'youtube-dl' and directly convert and rename video from youtube.com
##########################################################################################################################
TMP=/tmp/youtube.$$
#Some check before start
check() {
#check for "youtube-dl"
which youtube-dl > /dev/null
if [ "$?" != "0" ]; then
echo "ERROR> The 'youtube-dl' script seem to be not present on your system."
echo "ERROR> Please, install it and try again ..."
echo "ERROR> To install on Gentoo Linux : 'emerge youtube-dl'"
echo "ERROR> To install on Ubuntu Linux : 'apt-get install youtube-dl'"
exit 1
fi
#check for "ffmpeg" command
which ffmpeg > /dev/null
if [ "$?" != "0" ]; then
echo "ERROR> The 'ffmpeg' command line seem to be not present on your system."
echo "ERROR> Please, install it and try again ..."
echo "ERROR> To install on Gentoo Linux : 'emerge ffmpeg (with right USE flags ...)'"
echo "ERROR> To install on Ubuntu Linux : 'apt-get install ffmpeg'"
exit 1
fi
#check for the first parameter (URL)
if [ "$1" == "" ]; then
echo "ERROR> URL not specified in first parameter, abording ..."
exit 2
fi
}
#just print the help
print_help() {
echo "HELP> This script download, convert and rename a youtube's video to an AVI video"
echo "HELP> Syntax :"
echo "HELP> youtube <URL> [FINAL_NAME_WITHOUT_EXTENSION]"
}
#MAIN######################################
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
print_help
exit 0
fi
check $1
#create temporary folder
mkdir $TMP
cd $TMP
echo "> Downloading video from youtube.com (using 'youtube-dl')..."
#download the video using "youtube-dl" and "-b" parameter for "best quality"
youtube-dl -b $1
#select the final name
if [ "$2" != "" ]; then
NAME="$2.avi"
else
NAME="tatata.avi"
fi
echo "> Converting into XVID-MP4/MP3 ..."
#there is only one video in the temporary folder, and we don't know the final name and extention, so use "*"
ffmpeg -i * -acodec libmp3lame -ab 192k -vcodec libxvid -qscale 2 -vtag XVID -f avi $NAME
#acodec : mp3
#ab : audio bitrate
#vcodec : XVID
#qscale : qualité video = 2 (less is better but huge video size)
#-f : output format (container?) = avi
#move the final video from temporary folder to home folder
mv $NAME ~/
echo rm -r $TMP
echo "> Done"
|
C'est pas encore fini, ai été boire du vin avant de le finir ... Donc, en paramètre (le premier), je récupère l'URL et j'aimerais, pour nomer la vidéo final, récupérer le nom de la video qui se trouve dans l'url ... soit, une suite de caractère qui représente une clé primaire ? C'est pas bien grave, mais ce serais plus propre ^^
Merci d'avance je testerais bientot, demain je pense _________________ Mon MediaWiki perso : http://pix-mania.dyndns.org |
|
Back to top |
|
|
loopx Advocate
Joined: 01 Apr 2005 Posts: 2787 Location: Belgium / Liège
|
Posted: Sun Jan 03, 2010 2:17 pm Post subject: |
|
|
Pour ffmpeg, le script qui s'arrete, je pense que c'est ffmpeg qui crash (defunc) ... arf arf arf, devrais pas le faire sur la kubuntu en principe. _________________ Mon MediaWiki perso : http://pix-mania.dyndns.org |
|
Back to top |
|
|
loopx Advocate
Joined: 01 Apr 2005 Posts: 2787 Location: Belgium / Liège
|
Posted: Sun Jan 03, 2010 2:38 pm Post subject: |
|
|
truc wrote: | En général, on montre ce qu'on a fait jusque Ãlà avant d'appeller au secours! Là on n'a rien!
Soit!
Code: | TT='http://www.youtube.com/watch?v=lbZJXrtr0YY&feature=topvideos'
TT=${TT##*[?&]v=}
echo ${TT%%&*=*}
lbZJXrtr0YY
|
Après, tu peux aussi le faire avec sed, voir, awk, mais si c'est suffisant, autant se cantonner à ça. |
Eh ben, respect! Je vais probablement devoir me réveiller une deuxième fois pour comprendre, mais en tout cas, ca fonctionne, merci _________________ Mon MediaWiki perso : http://pix-mania.dyndns.org |
|
Back to top |
|
|
Magic Banana Veteran
Joined: 13 Dec 2005 Posts: 1912 Location: Belo Horizonte, Minas Gerais, Brasil
|
Posted: Sun Jan 03, 2010 8:52 pm Post subject: |
|
|
loopx wrote: | Eh ben, respect! Je vais probablement devoir me réveiller une deuxième fois pour comprendre, mais en tout cas, ca fonctionne, merci |
Pour t'aider à comprendre, rien de mieux que l'excellent ABS traduit en français. Voilà le chapitre qui t'intéresse. |
|
Back to top |
|
|
loopx Advocate
Joined: 01 Apr 2005 Posts: 2787 Location: Belgium / Liège
|
Posted: Mon Jan 04, 2010 5:16 pm Post subject: |
|
|
Magic Banana wrote: | loopx wrote: | Eh ben, respect! Je vais probablement devoir me réveiller une deuxième fois pour comprendre, mais en tout cas, ca fonctionne, merci |
Pour t'aider à comprendre, rien de mieux que l'excellent ABS traduit en français. Voilà le chapitre qui t'intéresse. |
Intéressant, merci _________________ Mon MediaWiki perso : http://pix-mania.dyndns.org |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|