如何将本地文件添加到 kodi 插件?
How can I add a local file to a kodi addon?
如何将本地文件添加到 kodi 插件?
在以下示例中,Internet 文件 (url='http://...') 有效。但是本地文件(url='file://...')没有。
import xbmc
import xbmcgui
import xbmcplugin
import xbmcaddon
import xbmcvfs
import sys
addon_handle = int(sys.argv[1])
xbmcplugin.setContent(addon_handle, 'songs')
#this works
xbmcplugin.addDirectoryItem(handle=addon_handle, url='http://www.noiseaddicts.com/samples_1w72b820/2537.mp3', listitem=xbmcgui.ListItem('internet_file'))
#this do not work
xbmcplugin.addDirectoryItem(handle=addon_handle, url='file://media/usb0/music/bn/local_file.mp3', listitem=xbmcgui.ListItem('local_file'))
xbmcplugin.endOfDirectory(addon_handle)
这应该是您的文件系统中没有任何前缀的绝对路径,例如 '/foo/bar/spam.mp4'
(*nix) 或 'c:\foo\bar\spam.mp4'
(Win)。我认为,网络文件系统也可以工作,对于它们你确实需要像 smb://
或 nfs://` 这样的前缀,但对于本地文件则不需要。
搜索了一段时间后,我找到了 Kodi 的 special://
协议:http://kodi.wiki/view/Special_protocol,我在这里引用:
The "Special Protocol" is Kodi's solution to platform dependent
directories. Common directory names are assigned a special://[name]
path which is passed around inside Kodi and then translated to the
platform specific path before the operating system sees it. This helps
keep most of the platform mess centralized in the code.
使用 special://
协议,下面的代码可以做到:
xbmcplugin.addDirectoryItem(handle=addon_handle,
url='special://home/bn/local_file.mp3',
listitem=xbmcgui.ListItem('local_file'))
如何将本地文件添加到 kodi 插件? 在以下示例中,Internet 文件 (url='http://...') 有效。但是本地文件(url='file://...')没有。
import xbmc
import xbmcgui
import xbmcplugin
import xbmcaddon
import xbmcvfs
import sys
addon_handle = int(sys.argv[1])
xbmcplugin.setContent(addon_handle, 'songs')
#this works
xbmcplugin.addDirectoryItem(handle=addon_handle, url='http://www.noiseaddicts.com/samples_1w72b820/2537.mp3', listitem=xbmcgui.ListItem('internet_file'))
#this do not work
xbmcplugin.addDirectoryItem(handle=addon_handle, url='file://media/usb0/music/bn/local_file.mp3', listitem=xbmcgui.ListItem('local_file'))
xbmcplugin.endOfDirectory(addon_handle)
这应该是您的文件系统中没有任何前缀的绝对路径,例如 '/foo/bar/spam.mp4'
(*nix) 或 'c:\foo\bar\spam.mp4'
(Win)。我认为,网络文件系统也可以工作,对于它们你确实需要像 smb://
或 nfs://` 这样的前缀,但对于本地文件则不需要。
搜索了一段时间后,我找到了 Kodi 的 special://
协议:http://kodi.wiki/view/Special_protocol,我在这里引用:
The "Special Protocol" is Kodi's solution to platform dependent directories. Common directory names are assigned a special://[name] path which is passed around inside Kodi and then translated to the platform specific path before the operating system sees it. This helps keep most of the platform mess centralized in the code.
使用 special://
协议,下面的代码可以做到:
xbmcplugin.addDirectoryItem(handle=addon_handle,
url='special://home/bn/local_file.mp3',
listitem=xbmcgui.ListItem('local_file'))