def display(self): handle = _handle() items = [i for i in self.items if i] if not items and self.no_items_label: items.append( Item( label=_(self.no_items_label, _label=True), is_folder=False, )) for item in items: item.art['thumb'] = item.art.get('thumb') or self.thunb item.art['fanart'] = item.art.get('fanart') or self.fanart li = item.get_li() xbmcplugin.addDirectoryItem(handle, item.path, li, item.is_folder) if self.content: xbmcplugin.setContent(handle, self.content) if self.title: xbmcplugin.setPluginCategory(handle, self.title) for sort_method in self.sort_methods: xbmcplugin.addSortMethod(handle, sort_method) xbmcplugin.endOfDirectory(handle, succeeded=True, updateListing=self.updateListing, cacheToDisc=self.cacheToDisc)
def list_search(self): query = MxPlayerPlugin.get_user_input() if not query: return [] # Set plugin category. It is displayed in some skins as the name # of the current section. xbmcplugin.setPluginCategory(self.handle, 'Search/{}'.format(query)) data = self.make_request( self.MainUrl + 'search/result?query={}&userid={}&platform={}&content-languages={}' .format(urllib_parse.quote_plus(query), self.userid, self.platform, self.languages)) for item in data['sections']: if item.get('id') in ['shows', 'album']: self.add_directory_item( content_id=item['items'][0].get('id'), title=item['items'][0].get('title'), description=item['items'][0].get('title'), action='season', section_next=item.get('next'), item=item) elif item.get('id') in ['shorts', 'movie', 'music']: if item['items'][0].get('stream') is not None: self.add_video_item(item['items'][0]) # Add a sort method for the virtual folder items (alphabetically, ignore articles) xbmcplugin.addSortMethod(self.handle, xbmcplugin.SORT_METHOD_NONE) xbmcplugin.endOfDirectory(self.handle)
def endDirectory(self, success): if success: if self.content: xbmcplugin.setContent(self.handle, self.content) if self.category: xbmcplugin.setPluginCategory(self.handle, self.category) xbmcplugin.endOfDirectory(self.handle, success)
def display(self): handle = _handle() items = [i for i in self.items if i] ep_sort = True last_show_name = '' if not items and self.no_items_label: label = _(self.no_items_label, _label=True) if self.no_items_method == 'dialog': gui.ok(label, heading=self.title) return resolve() else: items.append(Item( label=label, is_folder=False, )) for item in items: if self.thumb and not item.art.get('thumb'): item.art['thumb'] = self.thumb if self.fanart and not item.art.get('fanart'): item.art['fanart'] = self.fanart episode = item.info.get('episode') show_name = item.info.get('tvshowtitle') if not episode or not show_name or (last_show_name and show_name != last_show_name): ep_sort = False if not last_show_name: last_show_name = show_name li = item.get_li() xbmcplugin.addDirectoryItem(handle, item.path, li, item.is_folder) if self.content: xbmcplugin.setContent(handle, self.content) if self.title: xbmcplugin.setPluginCategory(handle, self.title) if not self.sort_methods: self.sort_methods = [ xbmcplugin.SORT_METHOD_EPISODE, xbmcplugin.SORT_METHOD_UNSORTED, xbmcplugin.SORT_METHOD_LABEL ] if not ep_sort: self.sort_methods.pop(0) for sort_method in self.sort_methods: xbmcplugin.addSortMethod(handle, sort_method) xbmcplugin.endOfDirectory(handle, succeeded=True, updateListing=self.updateListing, cacheToDisc=self.cacheToDisc) if self.show_news: process_news()
def play_with_fshare_code(): xbmcplugin.setPluginCategory(plugin.handle, 'Fshare Code') list_item = xbmcgui.ListItem( label= "Enter code: https://fshare.vn/file/[COLOR orange][B]%s[/B][/COLOR]" % "XXXXXXXXXX", ) xbmcplugin.addDirectoryItem(plugin.handle, plugin.url_for( app.playing_with_fshare_code), list_item, isFolder=True) xbmcplugin.addDirectoryItem( plugin.handle, plugin.url_for(app.clear_with_fshare_code), xbmcgui.ListItem(label="[COLOR red][B]%s[/B][/COLOR]" % "Clear all..."), True) # Support to save search history items: dict = helper.get_last_fshare_movie() for item in items.values(): url = plugin.url_for(app.play, query=json.dumps({ 'item': item, 'direct': 1 })) txt = '[%s] %s' % (item.get('size'), item.get('title')) list_item = xbmcgui.ListItem(label=txt) if item.get('is_folder') == True: url = plugin.url_for(app.show_fshare_folder, query=json.dumps({ 'item': item, 'movie_item': item })) list_item.setProperty("IsPlayable", "false") xbmcplugin.addDirectoryItem(plugin.handle, url, list_item, True) else: list_item.setProperty("IsPlayable", "true") list_item.setInfo('video', {'title': item.get('title')}) xbmcplugin.addDirectoryItem(plugin.handle, url, list_item, False) xbmcplugin.endOfDirectory(plugin.handle)
def display(self): handle = _handle() items = [i for i in self.items if i] if not items and self.no_items_label: label = _(self.no_items_label, _label=True) if self.no_items_method == 'dialog': gui.ok(label, heading=self.title) return resolve() else: items.append(Item( label=label, is_folder=False, )) for item in items: if self.thumb and not item.art.get('thumb'): item.art['thumb'] = self.thumb if self.fanart and not item.art.get('fanart'): item.art['fanart'] = self.fanart li = item.get_li() xbmcplugin.addDirectoryItem(handle, item.path, li, item.is_folder) if self.content: xbmcplugin.setContent(handle, self.content) if self.title: xbmcplugin.setPluginCategory(handle, self.title) for sort_method in self.sort_methods: xbmcplugin.addSortMethod(handle, sort_method) xbmcplugin.endOfDirectory(handle, succeeded=True, updateListing=self.updateListing, cacheToDisc=self.cacheToDisc) common_data = userdata.Userdata(COMMON_ADDON) plugin_msg = common_data.get('_next_plugin_msg') if plugin_msg: common_data.delete('_next_plugin_msg') gui.ok(plugin_msg)
def list_main(self): # Set plugin category. It is displayed in some skins as the name # of the current section. xbmcplugin.setPluginCategory(self.handle, 'main') for category in MxPlayerPlugin.MAIN_CATEGORIES['Main']: self.add_directory_item(content_id=category[0], title=category[1], description=category[1], action='sections', section_next='first', item=None) self.add_search_item() # Add a sort method for the virtual folder items (alphabetically, ignore articles) xbmcplugin.addSortMethod(self.handle, xbmcplugin.SORT_METHOD_NONE) # Finish creating a virtual folder. xbmcplugin.endOfDirectory(self.handle)
def browse_letters(media, view_id, server_id=None): ''' Display letters as options. ''' letters = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ" view = Jellyfin(server_id).get_client().jellyfin.get_item(view_id) xbmcplugin.setPluginCategory(PROCESS_HANDLE, view['Name']) for node in letters: params = { 'id': view_id, 'mode': "browse", 'type': media, 'folder': 'firstletter-%s' % node, 'server': server_id } path = "%s?%s" % ("plugin://plugin.video.jellyfin/", urlencode(params)) directory(node, path) xbmcplugin.setContent(PROCESS_HANDLE, 'files') xbmcplugin.endOfDirectory(PROCESS_HANDLE)
def browse_letters(media, view_id, server_id=None): ''' Display letters as options. ''' letters = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ" view = TheVoid('GetItem', {'ServerId': server_id, 'Id': view_id}).get() xbmcplugin.setPluginCategory(int(sys.argv[1]), view['Name']) for node in letters: params = { 'id': view_id, 'mode': "browse", 'type': media, 'folder': 'firstletter-%s' % node, 'server': server_id } path = "%s?%s" % ("plugin://plugin.video.jellyfin/", urlencode(params)) directory(node, path) xbmcplugin.setContent(int(sys.argv[1]), 'files') xbmcplugin.endOfDirectory(int(sys.argv[1]))
def list_sections(self, sec_id, sec_next): # Set plugin category. It is displayed in some skins as the name # of the current section. xbmcplugin.setPluginCategory(self.handle, 'sections') data = self.make_request( self.MainUrl + 'home/tab/{}?{}&userid={}&platform={}&content-languages={}'.format( sec_id, sec_next, self.userid, self.platform, self.languages)) #web_pdb.set_trace() for item in data['sections']: self.add_directory_item(title=item.get('name'), content_id=item.get('id'), description=item.get('name'), section_next=item.get('next'), action='folder') if data['next'] is not None: data = self.make_request( self.MainUrl + 'home/tab/{}?{}&userid={}&platform={}&content-languages={}'. format(sec_id, data['next'], self.userid, self.platform, self.languages)) #web_pdb.set_trace() for item in data['sections']: self.add_directory_item(title=item.get('name'), content_id=item.get('id'), description=item.get('name'), section_next=item.get('next'), action='folder') self.add_next_page_and_search_item(item=data, original_title='sections', action='sections') # Add a sort method for the virtual folder items (alphabetically, ignore articles) xbmcplugin.addSortMethod(self.handle, xbmcplugin.SORT_METHOD_NONE) # Finish creating a virtual folder. xbmcplugin.endOfDirectory(self.handle)
def browse_subfolders(media, view_id, server_id=None): ''' Display submenus for jellyfin views. ''' from ..views import DYNNODES view = Jellyfin(server_id).get_client().jellyfin.get_item(view_id) xbmcplugin.setPluginCategory(PROCESS_HANDLE, view['Name']) nodes = DYNNODES[media] for node in nodes: params = { 'id': view_id, 'mode': "browse", 'type': media, 'folder': view_id if node[0] == 'all' else node[0], 'server': server_id } path = "%s?%s" % ("plugin://plugin.video.jellyfin/", urlencode(params)) directory(node[1] or view['Name'], path) xbmcplugin.setContent(PROCESS_HANDLE, 'files') xbmcplugin.endOfDirectory(PROCESS_HANDLE)
def browse_subfolders(media, view_id, server_id=None): ''' Display submenus for jellyfin views. ''' from views import DYNNODES view = TheVoid('GetItem', {'ServerId': server_id, 'Id': view_id}).get() xbmcplugin.setPluginCategory(int(sys.argv[1]), view['Name']) nodes = DYNNODES[media] for node in nodes: params = { 'id': view_id, 'mode': "browse", 'type': media, 'folder': view_id if node[0] == 'all' else node[0], 'server': server_id } path = "%s?%s" % ("plugin://plugin.video.jellyfin/", urlencode(params)) directory(node[1] or view['Name'], path) xbmcplugin.setContent(int(sys.argv[1]), 'files') xbmcplugin.endOfDirectory(int(sys.argv[1]))
def list_show(self, show_id, title, show_next): # Set plugin category. It is displayed in some skins as the name # of the current section. xbmcplugin.setPluginCategory(self.handle, title) #web_pdb.set_trace() data = self.make_request( self.MainUrl + 'detail/tab/tvshowepisodes?{}&type=season&id={}&userid={}&platform={}&content-languages={}' .format(show_next, show_id, self.userid, self.platform, self.languages)) for shows in data['items']: self.add_video_item(shows) self.add_next_page_and_search_item(item=data, original_title=title, action='show') # Add a sort method for the virtual folder items (alphabetically, ignore articles) xbmcplugin.addSortMethod(self.handle, xbmcplugin.SORT_METHOD_NONE) # Finish creating a virtual folder. xbmcplugin.endOfDirectory(self.handle)
def list_season(self, season_id, season_name): # Set plugin category. It is displayed in some skins as the name # of the current section. xbmcplugin.setPluginCategory(self.handle, season_name) data = self.make_request( self.MainUrl + 'detail/collection?type=tvshow&id={}&userid={}&platform={}&content-languages={}' .format(season_id, self.userid, self.platform, self.languages)) for season in data['tabs'][0]['containers']: self.add_directory_item(title=season['title'], content_id=season['id'], description=season.get('description'), action='show', section_next='first', item=season) #self.add_search_item() # Add a sort method for the virtual folder items (alphabetically, ignore articles) #xbmcplugin.addSortMethod(self.handle, xbmcplugin.SORT_METHOD_NONE) # Finish creating a virtual folder. xbmcplugin.endOfDirectory(self.handle)
def display(self): handle = _handle() items = [i for i in self.items if i] ep_sort = True last_show_name = '' item_types = {} if not items and self.no_items_label: label = _(self.no_items_label, _label=True) if self.no_items_method == 'dialog': gui.ok(label, heading=self.title) return resolve() else: items.append(Item( label=label, is_folder=False, )) count = 0.0 for item in items: if self.thumb and not item.art.get('thumb'): item.art['thumb'] = self.thumb if self.fanart and not item.art.get('fanart'): item.art['fanart'] = self.fanart if not item.specialsort: media_type = item.info.get('mediatype') show_name = item.info.get('tvshowtitle') if media_type != 'episode' or not show_name or ( last_show_name and show_name != last_show_name): ep_sort = False if not last_show_name: last_show_name = show_name if media_type not in item_types: item_types[media_type] = 0 item_types[media_type] += 1 count += 1 li = item.get_li() xbmcplugin.addDirectoryItem(handle, item.path, li, item.is_folder) if self.content == 'AUTO': self.content = 'videos' if not settings.getBool('video_folder_content', True) and item_types: type_map = { 'movie': 'movies', 'tvshow': 'tvshows', 'season': 'tvshows', 'episode': 'episodes', } top_type = sorted(item_types, key=lambda k: item_types[k], reverse=True)[0] percent = (item_types[top_type] / count) * 100 content_type = type_map.get(top_type) if percent > 70 and content_type: self.content = content_type if self.content: xbmcplugin.setContent(handle, self.content) if self.title: xbmcplugin.setPluginCategory(handle, self.title) if not self.sort_methods: self.sort_methods = [ xbmcplugin.SORT_METHOD_EPISODE, xbmcplugin.SORT_METHOD_UNSORTED, xbmcplugin.SORT_METHOD_LABEL ] if not ep_sort: self.sort_methods.pop(0) for sort_method in self.sort_methods: xbmcplugin.addSortMethod(handle, sort_method) xbmcplugin.endOfDirectory(handle, succeeded=True, updateListing=self.updateListing, cacheToDisc=self.cacheToDisc) if self.show_news: process_news()
def setCategory(self, category): xbmcplugin.setPluginCategory(self.handle, category) self.category = 0
def browse(media, view_id=None, folder=None, server_id=None, api_client=None): ''' Browse content dynamically. ''' LOG.info("--[ v:%s/%s ] %s", view_id, media, folder) if not window('jellyfin_online.bool') and server_id is None: monitor = xbmc.Monitor() for _i in range(300): if window('jellyfin_online.bool'): break elif monitor.waitForAbort(0.1): return else: LOG.error("Default server is not online.") return folder = folder.lower() if folder else None if folder is None and media in ('homevideos', 'movies', 'books', 'audiobooks'): return browse_subfolders(media, view_id, server_id) if folder and folder == 'firstletter': return browse_letters(media, view_id, server_id) if view_id: view = api_client.get_item(view_id) xbmcplugin.setPluginCategory(PROCESS_HANDLE, view['Name']) content_type = "files" if media in ('tvshows', 'seasons', 'episodes', 'movies', 'musicvideos', 'songs', 'albums'): content_type = media elif media in ('homevideos', 'photos'): content_type = "images" elif media in ('books', 'audiobooks'): content_type = "videos" elif media == 'music': content_type = "artists" if folder == 'recentlyadded': listing = api_client.get_recently_added(None, view_id, None) elif folder == 'genres': listing = api_client.get_genres(view_id) elif media == 'livetv': listing = api_client.get_channels() elif folder == 'unwatched': listing = get_filtered_section(view_id, None, None, None, None, None, ['IsUnplayed'], None, server_id, api_client) elif folder == 'favorite': listing = get_filtered_section(view_id, None, None, None, None, None, ['IsFavorite'], None, server_id, api_client) elif folder == 'inprogress': listing = get_filtered_section(view_id, None, None, None, None, None, ['IsResumable'], None, server_id, api_client) elif folder == 'boxsets': listing = get_filtered_section(view_id, get_media_type('boxsets'), None, True, None, None, None, None, server_id, api_client) elif folder == 'random': listing = get_filtered_section(view_id, get_media_type(content_type), 25, True, "Random", None, None, None, server_id, api_client) elif (folder or "").startswith('firstletter-'): listing = get_filtered_section( view_id, get_media_type(content_type), None, None, None, None, None, {'NameStartsWith': folder.split('-')[1]}, server_id, api_client) elif (folder or "").startswith('genres-'): listing = get_filtered_section(view_id, get_media_type(content_type), None, None, None, None, None, {'GenreIds': folder.split('-')[1]}, server_id, api_client) elif folder == 'favepisodes': listing = get_filtered_section(None, get_media_type(content_type), 25, None, None, None, ['IsFavorite'], None, server_id, api_client) elif folder and media == 'playlists': listing = get_filtered_section(folder, get_media_type(content_type), None, False, 'None', None, None, None, server_id, api_client) elif media == 'homevideos': listing = get_filtered_section(folder or view_id, get_media_type(content_type), None, False, None, None, None, None, server_id, api_client) elif media in ['movies', 'episodes']: listing = get_filtered_section(folder or view_id, get_media_type(content_type), None, True, None, None, None, None, server_id, api_client) elif media in ('boxset', 'library'): listing = get_filtered_section(folder or view_id, None, None, True, None, None, None, None, server_id, api_client) elif media == 'boxsets': listing = get_filtered_section(folder or view_id, None, None, False, None, None, ['Boxsets'], None, server_id, api_client) elif media == 'tvshows': listing = get_filtered_section(folder or view_id, get_media_type(content_type), None, True, None, None, None, None, server_id, api_client) elif media == 'seasons': listing = api_client.get_seasons(folder) elif media != 'files': listing = get_filtered_section(folder or view_id, get_media_type(content_type), None, False, None, None, None, None, server_id, api_client) else: listing = get_filtered_section(folder or view_id, None, None, False, None, None, None, None, server_id, api_client) if listing: actions = Actions(server_id, api_client) list_li = [] listing = listing if type(listing) == list else listing.get( 'Items', []) for item in listing: li = xbmcgui.ListItem() li.setProperty('jellyfinid', item['Id']) li.setProperty('jellyfinserver', server_id) actions.set_listitem(item, li) if item.get('IsFolder'): params = { 'id': view_id or item['Id'], 'mode': "browse", 'type': get_folder_type(item, media) or media, 'folder': item['Id'], 'server': server_id } path = "%s?%s" % ("plugin://plugin.video.jellyfin/", urlencode(params)) context = [] if item['Type'] in ('Series', 'Season', 'Playlist'): context.append(( "Play", "RunPlugin(plugin://plugin.video.jellyfin/?mode=playlist&id=%s&server=%s)" % (item['Id'], server_id))) if item['UserData']['Played']: context.append((translate( 16104 ), "RunPlugin(plugin://plugin.video.jellyfin/?mode=unwatched&id=%s&server=%s)" % (item['Id'], server_id))) else: context.append((translate( 16103 ), "RunPlugin(plugin://plugin.video.jellyfin/?mode=watched&id=%s&server=%s)" % (item['Id'], server_id))) li.addContextMenuItems(context) list_li.append((path, li, True)) elif item['Type'] == 'Genre': params = { 'id': view_id or item['Id'], 'mode': "browse", 'type': get_folder_type(item, media) or media, 'folder': 'genres-%s' % item['Id'], 'server': server_id } path = "%s?%s" % ("plugin://plugin.video.jellyfin/", urlencode(params)) list_li.append((path, li, True)) else: if item['Type'] not in ('Photo', 'PhotoAlbum'): params = { 'id': item['Id'], 'mode': "play", 'server': server_id } path = "%s?%s" % ("plugin://plugin.video.jellyfin/", urlencode(params)) li.setProperty('path', path) context = [(translate( 13412 ), "RunPlugin(plugin://plugin.video.jellyfin/?mode=playlist&id=%s&server=%s)" % (item['Id'], server_id))] if item['UserData']['Played']: context.append((translate( 16104 ), "RunPlugin(plugin://plugin.video.jellyfin/?mode=unwatched&id=%s&server=%s)" % (item['Id'], server_id))) else: context.append((translate( 16103 ), "RunPlugin(plugin://plugin.video.jellyfin/?mode=watched&id=%s&server=%s)" % (item['Id'], server_id))) li.addContextMenuItems(context) list_li.append((li.getProperty('path'), li, False)) xbmcplugin.addDirectoryItems(PROCESS_HANDLE, list_li, len(list_li)) if content_type == 'images': xbmcplugin.addSortMethod(PROCESS_HANDLE, xbmcplugin.SORT_METHOD_VIDEO_TITLE) xbmcplugin.addSortMethod(PROCESS_HANDLE, xbmcplugin.SORT_METHOD_DATE) xbmcplugin.addSortMethod(PROCESS_HANDLE, xbmcplugin.SORT_METHOD_VIDEO_RATING) xbmcplugin.addSortMethod(PROCESS_HANDLE, xbmcplugin.SORT_METHOD_VIDEO_RUNTIME) xbmcplugin.setContent(PROCESS_HANDLE, content_type) xbmcplugin.endOfDirectory(PROCESS_HANDLE)
def setDispCat(self, cur_loc): xbmcplugin.setPluginCategory(self.handle, cur_loc) self.cur_loc = cur_loc
def list_folder(self, folder_id, title, folder_name): # Set plugin category. It is displayed in some skins as the name # of the current section. xbmcplugin.setPluginCategory(self.handle, folder_name) #web_pdb.set_trace() data = self.make_request( self.MainUrl + 'list/{}?{}&userid={}&platform={}&content-languages={}'.format( folder_id, folder_name, self.userid, self.platform, self.languages)) if not data['items']: logger.warn('items data is empty for folder! -- {}'.format(data)) kodiutils.notification('No items found', 'Check logs for api content!') return for item in data['items']: if item['container'] is not None: subtype = item['container'].get('type') else: subtype = item.get('type') newtitle = '{} (Count - {})'.format(item['title'], item.get('videoCount')) if subtype in ['folder']: self.add_directory_item(content_id=item['id'], title=newtitle, description=item.get('description'), action='folder', section_next=folder_name, item=item) elif subtype in [ 'trailer', 'movie', 'video', 'episode', 'teaser', 'music', 'webisode', 'clip', 'shorts', 'news', 'album', 'season', 'liveChannel' ]: self.add_video_item(item) elif subtype in ['original', 'tvshow']: self.add_directory_item( content_id=item['id'], title=newtitle, description=self.get_description(item), action='season', section_next=folder_name, item=item) #item['publisher'].get('name') elif subtype not in ['external_link']: logger.warn( u'Skipping rendering sub-type from item - {}: {}'.format( subtype, item)) if settings.is_debug(): kodiutils.notification( 'Unhandled asset type!', '{}'.format(subtype), icon=xbmcgui.NOTIFICATION_WARNING, ) self.add_next_page_and_search_item(item=data, original_title=folder_name, action='folder') # Add a sort method for the virtual folder items (alphabetically, ignore articles) xbmcplugin.addSortMethod(self.handle, xbmcplugin.SORT_METHOD_NONE) # Finish creating a virtual folder. xbmcplugin.endOfDirectory(self.handle)