[xiph-cvs] cvs commit: shout-python shout.c example.py

Brendan brendan at xiph.org
Wed Jul 9 14:56:44 PDT 2003



brendan     03/07/09 17:56:43

  Modified:    .        shout.c example.py
  Log:
  Declare libshout constants in module. Protocols and formats are omitted
  because 'mp3' and 'http' are easier to use in python than SHOUT_FORMAT_MP3
  et al.
  Example updated.

Revision  Changes    Path
1.2       +23 -5     shout-python/shout.c

Index: shout.c
===================================================================
RCS file: /usr/local/cvsroot/shout-python/shout.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -p -u -r1.1 -r1.2
--- shout.c	3 Jul 2003 17:30:45 -0000	1.1
+++ shout.c	9 Jul 2003 21:56:43 -0000	1.2
@@ -4,7 +4,7 @@
  * This code is licensed under the GNU LGPL. See COPYING in the source
  * distribution for details.
  *
- * $Id: shout.c,v 1.1 2003/07/03 17:30:45 brendan Exp $
+ * $Id: shout.c,v 1.2 2003/07/09 21:56:43 brendan Exp $
  */
 
 #include <Python.h>
@@ -90,7 +90,9 @@ static char docstring[] = "Shout library
   " audio_info - dictionary of stream audio parameters, for YP information.\n"
   "              Useful keys include \"bitrate\" (in kbps), \"samplerate\"\n"
   "              (in Hz), \"channels\" and \"quality\" (vorbis encoding\n"
-  "              quality. All dictionary values should be strings.\n"
+  "              quality. All dictionary values should be strings. The known\n"
+  "              keys are defined as the SHOUT_AI_* constants, but any other\n"
+  "              will be passed along to the server as well.\n"
   "   dumpfile - file name to record stream to on server (not supported on\n"
   "              all servers)\n"
   "      agent - for customizing the HTTP user-agent header\n\n";
@@ -196,15 +198,31 @@ static PyMethodDef ShoutObjectMethods[] 
 };
 
 void initshout(void) {
-  PyObject* methods;
+  PyObject* mod;
   PyObject* dict;
 
   ShoutObject_Type.ob_type = &PyType_Type;
 
-  methods = Py_InitModule3("shout", ShoutMethods, docstring);
-  dict = PyModule_GetDict(methods);
+  mod = Py_InitModule3("shout", ShoutMethods, docstring);
+  dict = PyModule_GetDict(mod);
   ShoutError = PyErr_NewException("shout.ShoutException", NULL, NULL);
   PyDict_SetItemString(dict, "ShoutException", ShoutError);
+
+  PyModule_AddIntConstant(mod, "SHOUTERR_SUCCESS", SHOUTERR_SUCCESS);
+  PyModule_AddIntConstant(mod, "SHOUTERR_INSANE", SHOUTERR_INSANE);
+  PyModule_AddIntConstant(mod, "SHOUTERR_NOCONNECT", SHOUTERR_NOCONNECT);
+  PyModule_AddIntConstant(mod, "SHOUTERR_NOLOGIN", SHOUTERR_NOLOGIN);
+  PyModule_AddIntConstant(mod, "SHOUTERR_SOCKET", SHOUTERR_SOCKET);
+  PyModule_AddIntConstant(mod, "SHOUTERR_MALLOC", SHOUTERR_MALLOC);
+  PyModule_AddIntConstant(mod, "SHOUTERR_METADATA", SHOUTERR_METADATA);
+  PyModule_AddIntConstant(mod, "SHOUTERR_CONNECTED", SHOUTERR_CONNECTED);
+  PyModule_AddIntConstant(mod, "SHOUTERR_UNCONNECTED", SHOUTERR_UNCONNECTED);
+  PyModule_AddIntConstant(mod, "SHOUTERR_UNSUPPORTED", SHOUTERR_UNSUPPORTED);
+
+  PyModule_AddStringConstant(mod, "SHOUT_AI_BITRATE", SHOUT_AI_BITRATE);
+  PyModule_AddStringConstant(mod, "SHOUT_AI_SAMPLERATE", SHOUT_AI_SAMPLERATE);
+  PyModule_AddStringConstant(mod, "SHOUT_AI_CHANNELS", SHOUT_AI_CHANNELS);
+  PyModule_AddStringConstant(mod, "SHOUT_AI_QUALITY", SHOUT_AI_QUALITY);
 }
 
 /* -- shout module methods -- */

<p><p>1.2       +3 -2      shout-python/example.py

Index: example.py
===================================================================
RCS file: /usr/local/cvsroot/shout-python/example.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -p -u -r1.1 -r1.2
--- example.py	3 Jul 2003 17:30:44 -0000	1.1
+++ example.py	9 Jul 2003 21:56:43 -0000	1.2
@@ -21,13 +21,14 @@ s.mount = "/pyshout"
 # s.url = ''
 # s.public = 0 | 1
 # s.audio_info = { 'key': 'val', ... }
-#  (keys are 'bitrate', 'samplerate', 'channels', 'quality')
+#  (keys are shout.SHOUT_AI_BITRATE, shout.SHOUT_AI_SAMPLERATE,
+#   shout.SHOUT_AI_CHANNELS, shout.SHOUT_AI_QUALITY)
 
 s.open()
 
 total = 0
 st = time.time()
-for fa in sys.argv[0:]:
+for fa in sys.argv[1:]:
     print "opening file %s" % fa
     f = open(fa)
     s.set_metadata({'song': fa})

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list