def __init__(self, url=None, name=None, directory=None, backlog_limit=0): self.temp_url = None # Maintain separate data members for originally provided URL and URL we may develop due to # redirects. if url is None or url == "": raise ERROR.MalformedSubscriptionError("No URL provided.") else: LOG.debug("Storing provided url '%s'.", url) self.url = url self.original_url = url # Maintain name of podcast. if name is None or name == "": raise ERROR.MalformedSubscriptionError("No name provided.") else: LOG.debug("Provided name '%s'.", name) self.name = name # Our file downloader. self.downloader = Util.generate_downloader(HEADERS, self.name) # Store feed state, including etag/last_modified. self.feed_state = _FeedState() self.directory = _process_directory(directory) self.backlog_limit = backlog_limit self.use_title_as_filename = None feedparser.USER_AGENT = CONSTANTS.USER_AGENT
def decode_subscription(cls, sub_dictionary): """Decode subscription from dictionary.""" url = sub_dictionary.get("url", None) if url is None: msg = "URL in subscription to decode is null. Cannot decode." raise Error.MalformedSubscriptionError(msg) name = sub_dictionary.get("name", None) if name is None: msg = "Name in subscription to decode is null. Cannot decode." raise Error.MalformedSubscriptionError(msg) original_url = sub_dictionary.get("original_url", None) directory = sub_dictionary.get("directory", None) backlog_limit = sub_dictionary.get("backlog_limit", 0) use_title_as_filename = sub_dictionary.get("use_title_as_filename", False) feed_state = _FeedState(feedstate_dict=sub_dictionary.get("feed_state", None)) sub = Subscription(url=url, name=name, directory=directory, backlog_limit=backlog_limit) sub.original_url = original_url sub.use_title_as_filename = use_title_as_filename sub.feed_state = feed_state # Generate data members that shouldn't/won't be cached. sub.downloader = Util.generate_downloader(HEADERS, sub.name) return sub
def default_missing_fields(self, settings): """Set default values for any fields that are None (ones that were never set).""" # NOTE - directory is set separately, because we'll want to create it. # These are just plain options. if self.backlog_limit is None: self.backlog_limit = settings["backlog_limit"] if self.use_title_as_filename is None: self.use_title_as_filename = settings["use_title_as_filename"] if not hasattr(self, "feed_state") or self.feed_state is None: self.feed_state = _FeedState() self.downloader = Util.generate_downloader(HEADERS, self.name)
def default_missing_fields(self, settings): """Set default values for any fields that are None (ones that were never set).""" # NOTE - directory is set separately, because we'll want to create it. # The options set here are just plain options. if self.backlog_limit is None: self.backlog_limit = settings["backlog_limit"] if self.use_title_as_filename is None: self.use_title_as_filename = settings["use_title_as_filename"] if not hasattr(self, "feed_state") or self.feed_state is None: self.feed_state = _FeedState() self.downloader = Util.generate_downloader(HEADERS, self.name) self.parser = _generate_feedparser(self.name)
def __init__(self, url=None, name=None, directory=None, backlog_limit=0): # Maintain separate data members for originally provided URL, and URL we may change due to # redirects. if url is None or url == "": msg = "URL is None or empty - can't create subscription." raise Error.MalformedSubscriptionError(msg) # Maintain name of podcast. if name is None or name == "": msg = "Name is None or empty - can't create subscription." raise Error.MalformedSubscriptionError(msg) # Temporary storage for swapping around urls. self.temp_url = None LOG.debug("Storing provided url '%s'.", url) self.url = url self.original_url = url LOG.debug("Provided name '%s'.", name) self.name = name # Our file downloader. self.downloader = Util.generate_downloader(HEADERS, self.name) # Our wrapper around feedparser's parse for rate limiting. self.parser = _generate_feedparser(self.name) # Store feed state, including etag/last_modified. self.feed_state = _FeedState() self.directory = _process_directory(directory) self.backlog_limit = backlog_limit self.use_title_as_filename = None feedparser.USER_AGENT = CONSTANTS.USER_AGENT
def decode_subscription(cls, sub_dictionary): """Decode subscription from dictionary.""" sub = Subscription.__new__(Subscription) attrs = ["name", "original_url", "url"] for attr in attrs: if attr not in sub_dictionary.keys(): LOG.error("Sub to decode is missing %s, can't continue.", attr) return None else: setattr(sub, attr, sub_dictionary[attr]) sub.directory = sub_dictionary.get("directory", None) # NOTE - Deprecate eventually. if "download_backlog" in sub_dictionary.keys(): if sub_dictionary["download_backlog"]: sub.backlog_limit = sub_dictionary["backlog_limit"] else: sub.backlog_limit = 0 # NOTE - deprecate eventually. if "_current_url" in sub_dictionary.keys(): sub.url = sub_dictionary["_current_url"] # NOTE - deprecate eventually. if "_provided_url" in sub_dictionary.keys(): sub.original_url = sub_dictionary["_provided_url"] sub.backlog_limit = sub_dictionary.get("backlog_limit", 0) sub.use_title_as_filename = sub_dictionary.get("use_title_as_filename", None) sub.feed_state = _FeedState(feedstate_dict=sub_dictionary.get("feed_state", None)) # Generate data members that shouldn't/won't be cached. sub.downloader = Util.generate_downloader(HEADERS, sub.name) return sub