def login(self, config): if self.auth and self.auth.logged: return if not isinstance(config, dict): config = {} self.auth = EmbyAuth(**config) self.auth.login(True)
def on_task_start(self, task, config): if not isinstance(config, dict): config = {} self.auth = EmbyAuth(**config) try: self.auth.login(False) except plugin.PluginError as e: logger.error('Not possible to login to emby: {}', e)
class PluginEmbyList: """ Returns Emby Lists Example: emby_list: server: host: http://localhost:8096 username: <username> apikey: <apikey> return_host: wan list: watched """ auth = None schema = { 'type': 'object', 'properties': { **SCHEMA_SERVER_TAG, 'list': { 'type': 'string' }, }, 'required': ['server', 'list'], 'additionalProperties': False, } def login(self, config): if self.auth and self.auth.logged: return if not isinstance(config, dict): config = {} self.auth = EmbyAuth(**config) self.auth.login(True) def get_list(self, config): self.login(config) return EmbyApiList(auth=self.auth, **config) def on_task_start(self, task, config): self.login(config) @plugin.internet(logger) def on_task_input(self, task, config): self.login(config) s_lists = EmbyApi.search_list(auth=self.auth, **config) for s_list in s_lists: entry = s_list.to_entry() yield entry
class EmbyRefreshLibrary: """ Refresh Emby Library Example: emby_refresh: server: host: http://localhost:8096 username: <username> apikey: <apikey> return_host: wan when: accepted """ auth = None schema = { 'type': 'object', 'properties': { **SCHEMA_SERVER_TAG, 'when': one_or_more({ 'type': 'string', 'enum': [ 'accepted', 'rejected', 'failed', 'no_entries', 'aborted', 'always' ], }), }, 'required': ['server'], 'additionalProperties': False, } def login(self, config): if self.auth and self.auth.logged: return if not isinstance(config, dict): config = {} self.auth = EmbyAuth(**config) self.auth.login(True) def prepare_config(self, config): config.setdefault('when', ['always']) when = config['when'] if when and not isinstance(when, list): config['when'] = [when] return def library_refresh(self): EmbyApiLibrary.library_refresh(self.auth) def on_task_start(self, task, config): self.login(config) @plugin.internet(logger) def on_task_exit(self, task, config): self.login(config) self.prepare_config(config) conditions = [ task.accepted and 'accepted' in config['when'], task.rejected and 'rejected' in config['when'], task.failed and 'failed' in config['when'], not task.all_entries and 'no_entries' in config['when'], 'always' in config['when'], ] if any(conditions): self.library_refresh() def on_task_abort(self, task, config): self.prepare_config(config) if 'aborted' in config['when']: self.library_refresh()
class EmbyLookup: """ Preforms Emby Lookup Example: emby_lookup: host: http://localhost:8096 username: <username> apikey: <apikey> return_host: wan """ auth = {} schema = {**SCHEMA_SERVER} def on_task_start(self, task, config): if not isinstance(config, dict): config = {} self.auth = EmbyAuth(**config) try: self.auth.login(False) except plugin.PluginError as e: logger.error('Not possible to login to emby: {}', e) @entry.register_lazy_lookup('emby_lookup') def lazy_loader(self, entry, auth): if not auth: return if not auth.logged: auth.login() emby_api = EmbyApi(auth) emby_data = emby_api.search(**entry) if not emby_data: return emby_type = EmbyApi.get_type(**emby_data) lazy_fields = get_field_map(media_type=emby_type) if not lazy_fields: return entry.update_using_map(lazy_fields, emby_data, ignore_none=True) def add_lazy(self, entry, media_type): lazy_fields = get_field_map(media_type=media_type) entry.add_lazy_fields(self.lazy_loader, lazy_fields, kwargs={'auth': self.auth}) entry['emby_server_id'] = self.auth.server_id entry['emby_username'] = self.auth.username entry['emby_user_id'] = self.auth.uid # Run after series and metainfo series and imdb @plugin.priority(110) def on_task_metainfo(self, task, config): if not config: return for entry in task.entries: self.add_lazy(entry, EmbyApi.get_type(**entry)) @property def movie_identifier(self): """Returns the plugin main identifier type""" return 'emby_movie_id' @property def series_identifier(self): """Returns the plugin main identifier type""" return 'emby_serie_id'
def on_task_start(self, task, config): if not isinstance(config, dict): config = {} self.auth = EmbyAuth(**config) self.auth.login(False)
class EmbyInput: """ Returns Emby Inputs Example: from_emby: server: host: http://localhost:8096 username: <username> apikey: <apikey> return_host: wan list: TV types: series """ auth = None schema = { 'type': 'object', 'properties': { **SCHEMA_SERVER_TAG, 'list': { 'type': 'string' }, 'types': one_or_more({ 'type': 'string', 'enum': ['movie', 'series', 'season', 'episode'] }), 'watched': { 'type': 'boolean' }, 'favorite': { 'type': 'boolean' }, 'sort': { 'oneOf': [ { 'type': 'string', 'enum': SORT_FIELDS, }, { 'type': 'object', 'properties': { 'field': { 'type': 'string', 'enum': SORT_FIELDS, }, 'order': { 'type': 'string', 'enum': ['ascending', 'descending'] }, }, 'required': ['field', 'order'], }, ] }, }, 'required': ['server'], 'additionalProperties': False, } def login(self, config): if self.auth and self.auth.logged: return if not isinstance(config, dict): config = {} self.auth = EmbyAuth(**config) self.auth.login(True) def on_task_start(self, task, config): self.login(config) @plugin.internet(logger) def on_task_input(self, task, config): self.login(config) s_lists = EmbyApi.search_list(**config) for s_list in s_lists: entry = s_list.to_entry() yield entry @plugin.internet(logger) def search(self, task, entry, config=None): self.login(config) s_list = EmbyApiList.get_api_list(**config) entries = [] entries_obj = {} for search_string in entry.get('search_strings', [entry['title']]): entry['search_string'] = search_string media = s_list.get(entry) if not media: continue new_entry = media.to_entry() if 'emby_id' not in new_entry: continue entries_obj[new_entry['emby_id']] = new_entry for _, new_entry in entries_obj.items(): entries.append(new_entry) return entries
class EmbyInput: """ Returns Emby Inputs Example: from_emby: server: host: http://localhost:8096 username: <username> apikey: <apikey> return_host: wan list: TV types: series """ auth = None schema = { 'type': 'object', 'properties': { **SCHEMA_SERVER_TAG, 'list': {'type': 'string'}, 'types': one_or_more( {'type': 'string', 'enum': ['movie', 'series', 'season', 'episode']} ), 'watched': {'type': 'boolean'}, 'favorite': {'type': 'boolean'}, 'sort': { 'oneOf': [ { 'type': 'string', 'enum': SORT_FIELDS, }, { 'type': 'object', 'properties': { 'field': { 'type': 'string', 'enum': SORT_FIELDS, }, 'order': {'type': 'string', 'enum': ['ascending', 'descending']}, }, 'required': ['field', 'order'], }, ] }, }, 'required': ['server', 'list'], 'additionalProperties': False, } def login(self, config): if self.auth and self.auth.logged: return if not isinstance(config, dict): config = {} self.auth = EmbyAuth(**config) self.auth.login(True) def on_task_start(self, task, config): self.login(config) @plugin.internet(logger) def on_task_input(self, task, config): self.login(config) s_lists = EmbyApi.search_list(**config) for s_list in s_lists: entry = s_list.to_entry() yield entry