[weboob] [PATCH 1/1] Let user choose his Stream to use from Radio instance. Close #1291

Thomas Lecavelier thomas at lecavelier.name
Wed Aug 14 09:48:39 CEST 2013


From: Thomas Lecavelier <thomas-weboob at lecavelier.name>


Signed-off-by: Thomas Lecavelier <thomas-weboob at lecavelier.name>
---
 man/radioob.1                          |    2 +-
 weboob/applications/radioob/radioob.py |   19 ++++++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/man/radioob.1 b/man/radioob.1
index e7d8cb8..b86ee54 100644
--- a/man/radioob.1
+++ b/man/radioob.1
@@ -26,7 +26,7 @@ Console application allowing to search for web radio stations, listen to them an
 .br
 Get information about a radio.
 .TP
-\fBplay\fR \fIID\fR
+\fBplay\fR \fIID\fR [stream_id]
 .br
 Play a radio with a found player.
 .TP
diff --git a/weboob/applications/radioob/radioob.py b/weboob/applications/radioob/radioob.py
index 8e38529..b47c5d0 100644
--- a/weboob/applications/radioob/radioob.py
+++ b/weboob/applications/radioob/radioob.py
@@ -73,19 +73,24 @@ class Radioob(ReplApplication):
         if len(args) == 2:
             return self._complete_object()
 
-    def do_play(self, _id):
+    def do_play(self, line):
         """
-        play ID
+        play ID [stream_id]
 
-        Play a radio with a found player.
+        Play a radio with a found player (optionnaly specify the wanted stream).
         """
+        _id, _stream_id = self.parse_command_args(line, 2, 1)
         if not _id:
             print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('play', short=True)
             return 2
+        try:
+            _stream_id = int(_stream_id)
+        except ValueError:
+            _stream_id = 0
 
         radio = self.get_object(_id, 'get_radio', ['streams'])
         if not radio:
-            print >>sys.stderr, 'Radio not found:', _id
+            print >>sys.stderr, 'Radio REALLY not found:', _id
             return 1
         try:
             player_name = self.config.get('media_player')
@@ -93,9 +98,9 @@ class Radioob(ReplApplication):
             if not player_name:
                 self.logger.debug(u'You can set the media_player key to the player you prefer in the radioob '
                                   'configuration file.')
-            self.player.play(radio.streams[0], player_name=player_name, player_args=media_player_args)
+            self.player.play(radio.streams[int(_stream_id)], player_name=player_name, player_args=media_player_args)
         except (InvalidMediaPlayer, MediaPlayerNotFound) as e:
-            print '%s\nRadio URL: %s' % (e, radio.streams[0].url)
+            print '%s\nRadio URL: %s' % (e, radio.streams[int(_stream_id)].url)
 
     def complete_info(self, text, line, *ignored):
         args = line.split(' ')
@@ -114,7 +119,7 @@ class Radioob(ReplApplication):
 
         radio = self.get_object(_id, 'get_radio', ['streams', 'current'])
         if not radio:
-            print >>sys.stderr, 'Radio not found:', _id
+            print >>sys.stderr, 'Radio not INFO found:', _id
             return 3
         self.format(radio)
 
-- 
1.7.10.2 (Apple Git-33)




More information about the weboob mailing list