def search_index(section): storage = container.search_storage() if 'search_term' in storage: del storage['search_term'] context_menu = [ (lang(40309), actions.background(plugin.url_for('clear_search_history'))) ] items = [{ 'label': lang(34009), 'path': plugin.url_for('new_search', section=section), 'context_menu': context_menu, 'replace_context_menu': True, }, { 'label': lang(34010), 'path': plugin.url_for('advanced_search', section=section), 'context_menu': context_menu, 'replace_context_menu': True, }] if 'search_recent' in storage: items.extend([{ 'label': s, 'path': plugin.url_for('do_search', section=section, name=s), 'context_menu': context_menu + [ (lang(40311), actions.background(plugin.url_for('delete_search', name=s))) ], 'replace_context_menu': True, } for s in reversed(storage['search_recent'])]) plugin.finish(with_fanart(items))
def update_library(): import mediapoisk.container as container from plugin import plugin from mediapoisk.common import lang, batch, abort_requested from xbmcswift2 import xbmcgui from contextlib import closing log = logging.getLogger(__name__) library_manager = container.library_manager() scraper = container.scraper() media_ids = library_manager.stored_media_ids() if media_ids: log.info("Starting MediaPoisk.info library update...") progress = xbmcgui.DialogProgressBG() with closing(progress): progress.create(lang(30000), lang(40322)) processed = 0 for section, media_ids in media_ids.iteritems(): for ids in batch(media_ids): all_details = scraper.get_details_bulk(section, ids) all_folders = scraper.get_folders_bulk(section, ids) for media_id, details in all_details.items(): if media_id in all_folders: for folder in all_folders[media_id]: if library_manager.has_folder(folder.id): library_manager.update_folder(details, folder) processed += len(ids) progress.update(processed*100/len(media_ids)) if abort_requested(): break log.info("MediaPoisk.ru library update finished.") if plugin.get_setting('update-xbmc-library', bool): log.info("Starting XBMC library update...") plugin.update_library('video', library_manager.path)
def update(self, percent): lines = [] if self.name: lines.append(lang(33001) % {'name': self.name}) size = self._human_size(self.size) if self.size >= 0 else lang(33003) lines.append(lang(33002) % ({'transferred': self._human_size(self._transferred_bytes), 'total': size})) return self.handler.update(percent, *lines)
def bookmark_context_menu(media_id, section, title): bookmarks = container.bookmarks() if media_id in bookmarks: return [(lang(40307), actions.background(plugin.url_for('delete_bookmark', media_id=media_id, section=section.filter_val)))] else: return [(lang(40306), actions.background(plugin.url_for('add_bookmark', media_id=media_id, section=section.filter_val, title=ensure_str(title))))]
def toggle_auto_refresh_context_menu(section, media_id): not_refreshing_items = container.not_refreshing_items() # plugin.log.info("Media ID: %d, Expire: %r" % (media_id, container.details_cache().get_item_expire(media_id))) if media_id in not_refreshing_items: return [(lang(40323), actions.background(plugin.url_for('turn_on_auto_refresh', section=section.filter_val, media_id=media_id)))] else: return [(lang(40324), actions.background(plugin.url_for('turn_off_auto_refresh', section=section.filter_val, media_id=media_id)))]
def mark_watched_context_menu(section, media_id, date_added=None, total_size=None): watched_items = container.watched_items() if media_id in watched_items: return [(lang(40302), actions.background(plugin.url_for('mark_unwatched', media_id=media_id)))] else: return [(lang(40301), actions.background(plugin.url_for('mark_watched', section=section.filter_val, media_id=media_id, date_added=date_added, total_size=total_size)))]
def library_context_menu(section, media_id, folder_id): library_manager = container.library_manager() if library_manager.has_folder(folder_id): return [(lang(40321), actions.background(plugin.url_for('remove_from_library', folder_id=folder_id)))] else: return [(lang(40320), actions.background(plugin.url_for('add_to_library', section=section.filter_val, media_id=media_id, folder_id=folder_id)))]
def index(): items = [ {"label": lang(34002), "path": plugin.url_for("global_bookmarks")}, {"label": lang(34011), "path": plugin.url_for("global_history")}, ] library_manager = container.library_manager() if library_manager.has_folders(): items.append({"label": lang(34012), "path": plugin.url_for("library_items")}) items.extend( {"label": tf.decorate(s.localized, bold=True, color="white"), "path": plugin.url_for("explore", section=s.name)} for s in Section ) return with_fanart(items)
def explore(section): plugin.set_content("movies") section = Section.find(section) sf = container.search_filter(section) header = [ {"label": lang(34000), "path": plugin.url_for("search_index", section=section.filter_val)}, {"label": lang(34001), "path": plugin.url_for("genre_index", section=section.filter_val)} if section != Section.ANIME else None, {"label": lang(34002), "path": plugin.url_for("bookmarks_index", section=section.filter_val)}, {"label": lang(34011), "path": plugin.url_for("history_index", section=section.filter_val)}, ] header = [h for h in header if h is not None] make_search(sf, header)
def download_torrent(url): client = container.torrent_client() client.add(container.torrent(url), save_path(local=True)) if isinstance(client, TransmissionClient): name = 'Transmission' addon_id = 'script.transmission' elif isinstance(client, UTorrentClient): name = 'UTorrent' addon_id = 'plugin.program.utorrent' else: return if xbmcgui.Dialog().yesno(lang(40316), *(lang(40317) % name).split("|")): xbmc.executebuiltin('XBMC.RunAddon(%s)' % addon_id)
def update(self, percent): if not self.overlay.visible: return heading = "%s - %d%%" % (self.state.localized, percent) self.heading.setLabel(heading) self.title.setLabel(self.name) lines = [] if self.state in [TorrentStatus.DOWNLOADING, TorrentStatus.CHECKING, TorrentStatus.SEEDING, TorrentStatus.PREBUFFERING]: size = self._human_size(self.size) if self.size >= 0 else lang(33015) lines.append(lang(33016) % {'transferred': self._human_size(self._transferred_bytes), 'total': size}) if self.state != TorrentStatus.CHECKING: lines.append(lang(33014) % {'download_rate': self._human_rate(self.download_rate), 'upload_rate': self._human_rate(self.upload_rate), 'peers': self.peers, 'seeds': self.seeds}) self.label.setLabel("\n".join(lines))
def update(self, percent): lines = [] if self.name is not None: lines.append(lang(33011) % {'name': self.name}) if self.state in [TorrentStatus.DOWNLOADING, TorrentStatus.SEEDING, TorrentStatus.CHECKING, TorrentStatus.PREBUFFERING]: size = self._human_size(self.size) if self.size >= 0 else lang(33015) lines.append(lang(33013) % {'transferred': self._human_size(self._transferred_bytes), 'total': size, 'state': self.state.localized}) if self.state != TorrentStatus.CHECKING: lines.append(lang(33014) % {'download_rate': self._human_rate(self.download_rate), 'upload_rate': self._human_rate(self.upload_rate), 'peers': self.peers, 'seeds': self.seeds}) else: lines.append(lang(33012) % {'state': self.state.localized}) return self.handler.update(percent, *lines)
def make_search(sf, header=None, cache_to_disc=False, update_listing=False): skip = plugin.request.arg('skip') scraper = container.scraper() results = scraper.search_cached(sf, skip) if not results: return False if isinstance(results, Details): if header: plugin.add_items(with_fanart(header)) item = itemify_single_result(results) plugin.finish(items=[item], cache_to_disc=cache_to_disc, update_listing=update_listing) return True total = len(results) items = [] if skip: skip_prev = max(skip - sf.page_size, 0) total += 1 items.append({ 'label': lang(34003), 'path': plugin.request.url_with_params(skip=skip_prev) }) elif header: items.extend(header) total += len(header) plugin.add_items(with_fanart(items), total) for batch_res in batch(results): if abort_requested(): break items = itemify_search_results(sf.section, batch_res) plugin.add_items(items, total) items = [] if scraper.has_more: skip_next = (skip or 0) + sf.page_size items.append({ 'label': lang(34004), 'path': plugin.request.url_with_params(skip=skip_next) }) plugin.finish(items=with_fanart(items), sort_methods=['unsorted', 'date', 'title', 'video_year', 'video_rating'], cache_to_disc=cache_to_disc, update_listing=update_listing or skip is not None) return True
def new_search(section): storage = container.search_storage() if 'search_term' in storage: value = storage['search_term'] else: value = plugin.keyboard(heading=lang(40310)) if not value: return storage['search_term'] = value plugin.redirect(plugin.url_for('do_search', section=section, name=value, new=True))
def do_search(section, name): plugin.set_content('movies') section = Section.find(section) sf = container.search_filter(section=section, name=str(name)) if not make_search(sf): notify(lang(40312) % ensure_unicode(name)) elif plugin.request.arg('new'): storage = container.search_storage() recent = storage.get('search_recent', []) if name in recent: recent.remove(name) recent.append(name) storage['search_recent'] = recent count = plugin.get_setting('search-items-count', int) if len(recent) > count: del recent[:len(recent)-count]
def refresh_context_menu(media_id): return [(lang(40304), actions.background(plugin.url_for('refresh', media_id=media_id)))]
def refresh_all_context_menu(): return [(lang(40303), actions.background(plugin.url_for('refresh_all')))]
def __init__(self, name=None, size=-1, heading=None): AbstractFileTransferProgress.__init__(self, name, size) self.heading = heading or lang(33000) self.handler = XbmcProgress(heading)
def toggle_watched_context_menu(): return [(lang(40305), actions.toggle_watched())]
def clear_history_context_menu(): return [(lang(40315), actions.background(plugin.url_for('clear_history')))]
def download_torrent_context_menu(url): if container.torrent_client() and url: return [(lang(40314), actions.background(plugin.url_for('download_torrent', url=url)))] else: return []
# -*- coding: utf-8 -*- import os import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'resources', 'lib')) from mediapoisk.plugin import plugin from mediapoisk.common import LocalizedError, notify, lang from xbmcswift2 import xbmcgui if __name__ == '__main__': try: import mediapoisk.plugin.main import mediapoisk.plugin.contextmenu import mediapoisk.plugin.search import mediapoisk.plugin.advancedsearch plugin.run() except LocalizedError as e: e.log() if e.kwargs.get('dialog'): xbmcgui.Dialog().ok(lang(30000), *e.localized.split("|")) else: notify(e.localized) if e.kwargs.get('check_settings'): plugin.open_settings()
def info_context_menu(): return [(lang(40300), "Action(Info)")]