def pre_pipeline(self): try: self.client = soundcloud.Client(access_token = self.token) except HTTPError: logger.error("Could not retrieve a valid client to the" " soundcloud API. Most likely the access_token" " in the configuration is invalid or expired." " Please check the docs on how to get a new token.\n" "This blueprint is **DISABLED** for this run") self.client = None self.already_recorded = self.storage.get( "soundcloud_stored_ids", None) if not self.already_recorded: self.already_recorded = {} self.storage["soundcloud_stored_ids"] = self.already_recorded # make an in memor dict with the paths already recorded # and their soundcloud id's try: with open(self.record_file) as records_: records = csv.reader(records_) self.already_recorded = dict((row for row in records)) except IOError: # likely teh file does not exist: self.already_recorded = dict() #starts the ID for the comming files self.log_uploaded_audio = self._log_uploaded_audio_iter() # and wind it to the point of getting the first item on # the pipeline: self.log_uploaded_audio.next()
def set_options(self): try: self.token = self.options["access_token"] except KeyError: # FIXME: allow other ways of fetching the access token. # TODO: create a Plone view to allow one to get a proper # token, to go with the product. logger.error("The sc.blueprints.soundcloud.upload blueprint" " needs a valid soundcloud access token with" " upload rights to be able to proceed. For now," " token should be passed as an \"acces_token\" " "option on the cfg file. " "This blueprint is **DISABLED** for this run") self.token = "" # Wether to remove the sound datafrom the item before dispacthing # it through the pipeline self.remove_data = ast.literal_eval(self.options.get( "remove_data", "True")) self.audio_types = ast.literal_eval(self.options.get( "audio_types", """("audio",)""")) self.url_template = self.options.get( "url_template", SOUNDCLOUD_TEMPLATE_URL) self.re_upload_existing = ast.literal_eval(self.options.get( "re_upload_existing", "False")) self.default_track_name = self.options.get( "default_track_name", "Plone audio file") # persitent text file to keep track of already uploaded # files self.record_file=self.options.get("record_file", "/tmp/sc.blueprints.soundcloud.uploaded.csv")