def create_and_publish_stream(self, name, bid, claim_dict, file_path): """Create lbry file and make claim""" log.info('Starting publish for %s', name) file_name = os.path.basename(file_path) with file_utils.get_read_handle(file_path) as read_handle: stream_hash = yield create_lbry_file(self.session, self.lbry_file_manager, file_name, read_handle) prm = self.session.payment_rate_manager self.lbry_file = yield self.lbry_file_manager.add_lbry_file( stream_hash, prm) sd_hash = yield publish_sd_blob( self.lbry_file_manager.stream_info_manager, self.session.blob_manager, self.lbry_file.stream_hash) if 'source' not in claim_dict['stream']: claim_dict['stream']['source'] = {} claim_dict['stream']['source']['source'] = sd_hash claim_dict['stream']['source']['sourceType'] = 'lbry_sd_hash' claim_dict['stream']['source']['contentType'] = get_content_type( file_path) claim_dict['stream']['source'][ 'version'] = "_0_0_1" # need current version here claim_out = yield self.make_claim(name, bid, claim_dict) self.lbry_file.completed = True yield self.lbry_file.load_file_attributes() yield self.lbry_file.save_status() defer.returnValue(claim_out)
def create_and_publish_stream(self, name, bid, claim_dict, file_path, claim_address=None, change_address=None): """Create lbry file and make claim""" log.info('Starting publish for %s', name) if not os.path.isfile(file_path): raise Exception("File {} not found".format(file_path)) if os.path.getsize(file_path) == 0: raise Exception("Cannot publish empty file {}".format(file_path)) file_name = os.path.basename(file_path) with file_utils.get_read_handle(file_path) as read_handle: self.lbry_file = yield create_lbry_file(self.session, self.lbry_file_manager, file_name, read_handle) if 'source' not in claim_dict['stream']: claim_dict['stream']['source'] = {} claim_dict['stream']['source']['source'] = self.lbry_file.sd_hash claim_dict['stream']['source']['sourceType'] = 'lbry_sd_hash' claim_dict['stream']['source']['contentType'] = get_content_type( file_path) claim_dict['stream']['source'][ 'version'] = "_0_0_1" # need current version here claim_out = yield self.make_claim(name, bid, claim_dict, claim_address, change_address) yield self.session.storage.save_content_claim( self.lbry_file.stream_hash, "%s:%i" % (claim_out['txid'], claim_out['nout'])) yield self.lbry_file.get_claim_info() defer.returnValue(claim_out)
def create_and_publish_stream(self, name, bid, claim_dict, file_path, claim_address=None, change_address=None): """Create lbry file and make claim""" log.info('Starting publish for %s', name) if not os.path.isfile(file_path): raise Exception("File {} not found".format(file_path)) if os.path.getsize(file_path) == 0: raise Exception("Cannot publish empty file {}".format(file_path)) file_name = os.path.basename(file_path) with file_utils.get_read_handle(file_path) as read_handle: self.lbry_file = yield create_lbry_file(self.session, self.lbry_file_manager, file_name, read_handle) if 'source' not in claim_dict['stream']: claim_dict['stream']['source'] = {} claim_dict['stream']['source']['source'] = self.lbry_file.sd_hash claim_dict['stream']['source']['sourceType'] = 'lbry_sd_hash' claim_dict['stream']['source']['contentType'] = get_content_type(file_path) claim_dict['stream']['source']['version'] = "_0_0_1" # need current version here claim_out = yield self.make_claim(name, bid, claim_dict, claim_address, change_address) # check if we have a file already for this claim (if this is a publish update with a new stream) old_stream_hashes = yield self.session.storage.get_old_stream_hashes_for_claim_id(claim_out['claim_id'], self.lbry_file.stream_hash) if old_stream_hashes: for lbry_file in filter(lambda l: l.stream_hash in old_stream_hashes, list(self.lbry_file_manager.lbry_files)): yield self.lbry_file_manager.delete_lbry_file(lbry_file, delete_file=False) log.info("Removed old stream for claim update: %s", lbry_file.stream_hash) yield self.session.storage.save_content_claim( self.lbry_file.stream_hash, "%s:%i" % (claim_out['txid'], claim_out['nout']) ) defer.returnValue(claim_out)
def create_and_publish_stream(self, name, bid, claim_dict, file_path, claim_address=None, change_address=None): """Create lbry file and make claim""" log.info('Starting publish for %s', name) if not os.path.isfile(file_path): raise Exception("File {} not found".format(file_path)) if os.path.getsize(file_path) == 0: raise Exception("Cannot publish empty file {}".format(file_path)) file_name = os.path.basename(file_path) with file_utils.get_read_handle(file_path) as read_handle: stream_hash = yield create_lbry_file(self.session, self.lbry_file_manager, file_name, read_handle) sd_hash = yield publish_sd_blob( self.lbry_file_manager.stream_info_manager, self.session.blob_manager, stream_hash) status = ManagedEncryptedFileDownloader.STATUS_FINISHED self.lbry_file = yield self.lbry_file_manager.add_lbry_file( stream_hash, sd_hash, status=status) if 'source' not in claim_dict['stream']: claim_dict['stream']['source'] = {} claim_dict['stream']['source']['source'] = sd_hash claim_dict['stream']['source']['sourceType'] = 'lbry_sd_hash' claim_dict['stream']['source']['contentType'] = get_content_type( file_path) claim_dict['stream']['source'][ 'version'] = "_0_0_1" # need current version here claim_out = yield self.make_claim(name, bid, claim_dict, claim_address, change_address) self.lbry_file.completed = True yield self.lbry_file.save_status() defer.returnValue(claim_out)
def publish_stream(self, name, file_path, bid, metadata): log.info('Starting publish for %s', name) file_name = os.path.basename(file_path) with file_utils.get_read_handle(file_path) as read_handle: stream_hash = yield create_lbry_file(self.session, self.lbry_file_manager, file_name, read_handle) prm = self.session.payment_rate_manager self.lbry_file = yield self.lbry_file_manager.add_lbry_file( stream_hash, prm) sd_hash = yield publish_sd_blob( self.lbry_file_manager.stream_info_manager, self.session.blob_manager, self.lbry_file.stream_hash) if 'sources' not in metadata: metadata['sources'] = {} metadata['sources']['lbry_sd_hash'] = sd_hash metadata['content_type'] = get_content_type(file_path) metadata['ver'] = Metadata.current_version claim_out = yield self.make_claim(name, bid, metadata) self.lbry_file.completed = True yield self.lbry_file.load_file_attributes() yield self.lbry_file.save_status() defer.returnValue(claim_out)