<p>Ce script python permet d'écouter l'une des 7 stations de la radio BBC.</p><p>Il vous faut VLC d'installé et plus précisément avoir la commande cvlc disponible.</p><p>Il faut après téléchargement du fichier joint, le désarchivé :</p><p><code>$ tar -xvf radiolite.py.tar</code></p><p>Placez le script ou bon vous semble, par exemple dans un répertoire nommé scripts dans votre home :</p><p><code>$ mkdir ~/scripts<br></code><code>$ cp radiolite.py ~/scripts<br></code></p><p>Vous pouvez ajouter un alias à votre bashrc :</p><p><code>$ vim ~/.bashrc</code></p><p>Ajoutez la ligne :</p><p><code>alias radiolite="~/scripts/radiolite.py"</code></p><p>Rechargez votre bashrc :</p><p><code>$ . ~/.bashrc</code></p><p>Vous pouvez maintenant lancer radiolite de n'importe où dans votre terminal.</p><p>Il est possible de rajouter des radios à la suite de celles existantes :</p><p><code>&nbsp;&nbsp;&nbsp; radio8 = Radio('Ma nouvelle radio','URL de la nouvelle radio')</code></p><p>Bonne utilisation !!</p><p><code>#!/usr/bin/python<br># _*_ coding: utf-8 _*_<br>#<br># fichier radiolite.py<br># permet d'écouter les stations de la BBC en ligne de commande avec VLC<br><br># import<br>import os<br>import subprocess<br><br># test si vlc-nox est installé<br># /usr/bin/cvlc<br>if not os.path.exists("/usr/bin/cvlc"):<br>&nbsp;&nbsp; &nbsp;print "l'éxécutable \"cvlc\" n'a pas été trouvé, installez le paquet \"vlc-nox\" ou \"VLC\""<br>else:<br>&nbsp;&nbsp; &nbsp;# variable<br>&nbsp;&nbsp; &nbsp;myList = []<br><br>&nbsp;&nbsp; &nbsp;# création d'une classe<br>&nbsp;&nbsp; &nbsp;class Radio(object):<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;def __init__(self,name,url):<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self._name = name<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self._url = url<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# ajout l'objet ma liste<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;myList.append(self)<br><br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;def getName(self):<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return self._name<br><br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;def getUrl(self):<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return self._url<br><br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# méthode écouter<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;def startLearn(self):<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print self.getName()<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# command = "cvlc " + self.getUrl()<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# os.system(command)<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# print command<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;p=subprocess.Popen(['cvlc', self.getUrl(), '&gt;', '/dev/null', '2&gt;&amp;1'], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr= subprocess.PIPE)<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# print p.pid<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;endSubProcess = 0<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;while not endSubProcess:<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;base = raw_input('Appuyer sur une touche pour arrêter la station\n')<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if base == "":<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print "Arrêt de la station\n"<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# terminer le processus p<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;p.terminate()<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;endSubProcess = 1<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;displayRadio()<br><br>&nbsp;&nbsp; &nbsp;# instanciation des différentes radios<br>&nbsp;&nbsp; &nbsp;radio1 = Radio("BBC 1","http://www.bbc.co.uk/radio/listen/live/r1.asx")<br>&nbsp;&nbsp; &nbsp;radio2 = Radio('BBC 2','http://www.bbc.co.uk/radio/listen/live/r2.asx')<br>&nbsp;&nbsp; &nbsp;radio3 = Radio('BBC 3','http://www.bbc.co.uk/radio/listen/live/r3.asx')<br>&nbsp;&nbsp; &nbsp;radio4 = Radio('BBC 4','http://www.bbc.co.uk/radio/listen/live/r4.asx')<br>&nbsp;&nbsp; &nbsp;radio5 = Radio('BBC 5','http://www.bbc.co.uk/radio/listen/live/r5.asx')<br>&nbsp;&nbsp; &nbsp;radio6 = Radio('BBC 6','http://www.bbc.co.uk/radio/listen/live/r6.asx')<br>&nbsp;&nbsp; &nbsp;radio7 = Radio('BBC 7','http://www.bbc.co.uk/radio/listen/live/r7.asx')<br><br>&nbsp;&nbsp; &nbsp;# affichage de la liste de radios<br>&nbsp;&nbsp; &nbsp;def displayRadio():<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;j = 0<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print "********************************"<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print "*&nbsp; Liste des radios de la BBC&nbsp; *"<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print "********************************"<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for i in myList:<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;j += 1<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print "%d - %s" % (j,i.getName())<br><br>&nbsp;&nbsp; &nbsp;# appel de la fonction displayRadio<br>&nbsp;&nbsp; &nbsp;displayRadio()<br><br>&nbsp;&nbsp; &nbsp;# select case<br>&nbsp;&nbsp; &nbsp;end = 0<br>&nbsp;&nbsp; &nbsp;while not end:<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;base = raw_input('Choisissez votre radio (q pour quitter) :')<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#i = int(base) # exemple de transtypage en python<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if base == "1":<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;radio1.startLearn()<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;elif base == "2":<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;radio2.startLearn()<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;elif base == "3":<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;radio3.startLearn()<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;elif base == "4":<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;radio4.startLearn()<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;elif base == "5":<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;radio5.startLearn()<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;elif base == "6":<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;radio6.startLearn()<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;elif base == "7":<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;radio7.startLearn()<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;elif base =="q":<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print "Merci d'utiliser RadioLite"<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end = 1<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;elif base =="":<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;displayRadio()<br><br># notre configuration de vim pour ce fichier<br># vim: ts=4 sw=4 expandtab</code></p>