add --no_file_path param to publish, stream_create, and stream_update

This commit is contained in:
Jack Robison 2021-03-08 14:39:22 -05:00 committed by Lex Berezhny
parent cbc76adcaa
commit dac75563d3
2 changed files with 45 additions and 13 deletions

View file

@ -2970,7 +2970,7 @@ class Daemon(metaclass=JSONRPCServerType):
Create or replace a stream claim at a given name (use 'stream create/update' for more control).
Usage:
publish (<name> | --name=<name>) [--bid=<bid>] [--file_path=<file_path>]
publish (<name> | --name=<name>) [--bid=<bid>] [--file_path=<file_path> | --no_file_path]
[--validate_file] [--optimize_file]
[--fee_currency=<fee_currency>] [--fee_amount=<fee_amount>] [--fee_address=<fee_address>]
[--title=<title>] [--description=<description>] [--author=<author>]
@ -2987,6 +2987,7 @@ class Daemon(metaclass=JSONRPCServerType):
--name=<name> : (str) name of the content (can only consist of a-z A-Z 0-9 and -(dash))
--bid=<bid> : (decimal) amount to back the claim
--file_path=<file_path> : (str) path to file to be associated with name.
--no_file_path : (bool) don't associate a file to the name at this time.
--validate_file : (bool) validate that the video container and encodings match
common web browser support or that optimization succeeds if specified.
FFmpeg is required
@ -3075,11 +3076,13 @@ class Daemon(metaclass=JSONRPCServerType):
if len(claims) == 0:
if 'bid' not in kwargs:
raise Exception("'bid' is a required argument for new publishes.")
if 'file_path' not in kwargs:
if 'file_path' not in kwargs and not kwargs.get('no_file_path', False):
raise Exception("'file_path' is a required argument for new publishes.")
return await self.jsonrpc_stream_create(name, **kwargs)
elif len(claims) == 1:
assert claims[0].claim.is_stream, f"Claim at name '{name}' is not a stream claim."
if 'no_file_path' in kwargs:
kwargs.pop('no_file_path')
return await self.jsonrpc_stream_update(claims[0].claim_id, replace=True, **kwargs)
raise Exception(
f"There are {len(claims)} claims for '{name}', please use 'stream update' command "
@ -3160,15 +3163,16 @@ class Daemon(metaclass=JSONRPCServerType):
@requires(WALLET_COMPONENT, FILE_MANAGER_COMPONENT, BLOB_COMPONENT, DATABASE_COMPONENT)
async def jsonrpc_stream_create(
self, name, bid, file_path, allow_duplicate_name=False,
self, name, bid, file_path=None, allow_duplicate_name=False,
channel_id=None, channel_name=None, channel_account_id=None,
account_id=None, wallet_id=None, claim_address=None, funding_account_ids=None,
preview=False, blocking=False, validate_file=False, optimize_file=False, **kwargs):
preview=False, blocking=False, validate_file=False, optimize_file=False, no_file_path=False, **kwargs):
"""
Make a new stream claim and announce the associated file to lbrynet.
Usage:
stream_create (<name> | --name=<name>) (<bid> | --bid=<bid>) (<file_path> | --file_path=<file_path>)
stream_create (<name> | --name=<name>) (<bid> | --bid=<bid>)
(<file_path> | --file_path=<file_path> | --no_file_path)
[--validate_file] [--optimize_file]
[--allow_duplicate_name=<allow_duplicate_name>]
[--fee_currency=<fee_currency>] [--fee_amount=<fee_amount>] [--fee_address=<fee_address>]
@ -3186,6 +3190,7 @@ class Daemon(metaclass=JSONRPCServerType):
--name=<name> : (str) name of the content (can only consist of a-z A-Z 0-9 and -(dash))
--bid=<bid> : (decimal) amount to back the claim
--file_path=<file_path> : (str) path to file to be associated with name.
--no_file_path : (bool) don't associate a file to the name at this time.
--validate_file : (bool) validate that the video container and encodings match
common web browser support or that optimization succeeds if specified.
FFmpeg is required
@ -3282,13 +3287,16 @@ class Daemon(metaclass=JSONRPCServerType):
f"Use --allow-duplicate-name flag to override."
)
file_path, spec = await self._video_file_analyzer.verify_or_repair(
validate_file, optimize_file, file_path, ignore_non_video=True
)
kwargs.update(spec)
if not no_file_path:
file_path, spec = await self._video_file_analyzer.verify_or_repair(
validate_file, optimize_file, file_path, ignore_non_video=True
)
kwargs.update(spec)
claim = Claim()
claim.stream.update(file_path=file_path, sd_hash='0' * 96, **kwargs)
if not no_file_path and 'sd_hash' not in kwargs:
kwargs['sd_hash'] = '0' * 96
claim.stream.update(file_path=file_path if not no_file_path else None, **kwargs)
tx = await Transaction.claim_create(
name, claim, amount, claim_address, funding_accounts, funding_accounts[0], channel
)
@ -3296,8 +3304,9 @@ class Daemon(metaclass=JSONRPCServerType):
file_stream = None
if not preview:
file_stream = await self.file_manager.create_stream(file_path)
claim.stream.source.sd_hash = file_stream.sd_hash
if not no_file_path:
file_stream = await self.file_manager.create_stream(file_path)
claim.stream.source.sd_hash = file_stream.sd_hash
new_txo.script.generate()
if channel:
@ -3311,7 +3320,8 @@ class Daemon(metaclass=JSONRPCServerType):
await self.storage.save_claims([self._old_get_temp_claim_info(
tx, new_txo, claim_address, claim, name, dewies_to_lbc(amount)
)])
await self.storage.save_content_claim(file_stream.stream_hash, new_txo.id)
if not no_file_path:
await self.storage.save_content_claim(file_stream.stream_hash, new_txo.id)
self.component_manager.loop.create_task(save_claims())
self.component_manager.loop.create_task(self.analytics_manager.send_claim_action('publish'))

View file

@ -1889,6 +1889,28 @@ class StreamCommands(ClaimTestCase):
self.assertEqual(claim['value']['languages'], ['uk-UA'])
self.assertEqual(claim['value']['tags'], ['anime'])
# publish a stream with no source
tx5 = await self.publish(
'future-release', bid='0.1', languages='uk-UA', tags=['Anime', 'anime '], no_file_path=True
)
self.assertItemCount(await self.daemon.jsonrpc_file_list(), 2)
claim = await self.resolve('lbry://future-release')
self.assertEqual(claim['txid'], tx5['outputs'][0]['txid'])
self.assertNotIn('signing_channel', claim)
self.assertEqual(claim['value']['languages'], ['uk-UA'])
self.assertEqual(claim['value']['tags'], ['anime'])
self.assertNotIn('source', claim['value'])
# update the stream to have a source
with tempfile.NamedTemporaryFile() as file:
file.write(b'hi')
file.flush()
tx6 = await self.publish('future-release', file_path=file.name, tags=['something-else'])
claim = await self.resolve('lbry://future-release')
self.assertEqual(claim['txid'], tx6['outputs'][0]['txid'])
self.assertEqual(claim['value']['tags'], ['something-else'])
self.assertIn('source', claim['value'])
class SupportCommands(CommandTestCase):