def initial_page_for_pagination(self, identifier=''): enable = self.addon.getSetting('enable_pagination') == 'true' offset = int(self.addon.getSetting('items_per_page')) if enable: return Page(0, offset, 0, identifier) return Page.inifinite(identifier)
def partial_result(self, playlist, page, session): tracks = [] page = Page(page.start, page.offset, playlist.num_tracks(), page.identifier) for i in page.current_range(): track = playlist.track(i) tracks.append(track) return Model(tracks = self.model_factory.to_track_list_model(tracks, session), page = page)
def search(self, page = {}): page = Page.from_obj(page) session = self.current_session() search_result = Search(page, session).run_and_wait() tracks = LoadTrack.from_list(search_result.tracks(), session) return Model(tracks = self.model_factory.to_track_list_model(tracks, session), page = page)
def playlist_tracks(self, page = {}): page = Page.from_obj(page) playlist_link = link.create_from_string(page.identifier) session = self.current_session() linked_playlist = Playlist(playlist.create(session, playlist_link)) return self.tracks_model(linked_playlist, page, session)
def wrapped_f(*args): cache_storage = args[0].cache_storage cache = cache_storage.get_cache(self.key) item_key = Cached.GLOBAL_KEY if len(args) > 1: arg = args[1] print arg if type(arg) == type({}): page = Page.from_obj(arg) item_key = page.cache_key() else: item_key = arg result = cache.get(item_key) if result is not None: print 'Cache hit for item ', item_key, ' and cache ', self.key return result else: print 'Cache miss. Calling function and filling cache item ', item_key, ' and cache ', self.key result = f(*args) cache.update(item_key, result) return f(*args)
def initial_page_for_pagination(self, identifier = ''): enable = self.addon.getSetting('enable_pagination') == 'true' offset = int(self.addon.getSetting('items_per_page')) if enable: return Page(0, offset, 0, identifier) return Page.inifinite(identifier)
def search(self, args, path): if args.identifier == '': query = self.ui_helper.keyboardText() else: query = args.identifier if query is not None and query is not '': tracks_model = Model.from_object(self.server.search(Page(args.start, args.offset, args.max_items, query))) self.ui_helper.create_list_of_tracks(Model.from_object_list(tracks_model.tracks), Page.from_obj(tracks_model.page), path) self.ui_helper.end_directory()
def create_track_list_items(self, tracks, page=Page()): indexes = range(0, len(tracks)) if not page.is_infinite(): indexes = page.current_range() for index in indexes: track = tracks[index - page.start] path, item = self.list_item_factory.create_list_item( track, index + 1) self.add_context_menu(track, path, item) xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=path, listitem=item)
def create_list_of_tracks(self, tracks, page=Page(), path=None): xbmcplugin.setContent(self.addon_handle, UiHelper.CONTENT_SONGS) xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_TRACKNUM) xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_ARTIST) xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_TITLE) xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_ALBUM) self.create_track_list_items(tracks, page) if page.has_next(): self.create_folder_item(self.add_on.getLocalizedString(30029), Router.url_for(path, page.next()))
def tracks_model(self, playlist, page, session): if not page.is_infinite(): tracks_model = self.partial_result(playlist, page, session) else: tracks = LoadTrack.from_list(playlist.tracks(), session) tracks_model = Model(tracks = self.model_factory.to_track_list_model(tracks, session), page = Page()) return tracks_model
def starred(self, page = {}): session = self.current_session() playlist = LoadStarred(session).run_and_wait() page = Page.from_obj(page) return self.tracks_model(playlist, page, session)
def initial_page_for_search(self, identifier=''): offset = int(self.addon.getSetting('items_per_page')) return Page(0, offset, 0, identifier)
def get_playlist(self, args, path): tracks_model = Model.from_object(self.server.playlist_tracks(args)) self.ui_helper.create_list_of_tracks(Model.from_object_list(tracks_model.tracks), Page.from_obj(tracks_model.page), path) self.ui_helper.end_directory()