本文整理汇总了Python中resources.lib.kodion.items.DirectoryItem.set_context_menu方法的典型用法代码示例。如果您正苦于以下问题:Python DirectoryItem.set_context_menu方法的具体用法?Python DirectoryItem.set_context_menu怎么用?Python DirectoryItem.set_context_menu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resources.lib.kodion.items.DirectoryItem
的用法示例。
在下文中一共展示了DirectoryItem.set_context_menu方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_channel_formats
# 需要导入模块: from resources.lib.kodion.items import DirectoryItem [as 别名]
# 或者: from resources.lib.kodion.items.DirectoryItem import set_context_menu [as 别名]
def _get_channel_formats(self, context, re_match):
self._set_sort_method_for_content_type(context, kodion.constants.content_type.TV_SHOWS)
result = []
# load the formats of the given channel
channel_id = re_match.group('channelid')
json_data = context.get_function_cache().get(FunctionCache.ONE_DAY, self._get_client(context).get_formats,
self._get_client(context).
API_V2, channel_id)
screen = json_data.get('screen', {})
screen_objects = screen.get('screen_objects', {})
for screen_object in screen_objects:
format_id = screen_object['id'].split(':')
channel_id = format_id[0]
format_id = format_id[1]
format_item = DirectoryItem(screen_object['title'],
context.create_uri([channel_id, 'library', format_id]),
image=screen_object['image_url'])
fanart = self.get_fanart(context)
data = self._load_format_content(context, channel_id, format_id, return_cached_only=True)
if data is not None:
fanart = data.get('fanart', self.get_fanart(context))
pass
format_item.set_fanart(fanart)
context_menu = [(context.localize(kodion.constants.localize.FAVORITES_ADD),
'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.FAVORITES, 'add'],
{'item': kodion.items.to_jsons(format_item)}))]
format_item.set_context_menu(context_menu)
result.append(format_item)
pass
return self._sort_result_by_name(result)
示例2: _do_formats
# 需要导入模块: from resources.lib.kodion.items import DirectoryItem [as 别名]
# 或者: from resources.lib.kodion.items.DirectoryItem import set_context_menu [as 别名]
def _do_formats(self, context, json_formats):
result = []
formats = json_formats.get("items", [])
# show only free videos if not logged in or or the setting is enabled
show_only_free_videos = not self.is_logged_in() and context.get_settings().get_bool(
"nowtv.videos.only_free", False
)
for format_data in formats:
if show_only_free_videos and not format_data["free"]:
continue
format_title = format_data["title"]
params = {}
if format_data.get("seoUrl", ""):
params["seoUrl"] = format_data["seoUrl"]
pass
format_item = DirectoryItem(
format_title,
# /rtl/format/2/
context.create_uri([format_data["station"], "format", str(format_data["id"])], params),
)
format_item.set_image(format_data["images"]["thumb"])
format_item.set_fanart(format_data["images"]["fanart"])
result.append(format_item)
if self.is_logged_in():
if context.get_path() == "/nowtv/favorites/list/":
context_menu = [
(
context.localize(self._local_map["nowtv.remove_from_favs"]),
"RunPlugin(%s)"
% context.create_uri(["nowtv", "favorites", "delete"], {"format_id": format_data["id"]}),
)
]
pass
else:
context_menu = [
(
context.localize(self._local_map["nowtv.add_to_favs"]),
"RunPlugin(%s)"
% context.create_uri(["nowtv", "favorites", "add"], {"format_id": format_data["id"]}),
)
]
pass
else:
context_menu = [
(
context.localize(self._local_map["nowtv.add_to_favs"]),
"RunPlugin(%s)"
% context.create_uri(
[kodion.constants.paths.FAVORITES, "add"], {"item": kodion.items.to_jsons(format_item)}
),
)
]
pass
format_item.set_context_menu(context_menu)
pass
return result
示例3: _screen_object_to_item
# 需要导入模块: from resources.lib.kodion.items import DirectoryItem [as 别名]
# 或者: from resources.lib.kodion.items.DirectoryItem import set_context_menu [as 别名]
def _screen_object_to_item(self, context, screen_object, show_format_title=False):
screen_object_type = screen_object.get('type', '')
if screen_object_type == '':
raise kodion.KodimonException('Missing type for screenObject')
fanart = self.get_fanart(context)
format_id = screen_object.get('format_id', screen_object.get('id', '')).split(':')
if len(format_id) == 2:
channel_id = format_id[0]
format_id = format_id[1]
if channel_id == 'tvog':
channel_id = 'pro7'
pass
data = self._load_format_content(context, channel_id, format_id, return_cached_only=True)
fanart = data.get('fanart', self.get_fanart(context))
pass
if screen_object_type == 'video_item_date_no_label' or screen_object_type == 'video_item_date' \
or screen_object_type == 'video_item_format_no_label' or screen_object_type == 'video_item_format':
name = screen_object.get('title', screen_object['video_title'])
if screen_object_type == 'video_item_format_no_label' or show_format_title:
name = '%s - %s' % (screen_object['format_title'], name)
pass
video_item = VideoItem(name,
context.create_uri(['play'], {'id': screen_object['id']}),
image=screen_object.get('image_url', ''))
video_item.set_fanart(fanart)
video_item.set_duration_from_seconds(int(screen_object.get('duration', '60')))
date_time = datetime_parser.parse(screen_object.get('start', '0000-00-00'))
video_item.set_aired_from_datetime(date_time)
video_item.set_premiered_from_datetime(date_time)
video_item.set_year_from_datetime(date_time)
try_set_season_and_episode(video_item)
context_menu = [(context.localize(kodion.constants.localize.WATCH_LATER),
'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.WATCH_LATER, 'add'],
{'item': kodion.items.to_jsons(video_item)}))]
video_item.set_context_menu(context_menu)
return video_item
elif screen_object_type == 'format_item_home' or screen_object_type == 'format_item':
format_item = DirectoryItem(screen_object['title'],
context.create_uri([channel_id, 'library', format_id]),
image=screen_object['image_url'])
format_item.set_fanart(fanart)
context_menu = [(context.localize(kodion.constants.localize.FAVORITES_ADD),
'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.FAVORITES, 'add'],
{'item': kodion.items.to_jsons(format_item)}))]
format_item.set_context_menu(context_menu)
return format_item
raise kodion.KodimonException("Unknown type '%s' for screen_object" % screen_object_type)
示例4: _do_formats
# 需要导入模块: from resources.lib.kodion.items import DirectoryItem [as 别名]
# 或者: from resources.lib.kodion.items.DirectoryItem import set_context_menu [as 别名]
def _do_formats(self, context, json_formats):
result = []
formats = json_formats.get('items', [])
# show only free videos if not logged in or or the setting is enabled
show_only_free_videos = not self.is_logged_in() or context.get_settings().get_bool('nowtv.videos.only_free',
False)
for format_data in formats:
if show_only_free_videos and not format_data['free']:
continue
format_title = format_data['title']
params = {}
if format_data.get('seoUrl', ''):
params['seoUrl'] = format_data['seoUrl']
pass
format_item = DirectoryItem(format_title,
# /rtl/format/2/
context.create_uri([format_data['station'], 'format', str(format_data['id'])],
params))
format_item.set_image(format_data['images']['thumb'])
format_item.set_fanart(format_data['images']['fanart'])
result.append(format_item)
if self.is_logged_in():
if context.get_path() == '/nowtv/favorites/list/':
context_menu = [(context.localize(self._local_map['nowtv.remove_from_favs']),
'RunPlugin(%s)' % context.create_uri(['nowtv', 'favorites', 'delete'],
{'format_id': format_data['id']}))]
pass
else:
context_menu = [(context.localize(self._local_map['nowtv.add_to_favs']),
'RunPlugin(%s)' % context.create_uri(['nowtv', 'favorites', 'add'],
{'format_id': format_data['id']}))]
pass
else:
context_menu = [(context.localize(self._local_map['nowtv.add_to_favs']),
'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.FAVORITES, 'add'],
{'item': kodion.items.to_jsons(format_item)}))]
pass
format_item.set_context_menu(context_menu)
pass
return result
示例5: _do_formats
# 需要导入模块: from resources.lib.kodion.items import DirectoryItem [as 别名]
# 或者: from resources.lib.kodion.items.DirectoryItem import set_context_menu [as 别名]
def _do_formats(self, context, json_formats):
result = []
formats = json_formats.get('items', [])
for format_data in formats:
format_title = format_data['title']
params = {}
if format_data.get('seoUrl', ''):
params['seoUrl'] = format_data['seoUrl']
pass
format_item = DirectoryItem(format_title,
context.create_uri([format_data['station'], 'format', str(format_data['id'])], params))
format_item.set_image(format_data['images']['thumb'])
format_item.set_fanart(format_data['images']['fanart'])
result.append(format_item)
context_menu = [(context.localize(self._local_map['nowtv.add_to_favs']),
'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.FAVORITES, 'add'],
{'item': kodion.items.to_jsons(format_item)}))]
format_item.set_context_menu(context_menu)
pass
return result
示例6: _on_library
# 需要导入模块: from resources.lib.kodion.items import DirectoryItem [as 别名]
# 或者: from resources.lib.kodion.items.DirectoryItem import set_context_menu [as 别名]
def _on_library(self, context, re_match):
context.set_content_type(kodion.constants.content_type.TV_SHOWS)
context.add_sort_method(kodion.constants.sort_method.LABEL)
result = []
json_data = context.get_function_cache().get(FunctionCache.ONE_HOUR, self.get_client(context).get_formats)
format_list = json_data.get('result', {}).get('content', {}).get('formatlist')
for key in format_list:
now_format = format_list[key]
title = now_format['formatlong']
format_id = now_format['formatid']
free_episodes = int(now_format.get('free_episodes', '0'))
if free_episodes >= 1:
format_item = DirectoryItem(title,
context.create_uri(['format', format_id]))
# set image
image = self.get_client(context).get_config()['images']['format-thumbnail-url'].replace('%FORMAT_ID%',
format_id)
format_item.set_image(image)
# set fanart
fanart = self.get_client(context).get_config()['images']['format-fanart-url'].replace('%FORMAT_ID%',
format_id)
format_item.set_fanart(fanart)
context_menu = [(context.localize(self._local_map['now.add_to_favs']),
'RunPlugin(%s)' % context.create_uri([kodion.constants.paths.FAVORITES, 'add'],
{'item': kodion.items.to_jsons(format_item)}))]
format_item.set_context_menu(context_menu)
result.append(format_item)
pass
pass
return result
示例7: _do_item
# 需要导入模块: from resources.lib.kodion.items import DirectoryItem [as 别名]
# 或者: from resources.lib.kodion.items.DirectoryItem import set_context_menu [as 别名]
def _do_item(self, context, json_item, path, process_playlist=False):
def _get_track_year(collection_item_json):
# this would be the default info, but is mostly not set :(
year = collection_item_json.get('release_year', '')
if year:
return year
# we use a fallback.
# created_at=2013/03/24 00:32:01 +0000
re_match = re.match('(?P<year>\d{4})(.*)', collection_item_json.get('created_at', ''))
if re_match:
year = re_match.group('year')
if year:
return year
pass
return ''
def _get_image(json_data):
image_url = json_data.get('artwork_url', '')
# test avatar image
if not image_url:
image_url = json_data.get('avatar_url', '')
# test tracks (used for playlists)
if not image_url:
tracks = json_data.get('tracks', [])
if len(tracks) > 0:
return _get_image(tracks[0])
# fall back is the user avatar (at least)
image_url = json_data.get('user', {}).get('avatar_url', '')
pass
return self._get_hires_image(image_url)
kind = json_item.get('kind', '')
if kind == 'playlist':
if process_playlist:
result = []
tracks = json_item['tracks']
track_number = 1
for track in tracks:
path = context.get_path()
track_item = self._do_item(context, track, path)
# set the name of the playlist for the albumname
track_item.set_album_name(json_item['title'])
# based on the position in the playlist we add a track number
track_item.set_track_number(track_number)
result.append(track_item)
track_number += 1
pass
return result
else:
playlist_item = DirectoryItem(json_item['title'],
context.create_uri(['playlist', unicode(json_item['id'])]),
image=_get_image(json_item))
playlist_item.set_fanart(self.get_fanart(context))
if path == '/user/favorites/me/':
context_menu = [(context.localize(self._local_map['soundcloud.unlike']),
'RunPlugin(%s)' % context.create_uri(['like/playlist', unicode(json_item['id'])],
{'like': '0'}))]
else:
context_menu = [(context.localize(self._local_map['soundcloud.like']),
'RunPlugin(%s)' % context.create_uri(['like/playlist', unicode(json_item['id'])],
{'like': '1'}))]
playlist_item.set_context_menu(context_menu)
return playlist_item
pass
elif kind == 'user':
username = json_item['username']
user_id = unicode(json_item['id'])
if path == '/':
user_id = 'me'
username = '[B]' + username + '[/B]'
pass
user_item = DirectoryItem(username,
context.create_uri(['user/tracks', user_id]),
image=_get_image(json_item))
user_item.set_fanart(self.get_fanart(context))
if path == '/user/following/me/':
context_menu = [(context.localize(self._local_map['soundcloud.unfollow']),
'RunPlugin(%s)' % context.create_uri(['follow', unicode(json_item['id'])],
{'follow': '0'}))]
pass
else:
context_menu = [(context.localize(self._local_map['soundcloud.follow']),
'RunPlugin(%s)' % context.create_uri(['follow', unicode(json_item['id'])],
{'follow': '1'}))]
pass
user_item.set_context_menu(context_menu)
return user_item
elif kind == 'track':
title = json_item['title']
#.........这里部分代码省略.........