本文整理匯總了Python中resources.lib.kodion.items.DirectoryItem類的典型用法代碼示例。如果您正苦於以下問題:Python DirectoryItem類的具體用法?Python DirectoryItem怎麽用?Python DirectoryItem使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DirectoryItem類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_channel_formats
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: _on_explore_genre
def _on_explore_genre(self, context, re_match):
result = []
genre = re_match.group('genre')
if not genre:
json_data = context.get_function_cache().get(FunctionCache.ONE_DAY, self.get_client(context).get_categories)
category = re_match.group('category')
genres = json_data.get(category, [])
for genre in genres:
title = genre['title']
genre_item = DirectoryItem(title,
context.create_uri(['explore', 'genre', category, title]))
genre_item.set_fanart(self.get_fanart(context))
result.append(genre_item)
pass
else:
context.set_content_type(kodion.constants.content_type.SONGS)
params = context.get_params()
page = int(params.get('page', 1))
json_data = context.get_function_cache().get(FunctionCache.ONE_HOUR, self.get_client(context).get_genre,
genre=genre,
page=page)
path = context.get_path()
result = self._do_mobile_collection(context, json_data, path, params)
pass
return result
示例3: on_root
def on_root(self, context, re_match):
result = []
# favorites
if len(context.get_favorite_list().list()) > 0:
fav_item = kodion.items.FavoritesItem(context, fanart=self.get_fanart(context))
fav_item.set_name('[B]%s[/B]' % fav_item.get_name())
result.append(fav_item)
pass
# watch later
if len(context.get_watch_later_list().list()) > 0:
watch_later_item = kodion.items.WatchLaterItem(context, fanart=self.get_fanart(context))
result.append(watch_later_item)
pass
# list channels
for channel_id in self._channel_ids:
channel_config = Client.CHANNELS[channel_id]
channel_id = channel_config['id']
channel_title = channel_config['title']
channel_item = DirectoryItem(channel_title, context.create_uri([channel_id, 'formats']))
channel_item.set_fanart(context.create_resource_path('media', channel_id, 'background.jpg'))
channel_item.set_image(context.create_resource_path('media', channel_id, 'logo.png'))
result.append(channel_item)
pass
# search
search_item = kodion.items.SearchItem(context, image=context.create_resource_path('media', 'search.png'),
fanart=self.get_fanart(context))
result.append(search_item)
return result
示例4: _screen_object_to_item
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)
示例5: on_channel_format
def on_channel_format(self, context, re_match):
channel_id = re_match.group("channel_id")
format_id = re_match.group("format_id")
channel_config = Client.CHANNELS[channel_id]
client = self.get_client(context)
# try to process tabs
seo_url = context.get_param("seoUrl", "")
if not seo_url:
raise KodionException("seoUrl missing")
format_tabs = client.get_format_tabs(channel_config, seo_url)
# only on season tab -> show the content directly
if len(format_tabs) == 1 and format_tabs[0]["type"] == "tab":
format_tab = format_tabs[0]
return self._on_channel_format_list(context, channel_config, format_tab["id"])
# show the tabs/sections
tabs = []
for format_tab in format_tabs:
if format_tab["type"] == "tab":
tab_item = DirectoryItem(
format_tab["title"],
# /[CHANNEL_ID]/format/[FORMAT_ID]/list/[FORMAT_LIST_ID]/
context.create_uri([channel_id, "format", format_id, "list", str(format_tab["id"])]),
)
tab_item.set_image(format_tab["images"]["thumb"])
tab_item.set_fanart(format_tab["images"]["fanart"])
tabs.append(tab_item)
pass
elif format_tab["type"] == "date-span":
tab_title = format_tab["title"]
image = format_tab["images"]["thumb"]
fanart = format_tab["images"]["fanart"]
tab_item = DirectoryItem(
tab_title,
# /[CHANNEL_ID]/format/[FORMAT_ID]/year/[YEAR]/
context.create_uri(
[channel_id, "format", format_id, "year", tab_title],
{"start": format_tab["start"], "end": format_tab["end"], "image": image, "fanart": fanart},
),
)
tab_item.set_image(image)
tab_item.set_fanart(fanart)
tabs.append(tab_item)
pass
else:
raise KodionException('Unknown type "%s" for tab' % format_tab["type"])
pass
return tabs
示例6: _get_channel_highlights
def _get_channel_highlights(self, context, re_match):
result = []
channel_id = re_match.group('channelid')
channel_image = context.create_resource_path('media', 'channels' '%s.png' % channel_id)
category = re_match.group('category')
if category is None:
# Popular Shows
item = DirectoryItem(context.localize(self._local_map['7tv.popular_shows']),
context.create_uri([channel_id, 'highlights', 'Beliebte Sendungen']),
image=channel_image)
item.set_fanart(self.get_fanart(context))
result.append(item)
# Current Entire Episodes
item = DirectoryItem(context.localize(self._local_map['7tv.current_entire_episodes']),
context.create_uri([channel_id, 'highlights', 'Aktuelle ganze Folgen']),
image=channel_image)
item.set_fanart(self.get_fanart(context))
result.append(item)
# Newest Clips
item = DirectoryItem(context.localize(self._local_map['7tv.newest_clips']),
context.create_uri([channel_id, 'highlights', 'Neueste Clips']),
image=channel_image)
item.set_fanart(self.get_fanart(context))
result.append(item)
else:
json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE * 5,
self._get_client(context).get_homepage,
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:
if screen_object.get('type', '') == 'sushi_bar':
if screen_object.get('title', '') == category:
sub_screen_objects = screen_object.get('screen_objects', [])
for sub_screen_object in sub_screen_objects:
result.append(self._screen_object_to_item(context,
sub_screen_object,
show_format_title=(category == 'Neueste Clips')))
pass
break
pass
pass
if category == 'Beliebte Sendungen':
self._set_sort_method_for_content_type(context, kodion.constants.content_type.TV_SHOWS)
result = self._sort_result_by_name(result)
else:
self._set_sort_method_for_content_type(context, kodion.constants.content_type.EPISODES)
result = self._sort_result_by_aired(result)
pass
return result
示例7: on_channel_format
def on_channel_format(self, context, re_match):
channel_id = re_match.group('channel_id')
format_id = re_match.group('format_id')
channel_config = Client.CHANNELS[channel_id]
client = self.get_client(context)
# try to process tabs
seo_url = context.get_param('seoUrl', '')
if not seo_url:
raise KodionException('seoUrl missing')
format_tabs = client.get_format_tabs(channel_config, seo_url)
# only on season tab -> show the content directly
if len(format_tabs) == 1 and format_tabs[0]['type'] == 'tab':
format_tab = format_tabs[0]
return self._on_channel_format_list(context, channel_config, format_tab['id'])
# show the tabs/sections
tabs = []
for format_tab in format_tabs:
if format_tab['type'] == 'tab':
tab_item = DirectoryItem(format_tab['title'],
# /[CHANNEL_ID]/format/[FORMAT_ID]/list/[FORMAT_LIST_ID]/
context.create_uri(
[channel_id, 'format', format_id, 'list', str(format_tab['id'])]))
tab_item.set_image(format_tab['images']['thumb'])
tab_item.set_fanart(format_tab['images']['fanart'])
tabs.append(tab_item)
pass
elif format_tab['type'] == 'date-span':
tab_title = format_tab['title']
image = format_tab['images']['thumb']
fanart = format_tab['images']['fanart']
tab_item = DirectoryItem(tab_title,
# /[CHANNEL_ID]/format/[FORMAT_ID]/year/[YEAR]/
context.create_uri([channel_id, 'format', format_id, 'year', tab_title],
{'start': format_tab['start'],
'end': format_tab['end'],
'image': image,
'fanart': fanart}))
tab_item.set_image(image)
tab_item.set_fanart(fanart)
tabs.append(tab_item)
pass
else:
raise KodionException('Unknown type "%s" for tab' % format_tab['type'])
pass
return tabs
示例8: add_url
def add_url(self, url, provider, context):
url_components = urlparse.urlparse(url)
if url_components.hostname.lower() == 'youtube.com' or url_components.hostname.lower() == 'www.youtube.com':
params = dict(urlparse.parse_qsl(url_components.query))
if url_components.path.lower() == '/watch':
video_id = params.get('v', '')
if video_id:
plugin_uri = context.create_uri(['play'], {'video_id': video_id})
video_item = VideoItem('', plugin_uri)
self._video_id_dict[video_id] = video_item
pass
playlist_id = params.get('list', '')
if playlist_id:
if self._flatten:
self._playlist_ids.append(playlist_id)
pass
else:
playlist_item = DirectoryItem('', context.create_uri(['playlist', playlist_id]))
playlist_item.set_fanart(provider.get_fanart(context))
self._playlist_id_dict[playlist_id] = playlist_item
pass
pass
pass
elif url_components.path.lower() == '/playlist':
playlist_id = params.get('list', '')
if playlist_id:
if self._flatten:
self._playlist_ids.append(playlist_id)
pass
else:
playlist_item = DirectoryItem('', context.create_uri(['playlist', playlist_id]))
playlist_item.set_fanart(provider.get_fanart(context))
self._playlist_id_dict[playlist_id] = playlist_item
pass
pass
pass
elif self.RE_CHANNEL_ID.match(url_components.path):
re_match = self.RE_CHANNEL_ID.match(url_components.path)
channel_id = re_match.group('channel_id')
if self._flatten:
self._channel_ids.append(channel_id)
pass
else:
channel_item = DirectoryItem('', context.create_uri(['channel', channel_id]))
channel_item.set_fanart(provider.get_fanart(context))
self._channel_id_dict[channel_id] = channel_item
pass
pass
else:
context.log_debug('Unknown path "%s"' % url_components.path)
pass
pass
pass
示例9: on_search
def on_search(self, search_text, context, re_match):
context.get_ui().set_view_mode('videos')
result = []
json_data = self.get_client(context).search(search_text)
list = json_data.get('result', {}).get('content', {}).get('list', {})
for key in list:
item = list[key]
title = item['result']
format_id = item['formatid']
search_item = DirectoryItem(title,
context.create_uri(['format', format_id]))
search_item.set_fanart(self.get_fanart(context))
result.append(search_item)
pass
return result
示例10: _feed_to_item
def _feed_to_item(self, json_data, context):
result = []
data = json_data['data']['data']
for item in data:
gallery_item = DirectoryItem(item['title'],
context.create_uri(['show', str(item['id'])]))
gallery_item.set_fanart(self.get_fanart(context))
image = item.get('thumbnails', [])
if len(image) > 0:
image = image[0].get('url', '')
gallery_item.set_image(image)
pass
result.append(gallery_item)
pass
return result
示例11: _do_formats
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
示例12: _display_playlists
def _display_playlists(_playlist_ids):
_playlist_id_dict = {}
for playlist_id in _playlist_ids:
playlist_item = DirectoryItem('', context.create_uri(['playlist', playlist_id]))
playlist_item.set_fanart(provider.get_fanart(context))
_playlist_id_dict[playlist_id] = playlist_item
pass
_channel_item_dict = {}
utils.update_playlist_infos(provider, context, _playlist_id_dict, _channel_item_dict)
utils.update_fanarts(provider, context, _channel_item_dict)
# clean up - remove empty entries
_result = []
for key in _playlist_id_dict:
_playlist_item = _playlist_id_dict[key]
if _playlist_item.get_name():
_result.append(_playlist_item)
pass
return _result
示例13: on_search
def on_search(self, search_text, context, re_match):
result = []
params = context.get_params()
page = int(params.get('page', 1))
category = params.get('category', 'sounds')
path = context.get_path()
if page == 1 and category == 'sounds':
people_params = {}
people_params.update(params)
people_params['category'] = 'people'
people_item = DirectoryItem('[B]' + context.localize(self._local_map['soundcloud.people']) + '[/B]',
context.create_uri(path, people_params),
image=context.create_resource_path('media', 'users.png'))
people_item.set_fanart(self.get_fanart(context))
result.append(people_item)
playlist_params = {}
playlist_params.update(params)
playlist_params['category'] = 'sets'
playlist_item = DirectoryItem('[B]' + context.localize(self._local_map['soundcloud.playlists']) + '[/B]',
context.create_uri(path, playlist_params),
image=context.create_resource_path('media', 'playlists.png'))
playlist_item.set_fanart(self.get_fanart(context))
result.append(playlist_item)
pass
json_data = context.get_function_cache().get(FunctionCache.ONE_MINUTE, self.get_client(context).search,
search_text,
category=category, page=page)
result.extend(self._do_collection(context, json_data, path, params))
return result
示例14: _display_channels
def _display_channels(_channel_ids):
_channel_id_dict = {}
for channel_id in _channel_ids:
channel_item = DirectoryItem('', context.create_uri(['channel', channel_id]))
channel_item.set_fanart(provider.get_fanart(context))
_channel_id_dict[channel_id] = channel_item
pass
_channel_item_dict = {}
utils.update_channel_infos(provider, context, _channel_id_dict, channel_items_dict=_channel_item_dict)
utils.update_fanarts(provider, context, _channel_item_dict)
# clean up - remove empty entries
_result = []
for key in _channel_id_dict:
_channel_item = _channel_id_dict[key]
if _channel_item.get_name():
_result.append(_channel_item)
pass
pass
return _result
示例15: on_channel_format
def on_channel_format(self, context, re_match):
channel_id = re_match.group('channel_id')
channel_config = Client.CHANNELS[channel_id]
client = self.get_client(context)
# try to process tabs
seo_url = context.get_param('seoUrl', '')
if seo_url:
format_tabs = client.get_format_tabs(channel_config, seo_url)
# with only one tab we could display the whole list of videos
if len(format_tabs) == 1:
format_tab = format_tabs[0]
return self._on_channel_format_list(context, channel_config, format_tab['id'])
# show the tabs/sections
tabs = []
for format_tab in format_tabs:
if format_tab['type'] == 'season' or format_tab['type'] == 'year':
tab_item = DirectoryItem(format_tab['title'],
context.create_uri([channel_id, 'formatlist', str(format_tab['id'])]))
tab_item.set_image(format_tab['images']['thumb'])
tab_item.set_fanart(format_tab['images']['fanart'])
tabs.append(tab_item)
pass
elif format_tab['type'] == 'year':
tab_item = DirectoryItem(format_tab['title'],
context.create_uri([channel_id, 'yearlist', str(format_tab['id'])]))
tab_item.set_image(format_tab['images']['thumb'])
tab_item.set_fanart(format_tab['images']['fanart'])
tabs.append(tab_item)
pass
else:
raise KodionException('Unknown type "%s" for tab' % format_tab['type'])
pass
return tabs
format_id = re_match.group('format_id')
return []