# -*- coding: utf-8 -*- from pyload.Api import LinkStatus, DownloadStatus as DS from pyload.utils import to_list, has_method, uniqify from pyload.utils.fs import exists, remove, fs_encode from Base import Base, Retry class Package: """ Container that indicates that a new package should be created """ def __init__(self, name=None, links=None): self.name = name self.links = [] if links: self.addLinks(links) # nested packages self.packs = [] def addLinks(self, links): """ Add one or multiple links to the package :param links: One or list of urls or :class:`LinkStatus` """ links = to_list(links) for link in links: if not isinstance(link, LinkStatus): link = LinkStatus(link, link, -1, DS.Queued) self.links.append(link) def addPackage(self, pack): self.packs.append(pack) def getURLs(self): return [link.url for link in self.links] def getAllURLs(self): urls = self.getURLs() for p in self.packs: urls.extend(p.getAllURLs()) return urls # same name and urls is enough to be equal for packages def __eq__(self, other): return self.name == other.name and self.links == other.links def __repr__(self): return u"