Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[script] get des paramètres d'une URL avec Bash (résolu)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
loopx
Advocate
Advocate


Joined: 01 Apr 2005
Posts: 2787
Location: Belgium / Liège

PostPosted: Sat Jan 02, 2010 6:28 pm    Post subject: [script] get des paramètres d'une URL avec Bash (résolu) Reply with quote

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
View user's profile Send private message
loopx
Advocate
Advocate


Joined: 01 Apr 2005
Posts: 2787
Location: Belgium / Liège

PostPosted: Sat Jan 02, 2010 6:53 pm    Post subject: Reply with quote

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 :o
_________________
Mon MediaWiki perso : http://pix-mania.dyndns.org
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Sat Jan 02, 2010 7:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Sat Jan 02, 2010 8:44 pm    Post subject: Reply with quote

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é. :twisted:

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
View user's profile Send private message
mrpouet
Retired Dev
Retired Dev


Joined: 29 Jul 2008
Posts: 87
Location: Bordeaux, France

PostPosted: Sat Jan 02, 2010 9:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
loopx
Advocate
Advocate


Joined: 01 Apr 2005
Posts: 2787
Location: Belgium / Liège

PostPosted: Sun Jan 03, 2010 1:10 am    Post subject: Reply with quote

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
View user's profile Send private message
loopx
Advocate
Advocate


Joined: 01 Apr 2005
Posts: 2787
Location: Belgium / Liège

PostPosted: Sun Jan 03, 2010 2:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
loopx
Advocate
Advocate


Joined: 01 Apr 2005
Posts: 2787
Location: Belgium / Liège

PostPosted: Sun Jan 03, 2010 2:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Sun Jan 03, 2010 8:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
loopx
Advocate
Advocate


Joined: 01 Apr 2005
Posts: 2787
Location: Belgium / Liège

PostPosted: Mon Jan 04, 2010 5:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French All times are GMT
Page 1 of 1

 
Jump to:  
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