def recheckPackage(self, pid): """Check online status of all files in a package, also a default action when package is added. """ self.core.files.reCheckPackage(pid) @RequirePerm(Permission.Modify) def restartFailed(self): """Restarts all failed failes.""" self.core.files.restartFailed() @RequirePerm(Permission.Modify) def stopAllDownloads(self): """Aborts all running downloads.""" for pyfile in self.core.files.cachedFiles(): if self.hasAccess(pyfile): pyfile.abortDownload() @RequirePerm(Permission.Modify) def stopDownloads(self, fids): """Aborts specific downloads. :param fids: list of file ids :return: """ pyfiles = self.core.files.cachedFiles() for pyfile in pyfiles: if pyfile.id in fids and self.hasAccess(pyfile): pyfile.abortDownload() if Api.extend(DownloadApi): del DownloadApi
class CollectorApi(ApiComponent): """ Link collector """ @RequirePerm(Permission.All) def getCollector(self): pass @RequirePerm(Permission.Add) def addToCollector(self, links): pass @RequirePerm(Permission.Add) def addFromCollector(self, name, new_name): pass @RequirePerm(Permission.Delete) def deleteCollPack(self, name): pass @RequirePerm(Permission.Add) def renameCollPack(self, name, new_name): pass @RequirePerm(Permission.Delete) def deleteCollLink(self, url): pass if Api.extend(CollectorApi): del CollectorApi
:param plugin: pluginName :return: list of :class:`AddonInfo` """ return self.core.addonManager.getInfo(plugin) @RequirePerm(Permission.Interaction) def getAddonHandler(self): """ Lists all available addon handler :return: dict of plugin name to list of :class:`AddonService` """ handler = {} for name, data in self.core.addonManager.iterAddons(): if data.handler: handler[name] = data.handler.values() return handler @RequirePerm(Permission.Interaction) def invokeAddon(self, plugin, func, func_args): """ Calls any function exposed by an addon """ return self.core.addonManager.invoke(plugin, func, func_args) @RequirePerm(Permission.Interaction) def invokeAddonHandler(self, plugin, func, pid_or_fid): """ Calls an addon handler registered to work with packages or files """ return self.invokeAddon(plugin, func, (pid_or_fid, )) if Api.extend(AddonApi): del AddonApi
@RequirePerm(Permission.All) def getUserData(self): """ Retrieves :class:`UserData` for the currently logged in user. """ @RequirePerm(Permission.All) def setPassword(self, username, old_password, new_password): """ Changes password for specific user. User can only change their password. Admins can change every password! """ def getAllUserData(self): """ Retrieves :class:`UserData` of all exisitng users.""" def addUser(self, username, password): """ Adds an user to the db. :param username: desired username :param password: password for authentication """ def updateUserData(self, data): """ Change parameters of user account. """ def removeUser(self, uid): """ Removes user from the db. :param uid: users uid """ if Api.extend(UserApi): del UserApi
# requires at least plugin permissions, but only admin can load core config config, values = self.core.config.getSection(name, self.primaryUID) return toConfigHolder(name, config, values) @RequirePerm(Permission.Plugins) def saveConfig(self, config): """Used to save a configuration, core config can only be saved by admins :param config: :class:`ConfigHolder` """ for item in config.items: self.core.config.set(config.name, item.name, item.value, sync=False, user=self.primaryUID) # save the changes self.core.config.saveValues(self.primaryUID, config.name) @RequirePerm(Permission.Plugins) def deleteConfig(self, plugin): """Deletes modified config :param plugin: plugin name """ #TODO: delete should deactivate addons? self.core.config.delete(plugin, self.primaryUID) if Api.extend(ConfigApi): del ConfigApi
:return: updated account info """ return self.core.accountManager.updateAccount(aid, plugin, loginname, password, self.user).toInfoData() @RequirePerm(Permission.Accounts) def updateAccountInfo(self, account): """ Update account settings from :class:`AccountInfo` """ inst = self.core.accountManager.getAccount(account.aid, account.plugin, self.user) if not inst: return inst.activated = to_bool(account.activated) inst.shared = to_bool(account.shared) inst.updateConfig(account.config) @RequirePerm(Permission.Accounts) def removeAccount(self, account): """Remove account from pyload. :param account: :class:`ÀccountInfo` instance """ self.core.accountManager.removeAccount(account.aid, account.plugin, self.primaryUID) if Api.extend(AccountApi): del AccountApi
:param name: Name of plugin or config section :rtype: ConfigHolder """ # requires at least plugin permissions, but only admin can load core config config, values = self.core.config.getSection(name, self.primaryUID) return toConfigHolder(name, config, values) @RequirePerm(Permission.Plugins) def saveConfig(self, config): """Used to save a configuration, core config can only be saved by admins :param config: :class:`ConfigHolder` """ for item in config.items: self.core.config.set(config.name, item.name, item.value, sync=False, user=self.primaryUID) # save the changes self.core.config.saveValues(self.primaryUID, config.name) @RequirePerm(Permission.Plugins) def deleteConfig(self, plugin): """Deletes modified config :param plugin: plugin name """ #TODO: delete should deactivate addons? self.core.config.delete(plugin, self.primaryUID) if Api.extend(ConfigApi): del ConfigApi
urls += [x[0] for x in urlmatcher.findall(html)] if url: page = getURL(url) urls += [x[0] for x in urlmatcher.findall(page)] return self.checkLinks(uniqify(urls)) @RequirePerm(Permission.Add) def pollResults(self, rid): """ Polls the result available for ResultID :param rid: `ResultID` :return: `OnlineCheck`, if rid is -1 then there is no more data available """ result = self.core.threadManager.getInfoResult(rid) if result and result.owner == self.primaryUID: return result.toApiData() @RequirePerm(Permission.Add) def generatePackages(self, links): """ Parses links, generates packages names from urls :param links: list of urls :return: package names mapped to urls """ result = parseNames((x, x) for x in links) return result if Api.extend(DownloadPreparingApi): del DownloadPreparingApi
#!/usr/bin/env python # -*- coding: utf-8 -*- from pyload.Api import Api, RequirePerm, Permission from ApiComponent import ApiComponent CACHE = {} QUOTA_UNLIMITED = -1 class StatisticsApi(ApiComponent): """ Retrieve download statistics and quota """ def recordDownload(self, pyfile): """ Add download record to the statistics """ del CACHE[:] def calcQuota(self, uid): return QUOTA_UNLIMITED def getQuota(self): """ Number of bytes the user has left for download """ return self.calcQuota(self.user.true_primary) if Api.extend(StatisticsApi): del StatisticsApi
urls.append(th.name) return self.checkOnlineStatus(urls) @RequirePerm(Permission.Add) def pollResults(self, rid): """ Polls the result available for ResultID :param rid: `ResultID` :return: `OnlineCheck`, if rid is -1 then there is no more data available """ result = self.core.threadManager.getInfoResult(rid) if "ALL_INFO_FETCHED" in result: del result["ALL_INFO_FETCHED"] return OnlineCheck(-1, result) else: return OnlineCheck(rid, result) @RequirePerm(Permission.Add) def generatePackages(self, links): """ Parses links, generates packages names from urls :param links: list of urls :return: package names mapped to urls """ result = parseNames((x, x) for x in links) return result if Api.extend(DownloadPreparingApi): del DownloadPreparingApi
:param fids: list of file ids :param pid: destination package :return: False if files can't be moved """ return self.core.files.moveFiles(fids, pid) @RequirePerm(Permission.Modify) def orderPackage(self, pid, position): """Set new position for a package. :param pid: package id :param position: new position, 0 for very beginning """ self.core.files.orderPackage(pid, position) @RequirePerm(Permission.Modify) def orderFiles(self, fids, pid, position): """ Set a new position for a bunch of files within a package. All files have to be in the same package and must be **continuous**\ in the package. That means no gaps between them. :param fids: list of file ids :param pid: package id of parent package :param position: new position: 0 for very beginning """ self.core.files.orderFiles(fids, pid, position) if Api.extend(FileApi): del FileApi
#!/usr/bin/env python # -*- coding: utf-8 -*- from pyload.Api import Api, RequirePerm, Permission from ApiComponent import ApiComponent class AddonApi(ApiComponent): """ Methods to interact with addons """ def getAllInfo(self): """Returns all information stored by addon plugins. Values are always strings :return: {"plugin": {"name": value } } """ return self.core.addonManager.getAllInfo() def getInfoByPlugin(self, plugin): """Returns information stored by a specific plugin. :param plugin: pluginname :return: dict of attr names mapped to value {"name": value} """ return self.core.addonManager.getInfo(plugin) if Api.extend(AddonApi): del AddonApi
""" Delete package and all content from disk recursively :param pids: list of package ids :return: False if any package can't be deleted currently """ # TODO @RequirePerm(Permission.Modify) def orderPackage(self, pid, position): """Set new position for a package. :param pid: package id :param position: new position, 0 for very beginning """ self.core.files.orderPackage(pid, position) @RequirePerm(Permission.Modify) def orderFiles(self, fids, pid, position): """ Set a new position for a bunch of files within a package. All files have to be in the same package and must be **continuous**\ in the package. That means no gaps between them. :param fids: list of file ids :param pid: package id of parent package :param position: new position: 0 for very beginning """ self.core.files.orderFiles(fids, pid, position) if Api.extend(FileApi): del FileApi
lines = fh.readlines() fh.close() if offset >= len(lines): return [] return lines[offset:] except: return ['No log available'] @RequirePerm(Permission.All) def isTimeDownload(self): """Checks if pyload will start new downloads according to time in config. :return: bool """ start = self.core.config['downloadTime']['start'].split(":") end = self.core.config['downloadTime']['end'].split(":") return compare_time(start, end) @RequirePerm(Permission.All) def isTimeReconnect(self): """Checks if pyload will try to make a reconnect :return: bool """ start = self.core.config['reconnect']['startTime'].split(":") end = self.core.config['reconnect']['endTime'].split(":") return compare_time(start, end) and self.core.config["reconnect"]["activated"] if Api.extend(CoreApi): del CoreApi
"""Check online status of all files in a package, also a default action when package is added. """ self.core.files.reCheckPackage(pid) @RequirePerm(Permission.Modify) def restartFailed(self): """Restarts all failed failes.""" self.core.files.restartFailed() @RequirePerm(Permission.Modify) def stopAllDownloads(self): """Aborts all running downloads.""" pyfiles = self.core.files.cachedFiles() for pyfile in pyfiles: pyfile.abortDownload() @RequirePerm(Permission.Modify) def stopDownloads(self, fids): """Aborts specific downloads. :param fids: list of file ids :return: """ pyfiles = self.core.files.cachedFiles() for pyfile in pyfiles: if pyfile.id in fids: pyfile.abortDownload() if Api.extend(DownloadApi): del DownloadApi
def updateAccount(self, plugin, loginname, password): """Creates an account if not existent or updates the password :return: newly created or updated account info """ # TODO: None pointer return self.core.accountManager.updateAccount(plugin, loginname, password, self.user).toInfoData() @RequirePerm(Permission.Accounts) def updateAccountInfo(self, account): """ Update account settings from :class:`AccountInfo` """ inst = self.core.accountManager.getAccount(account.plugin, account.loginname, self.user) if not account: return inst.activated = to_bool(account.activated) inst.shared = to_bool(account.shared) inst.updateConfig(account.config) @RequirePerm(Permission.Accounts) def removeAccount(self, account): """Remove account from pyload. :param account: :class:`ÀccountInfo` instance """ self.core.accountManager.removeAccount(account.plugin, account.loginname, self.primaryUID) if Api.extend(AccountApi): del AccountApi
if t.type == Interaction.Notification: t.setWaiting(self.core.interactionManager.CLIENT_THRESHOLD) return tasks @RequirePerm(Permission.Interaction) def setInteractionResult(self, iid, result): """Set Result for a interaction task. It will be immediately removed from task queue afterwards :param iid: interaction id :param result: result as json string """ task = self.core.interactionManager.getTaskByID(iid) if task and self.primaryUID == task.owner: task.setResult(result) @RequirePerm(Permission.Interaction) def getAddonHandler(self): pass @RequirePerm(Permission.Interaction) def callAddonHandler(self, plugin, func, pid_or_fid): pass @RequirePerm(Permission.Download) def generateDownloadLink(self, fid, timeout): pass if Api.extend(UserInteractionApi): del UserInteractionApi