本文整理汇总了Python中xbmcswift2.ListItem.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python ListItem.from_dict方法的具体用法?Python ListItem.from_dict怎么用?Python ListItem.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xbmcswift2.ListItem
的用法示例。
在下文中一共展示了ListItem.from_dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: play
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def play(url):
resolved = ''
stream_url = ''
item = None
try:
import urlresolver
resolved = urlresolver.HostedMediaFile(url).resolve()
if not resolved or resolved == False or len(resolved) < 1:
resolved = urlresolver.resolve(url)
if resolved is None or len(resolved) < 1:
resolved = urlresolver.resolve(urllib.unquote(url))
if len(resolved) > 1:
plugin.notify(msg="PLAY {0}".format(resolved.partition('.')[-1]), title="URLRESOLVER", delay=1000)
plugin.set_resolved_url(resolved)
item = ListItem.from_dict(path=resolved)
item.add_stream_info('video', stream_values={})
item.set_is_playable(True)
return item
except:
resolved = ''
plugin.notify(msg="FAILED {0}".format(url.partition('.')[-1]), title="URLRESOLVER", delay=1000)
try:
import YDStreamExtractor
info = YDStreamExtractor.getVideoInfo(url, resolve_redirects=True)
resolved = info.streamURL()
for s in info.streams():
try:
stream_url = s['xbmc_url'].encode('utf-8', 'ignore')
xbmc.log(msg="**YOUTUBE-DL Stream found: {0}".format(stream_url))
except:
pass
if len(stream_url) > 1:
resolved = stream_url
if len(resolved) > 1:
plugin.notify(msg="Playing: {0}".format(resolved.partition('.')[-1]), title="YOUTUBE-DL", delay=1000)
plugin.set_resolved_url(resolved)
item = ListItem.from_dict(path=resolved)
item.add_stream_info('video', stream_values={})
item.set_is_playable(True)
return item
except:
plugin.notify(msg="Failed: {0}".format(resolved.partition('.')[-1]), title="YOUTUBE-DL", delay=1000)
if len(resolved) > 1:
plugin.set_resolved_url(resolved)
item = ListItem.from_dict(path=resolved)
return item
else:
plugin.set_resolved_url(url) #url)
#plugurl = 'plugin://plugin.video.live.streamspro/?url={0}'.format(urllib.quote_plus(url))
#item = ListItem.from_dict(path=plugurl)
#item.add_stream_info('video', stream_values={})
#item.set_is_playable(True)
#plugin.notify(msg="RESOLVE FAIL: {0}".format(url.split('.', 1)[-1]),title="Trying {0}".format(item.path.split('.', 1)[-1]), delay=2000)
return None
示例2: test_from_dict_props
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def test_from_dict_props(self):
dct = {
'properties': {'StartOffset': '256.4'},
}
item = ListItem.from_dict(**dct)
self.assertEqual(item.get_property('StartOffset'), '256.4')
dct = {
'properties': [('StartOffset', '256.4')],
}
item = ListItem.from_dict(**dct)
self.assertEqual(item.get_property('StartOffset'), '256.4')
示例3: interactive
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def interactive(plugin):
'''A run mode for the CLI that runs the plugin in a loop based on user
input.
'''
items = [item for item in once(plugin) if not item.get_played()]
parent_stack = [] # Keep track of parents so we can have a '..' option
selected_item = get_user_choice(items)
while selected_item is not None:
if parent_stack and selected_item == parent_stack[-1]:
# User selected the parent item, remove from list
parent_stack.pop()
else:
# User selected non parent item, add current url to parent stack
parent_stack.append(ListItem.from_dict(label='..',
path=plugin.request.url))
patch_plugin(plugin, selected_item.get_path())
# If we have parent items, include the top of the stack in the list
# item display
parent_item = None
if parent_stack:
parent_item = parent_stack[-1]
items = [item for item in once(plugin, parent_item=parent_item)
if not item.get_played()]
selected_item = get_user_choice(items)
示例4: episode
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def episode(name='', url=''):
waserror = False
linklist = []
if len(url) == '':
waserror = True
else:
html = DL(url)
litems = []
linklist = findvidlinks(html)
itemparent = None
if len(linklist) > 0:
for name, link in linklist:
itempath = plugin.url_for(play, url=link)
item = dict(label=name, label2=link, icon='DefaultFolder.png', thumbnail='DefaultFolder.png', path=itempath)
item.setdefault(item.keys()[0])
litems.append(item)
vitems = sortSourceItems(litems)
litems = []
for li in vitems:
item = ListItem.from_dict(**li)
item.set_is_playable(True)
item.set_info(type='video', info_labels={'Title': item.label, 'Plot': item.label2})
item.add_stream_info(stream_type='video', stream_values={})
litems.append(item)
else:
waserror = True
if waserror:
plugin.notify(title="ERROR No links: {0}".format(name), msg=url)
return []
return litems
示例5: test_from_dict
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def test_from_dict(self):
dct = {
'label': 'foo',
'label2': 'bar',
'icon': 'icon',
'thumbnail': 'thumbnail',
'path': 'plugin://my.plugin.id/',
'selected': True,
'info': {'title': 'My title'},
'info_type': 'pictures',
'properties': [('StartOffset', '256.4')],
'context_menu': [('label', 'action')],
'is_playable': True}
with patch.object(ListItem, 'set_info', spec=True) as mock_set_info:
item = ListItem.from_dict(**dct)
self.assertEqual(item.label, 'foo')
self.assertEqual(item.label2, 'bar')
self.assertEqual(item.icon, 'icon')
self.assertEqual(item.thumbnail, 'thumbnail')
self.assertEqual(item.path, 'plugin://my.plugin.id/')
self.assertEqual(item.selected, True)
mock_set_info.assert_called_with('pictures', {'title': 'My title'})
self.assertEqual(item.get_property('StartOffset'), '256.4')
self.assertEqual(item.get_context_menu_items(), [('label', 'action')])
self.assertEqual(item.get_property('isPlayable'), 'true')
self.assertEqual(item.is_folder, False)
示例6: play
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def play(self, videoId):
api = NetworkTenVideo()
media = api.get_media_for_video(videoId)
self.log.debug("Found media renditions for video: %s", repr(media.items))
if len(media.items):
# Blindly go for the highest bitrate for now.
# Later versions could include a customisable setting of which stream to use
media_sorted = sorted(media.items, key=lambda m: m.encodingRate, reverse=True)
media = media_sorted[0]
path = media.defaultURL
self.log.info("Using rendition: %s with url: %s" % (media, path))
else:
# Fallback to API FLVFullLength (e.g. for live streams)
media = api.get_fallback_media_for_video(videoId)
path = media.remoteUrl
self.log.info("Using fallback rendition: %s with url: %s" % (media, path))
if path.startswith("rtmp"):
path = path.replace("&mp4:", " playpath=mp4:")
path += " swfVfy=true swfUrl=%s pageUrl=%s" % (SWF_URL, PAGE_URL)
# Set the resolved url, and include media stream info
item = ListItem.from_dict(path=path)
item.add_stream_info(
"video", {"codec": media.videoCodec, "width": media.frameWidth, "height": media.frameHeight}
)
self.plugin.set_resolved_url(path)
示例7: play
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def play(self, videoId):
api = NetworkTenVideo()
media = api.get_media_for_video(videoId)
self.log.debug('Found media renditions for video: %s', repr(media))
if len(media):
# Blindly go for the highest bitrate for now.
# Later versions could include a customisable setting of which stream to use
media_sorted = sorted(media, key=lambda m: m.encodingRate, reverse=True)
media = media_sorted[0]
path = media.url
self.log.info('Using rendition: %s with url: %s' % (media, path))
else:
# Fallback to API FLVFullLength (e.g. for live streams)
media = api.get_fallback_media_for_video(videoId)
if media.remoteUrl:
path = media.remoteUrl
self.log.info('Using fallback rendition: %s with url: %s' % (media, path))
else:
# attempt to deal with DRM'd content by falling back to mobile HLS stream
path = "http://c.brightcove.com/services/mobile/streaming/index/master.m3u8?videoId=%s" % videoId
self.log.info('Using fallback rendition unavailable - falling back to mobile HLS stream: %s' % path)
if path.startswith('rtmp'):
path = path.replace('&mp4:', ' playpath=mp4:')
path += ' swfVfy=true swfUrl=%s pageUrl=%s' % (SWF_URL, PAGE_URL)
# Set the resolved url, and include media stream info
item = ListItem.from_dict(path=path)
item.add_stream_info('video', {'codec': media.videoCodec, 'width': media.frameWidth, 'height': media.frameHeight})
self.plugin.set_resolved_url(path)
示例8: playurl
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def playurl():
url = ''
url = plugin.keyboard(default='', heading='Video Page URL')
if url != '' and len(url) > 0:
item = ListItem.from_dict(path=plugin.url_for(endpoint=play, url=url))
item.set_is_playable(True)
item.set_info(type='video', info_labels={'Title': url, 'Plot': url})
item.add_stream_info(stream_type='video', stream_values={})
return play(url)
示例9: playfirst
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def playfirst(url=''):
idx = 0
if len(url) < 1:
return None
thispath = plugin.url_for(endpoint=play, url=url)
selItem = None
outtxt = "Not Found"
try:
for fitem in plugin.added_items:
if fitem.selected == True or fitem.path.find(thispath) != -1:
try:
plugin.set_resolved_url(fitem)
fitem.is_playable(True)
fitem.played(True)
except:
pass
selItem = fitem
plugin.notify(msg=selItem.label, title="Found item")
break
except:
selItem = None
if selItem is not None:
try:
selItem.set_is_playable(True)
selItem.set_played(was_played=True)
outtxt = selItem.label + " " + selItem.label2
except:
outtxt = str(repr(selItem))
plugin.notify(msg=outtxt, title=str(idx))
html = DL(url)
prefhost = ''
sourceslist = []
stext = plugin.get_setting('topSources')
if len(stext) < 1:
prefhost = 'thevideo'
else:
sourceslist = stext.split(',')
prefhost = sourceslist[0]
litems = []
linklist = findvidlinks(html, findhost=prefhost)
if len(linklist) > 0:
name, link = linklist[0]
itempath = plugin.url_for(play, url=link)
sitem = dict(label=name, label2=link, icon='DefaultFolder.png', thumbnail='DefaultFolder.png', path=itempath)
sitem.setdefault(sitem.keys()[0])
item = ListItem.from_dict(**sitem)
item.set_is_playable(True)
item.set_info(type='video', info_labels={'Title': item.label, 'Plot': item.label2})
item.add_stream_info(stream_type='video', stream_values={})
plugin.notify(msg=link, title=name)
# plugin.add_items([item])
item.set_played(was_played=True)
# plugin.add_items([plugin.set_resolved_url(link)])#.as_tuple())])
plugin.play_video(item)
return [plugin.set_resolved_url(item)]
示例10: makecatitem
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def makecatitem(name, link, removelink=False):
item = {}
ctxitem = {}
itempath = plugin.url_for(category, name=name, url=link)
item = {'label': name, 'label2': link, 'icon': 'DefaultFolder.png', 'thumbnail': 'DefaultFolder.png', 'path': itempath}
item.setdefault(item.keys()[0])
litem = ListItem.from_dict(**item)
#if removelink:
# litem.add_context_menu_items([('Remove Saved Show', 'RunPlugin("{0}")'.format(plugin.url_for(removeshow, name=name, link=itempath)),)])
#else:
litem.add_context_menu_items([('Save Show', 'RunPlugin("{0}")'.format(plugin.url_for(saveshow, name=name, link=link)),)])
return litem
示例11: playlist_play_all
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def playlist_play_all(playlist_id):
data = api.request('playlist.getInfo', {
'id': playlist_id,
'video_sources': _get_supported_sources(),
'video_status': 1
})
items = [_make_video_item(video) for video in data['playlist']['videos']['video']]
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear()
for item in items:
listitem = ListItem.from_dict(**item)
playlist.add(item['path'], listitem.as_xbmc_listitem())
player = xbmc.Player()
player.playPlaylist(playlist)
示例12: playlist
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def playlist(self, show):
api = APICache(self.plugin)
show_data = api.get_show(show)
if len(show_data.playlists) > 0:
playlists = show_data.playlists
else:
playlists = api.get_playlists(show)
playlistItems = []
for playlist in playlists:
item = ListItem.from_dict(
label=playlist.name,
path=self.url_for("videolist.videolist", explicit=True, query=playlist.query, show=show),
)
if show_data.fanart:
item.set_property("fanart_image", show_data.fanart)
if playlist.type == "season":
item.set_info("video", {season: playlist.season})
playlistItems.append(item)
self.plugin.finish(items=playlistItems, sort_methods=[SortMethod.UNSORTED, SortMethod.LABEL_IGNORE_THE])
示例13: episode_makeitem
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def episode_makeitem(episodename, episodelink, dateadded=None):
'''
Will return a ListItem for the given link to an episode and it's full linked name.
Name will be sent to format show to attempt to parse out a date or season from the title.
Infolabels are populated with any details that can be parsed from the title as well.
Should be used anytime an item needs to be created that is an item for one specific episode of a show.
Latest 350, Saved Show, Category (Show listing of all episodes for that series) would all use this.
'''
infolbl = {}
spath = plugin.url_for(episode, name=episodename, url=episodelink)
img = "DefaultVideoFolder.png"
seasonstr = ''
try:
eptitle, epdate, epnum = formatshow(episodename)
eplbl = formatlabel(eptitle, epdate, epnum)
plotstr = "{0} ({1}): {2} {3}".format(epdate, epnum, eptitle, episodelink)
infolbl = {'EpisodeName': epdate, 'Title': eptitle, 'Plot': plotstr}
if len(epnum) > 0:
showS, showE = findepseason(epnum)
snum = int(showS)
epnum = int(showE)
infolbl.update({'Episode': showE, 'Season': showS})
if snum > 0 and epnum > 0:
epdate = "S{0}e{1}".format(snum, epnum)
infolbl.update({'PlotOutline': epdate})
if dateadded is not None:
dateout = str(dateadded.replace(' ', '-')).strip()
infolbl.update({"Date": dateout})
item = {'label': eplbl, 'label2': epdate, 'icon': img, 'thumbnail': img, 'path': spath}
item.setdefault(item.keys()[0])
li = ListItem.from_dict(**item)
li.set_is_playable(is_playable=True)
li.is_folder = True
li.set_info(type='video', info_labels=infolbl)
li.add_context_menu_items(
[('Autoplay', 'RunPlugin("{0}")'.format(plugin.url_for(endpoint=playfirst, url=episodelink)),)])
except:
li = ListItem(label=episodename, label2=episodelink, icon=img, thumbnail=img, path=spath)
return li
示例14: loadsaved
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def loadsaved():
sitems = []
litems = []
items = []
savedpath = ''
try:
savedpath = path.join(__datadir__, "saved.json")
if path.exists(savedpath):
fpin = file(savedpath)
rawjson = fpin.read()
sitems = json.loads(rawjson)
fpin.close()
else:
return []
for item in sitems:
li = ListItem.from_dict(**item)
li.add_context_menu_items(
[('Remove Saved Show', 'RunPlugin("{0}")'.format(plugin.url_for(removeshow, name=li.label, link=li.path)),)])
litems.append(li)
except:
pass
return litems
示例15: test_from_dict_info_default_info_type
# 需要导入模块: from xbmcswift2 import ListItem [as 别名]
# 或者: from xbmcswift2.ListItem import from_dict [as 别名]
def test_from_dict_info_default_info_type(self):
dct = {'info': {'title': 'My title'}}
with patch.object(ListItem, 'set_info', spec=True) as mock_set_info:
item = ListItem.from_dict(**dct)
mock_set_info.assert_called_with('video', {'title': 'My title'})