Permalink
Browse files

Merge pull request #144 from cptspiff/streamdetails

added: addStreamInfo python binding
  • Loading branch information...
2 parents 1d39bd9 + 2415d89 commit 2be41992a39da0d0762f06a04a5ded4faad7ef66 Arne Morten Kvarving committed Mar 26, 2012
Showing with 117 additions and 0 deletions.
  1. +117 −0 xbmc/interfaces/python/xbmcmodule/listitem.cpp
@@ -610,6 +610,122 @@ namespace PYXBMC
return Py_None;
}
+ PyDoc_STRVAR(addStreamInfo__doc__,
+ "addStreamInfo(type, values) -- Add a stream with details.\n"
+ "\n"
+ "type : string - type of stream(video/audio/subtitle).\n"
+ "values : dictionary - pairs of { label: value }.\n"
+ "\n"
+ "Video Values:\n"
+ " codec : string (h264)\n"
+ " aspect : float (1.78)\n"
+ " width : integer (1280)\n"
+ " height : integer (720)\n"
+ " duration : integer (seconds)\n"
+ "\n"
+ "Audio Values:\n"
+ " codec : string (dts)\n"
+ " language : string (en)\n"
+ " channels : integer (2)\n"
+ "\n"
+ "Subtitle Values:\n"
+ " language : string (en)\n"
+ "\n"
+ "example:\n"
+ " - self.list.getSelectedItem().addStreamInfo('video', { 'Codec': 'h264', 'Width' : 1280 })\n");
+
+ PyObject* ListItem_AddStreamInfo(ListItem *self, PyObject *args, PyObject *kwds)
+ {
+ static const char *keywords[] = { "type", "values", NULL };
+ char *cType = NULL;
+ PyObject *pValues = NULL;
+ if (!PyArg_ParseTupleAndKeywords(
+ args,
+ kwds,
+ (char*)"sO",
+ (char**)keywords,
+ &cType,
+ &pValues))
+ {
+ return NULL;
+ }
+ if (!PyObject_TypeCheck(pValues, &PyDict_Type))
+ {
+ PyErr_SetString(PyExc_TypeError, "values object should be of type Dict");
+ return NULL;
+ }
+ if (PyDict_Size(pValues) == 0)
+ {
+ PyErr_SetString(PyExc_ValueError, "Empty values dictionary");
+ return NULL;
+ }
+
+ PyObject *key, *value;
+ Py_ssize_t pos = 0;
+
+ PyXBMCGUILock();
+
+ CStdString tmp;
+ if (strcmpi(cType, "video") == 0)
+ {
+ CStreamDetailVideo* video = new CStreamDetailVideo;
+ while (PyDict_Next(pValues, &pos, &key, &value))
+ {
+ if (strcmpi(PyString_AsString(key), "codec") == 0)
+ {
+ if (!PyXBMCGetUnicodeString(video->m_strCodec, value, 1))
+ continue;
+ }
+ else if (strcmpi(PyString_AsString(key), "aspect") == 0)
+ video->m_fAspect = PyFloat_AsDouble(value);
+ else if (strcmpi(PyString_AsString(key), "width") == 0)
+ video->m_iWidth = PyInt_AsLong(value);
+ else if (strcmpi(PyString_AsString(key), "height") == 0)
+ video->m_iHeight = PyInt_AsLong(value);
+ else if (strcmpi(PyString_AsString(key), "duration") == 0)
+ video->m_iDuration = PyInt_AsLong(value);
+ }
+ self->item->GetVideoInfoTag()->m_streamDetails.AddStream(video);
+ }
+ else if (strcmpi(cType, "audio") == 0)
+ {
+ CStreamDetailAudio* audio = new CStreamDetailAudio;
+ while (PyDict_Next(pValues, &pos, &key, &value))
+ {
+ if (strcmpi(PyString_AsString(key), "codec") == 0)
+ {
+ if (!PyXBMCGetUnicodeString(audio->m_strCodec, value, 1))
+ continue;
+ }
+ else if (strcmpi(PyString_AsString(key), "language") == 0)
+ {
+ if (!PyXBMCGetUnicodeString(audio->m_strLanguage, value, 1))
+ continue;
+ }
+ else if (strcmpi(PyString_AsString(key), "channels") == 0)
+ audio ->m_iChannels = PyInt_AsLong(value);
+ }
+ self->item->GetVideoInfoTag()->m_streamDetails.AddStream(audio);
+ }
+ else if (strcmpi(cType, "subtitle") == 0)
+ {
+ CStreamDetailSubtitle* subtitle = new CStreamDetailSubtitle;
+ while (PyDict_Next(pValues, &pos, &key, &value))
+ {
+ if (strcmpi(PyString_AsString(key), "language") == 0)
+ {
+ if (!PyXBMCGetUnicodeString(subtitle->m_strLanguage, value, 1))
+ continue;
+ }
+ }
+ self->item->GetVideoInfoTag()->m_streamDetails.AddStream(subtitle);
+ }
+ PyXBMCGUIUnlock();
+
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
PyDoc_STRVAR(setProperty__doc__,
"setProperty(key, value) -- Sets a listitem property, similar to an infolabel.\n"
"\n"
@@ -858,6 +974,7 @@ namespace PYXBMC
{(char*)"setProperty", (PyCFunction)ListItem_SetProperty, METH_VARARGS|METH_KEYWORDS, setProperty__doc__},
{(char*)"getProperty", (PyCFunction)ListItem_GetProperty, METH_VARARGS|METH_KEYWORDS, getProperty__doc__},
{(char*)"addContextMenuItems", (PyCFunction)ListItem_AddContextMenuItems, METH_VARARGS|METH_KEYWORDS, addContextMenuItems__doc__},
+ {(char*)"addStreamInfo", (PyCFunction)ListItem_AddStreamInfo, METH_VARARGS|METH_KEYWORDS, addStreamInfo__doc__},
{(char*)"setPath" , (PyCFunction)ListItem_SetPath, METH_VARARGS|METH_KEYWORDS, setPath__doc__},
{NULL, NULL, 0, NULL}
};

0 comments on commit 2be4199

Please sign in to comment.