Skip to content

Commit

Permalink
added: addStreamInfo python binding
Browse files Browse the repository at this point in the history
this allows settings streamdetails from plugins, i.e. to the media
flags. see the pydocs for syntax. closes #8982
  • Loading branch information
spiff committed Mar 25, 2012
1 parent 435c433 commit 2415d89
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions xbmc/interfaces/python/xbmcmodule/listitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}
};
Expand Down

0 comments on commit 2415d89

Please sign in to comment.