updating to new protobufs
This commit is contained in:
parent
665dba62c7
commit
60080cbd19
4 changed files with 526 additions and 327 deletions
|
@ -195,28 +195,60 @@ class Audio(Playable):
|
|||
self.message = audio_message
|
||||
|
||||
|
||||
class File:
|
||||
class Source:
|
||||
|
||||
__slots__ = '_file',
|
||||
__slots__ = 'message',
|
||||
|
||||
def __init__(self, file_message):
|
||||
self._file = file_message
|
||||
self.message = file_message
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._file.name
|
||||
return self.message.name
|
||||
|
||||
@name.setter
|
||||
def name(self, name: str):
|
||||
self._file.name = name
|
||||
self.message.name = name
|
||||
|
||||
@property
|
||||
def size(self) -> int:
|
||||
return self._file.size
|
||||
return self.message.size
|
||||
|
||||
@size.setter
|
||||
def size(self, size: int):
|
||||
self._file.size = size
|
||||
self.message.size = size
|
||||
|
||||
@property
|
||||
def media_type(self) -> str:
|
||||
return self.message.media_type
|
||||
|
||||
@media_type.setter
|
||||
def media_type(self, media_type: str):
|
||||
self.message.media_type = media_type
|
||||
|
||||
@property
|
||||
def sd_hash(self) -> str:
|
||||
return hexlify(self.message.sd_hash).decode()
|
||||
|
||||
@sd_hash.setter
|
||||
def sd_hash(self, sd_hash: str):
|
||||
self.message.sd_hash = unhexlify(sd_hash.encode())
|
||||
|
||||
@property
|
||||
def sd_hash_bytes(self) -> bytes:
|
||||
return self.message.sd_hash
|
||||
|
||||
@sd_hash_bytes.setter
|
||||
def sd_hash_bytes(self, sd_hash: bytes):
|
||||
self.message.sd_hash = sd_hash
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
return self.message.url
|
||||
|
||||
@url.setter
|
||||
def url(self, url: str):
|
||||
self.message.url = url
|
||||
|
||||
|
||||
class Fee:
|
||||
|
@ -505,35 +537,31 @@ class BaseClaimSubType:
|
|||
|
||||
@property
|
||||
def title(self) -> str:
|
||||
return self.message.title
|
||||
return self.claim.message.title
|
||||
|
||||
@title.setter
|
||||
def title(self, title: str):
|
||||
self.message.title = title
|
||||
self.claim.message.title = title
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return self.message.description
|
||||
return self.claim.message.description
|
||||
|
||||
@description.setter
|
||||
def description(self, description: str):
|
||||
self.message.description = description
|
||||
self.claim.message.description = description
|
||||
|
||||
@property
|
||||
def thumbnail_url(self) -> str:
|
||||
return self.message.thumbnail_url
|
||||
|
||||
@thumbnail_url.setter
|
||||
def thumbnail_url(self, thumbnail_url: str):
|
||||
self.message.thumbnail_url = thumbnail_url
|
||||
def thumbnail(self) -> Source:
|
||||
return Source(self.claim.message.thumbnail)
|
||||
|
||||
@property
|
||||
def tags(self) -> List:
|
||||
return self.message.tags
|
||||
return self.claim.message.tags
|
||||
|
||||
@property
|
||||
def languages(self) -> LanguageList:
|
||||
return LanguageList(self.message.languages)
|
||||
return LanguageList(self.claim.message.languages)
|
||||
|
||||
@property
|
||||
def langtags(self) -> List[str]:
|
||||
|
@ -541,7 +569,7 @@ class BaseClaimSubType:
|
|||
|
||||
@property
|
||||
def locations(self) -> LocationList:
|
||||
return LocationList(self.message.locations)
|
||||
return LocationList(self.claim.message.locations)
|
||||
|
||||
def to_dict(self):
|
||||
return MessageToDict(self.message, preserving_proto_field_name=True)
|
||||
|
@ -604,12 +632,8 @@ class Channel(BaseClaimSubType):
|
|||
self.message.homepage_url = homepage_url
|
||||
|
||||
@property
|
||||
def cover_url(self) -> str:
|
||||
return self.message.cover_url
|
||||
|
||||
@cover_url.setter
|
||||
def cover_url(self, cover_url: str):
|
||||
self.message.cover_url = cover_url
|
||||
def cover(self) -> Source:
|
||||
return Source(self.message.cover)
|
||||
|
||||
|
||||
class Stream(BaseClaimSubType):
|
||||
|
@ -670,22 +694,6 @@ class Stream(BaseClaimSubType):
|
|||
else:
|
||||
raise Exception(f'Unknown currency type: {fee_currency}')
|
||||
|
||||
@property
|
||||
def sd_hash(self) -> str:
|
||||
return hexlify(self.message.sd_hash).decode()
|
||||
|
||||
@sd_hash.setter
|
||||
def sd_hash(self, sd_hash: str):
|
||||
self.message.sd_hash = unhexlify(sd_hash.encode())
|
||||
|
||||
@property
|
||||
def sd_hash_bytes(self) -> bytes:
|
||||
return self.message.sd_hash
|
||||
|
||||
@sd_hash_bytes.setter
|
||||
def sd_hash_bytes(self, sd_hash: bytes):
|
||||
self.message.sd_hash = sd_hash
|
||||
|
||||
@property
|
||||
def author(self) -> str:
|
||||
return self.message.author
|
||||
|
@ -718,14 +726,6 @@ class Stream(BaseClaimSubType):
|
|||
def release_time(self, release_time: int):
|
||||
self.message.release_time = release_time
|
||||
|
||||
@property
|
||||
def media_type(self) -> str:
|
||||
return self.message.media_type
|
||||
|
||||
@media_type.setter
|
||||
def media_type(self, media_type: str):
|
||||
self.message.media_type = media_type
|
||||
|
||||
@property
|
||||
def fee(self) -> Fee:
|
||||
return Fee(self.message.fee)
|
||||
|
@ -735,8 +735,8 @@ class Stream(BaseClaimSubType):
|
|||
return self.message.HasField('fee')
|
||||
|
||||
@property
|
||||
def file(self) -> File:
|
||||
return File(self.message.file)
|
||||
def source(self) -> Source:
|
||||
return Source(self.message.source)
|
||||
|
||||
@property
|
||||
def image(self) -> Image:
|
||||
|
|
|
@ -11,10 +11,13 @@ from lbrynet.schema.types.v1.fee_pb2 import Fee as FeeMessage
|
|||
def from_old_json_schema(claim, payload: bytes):
|
||||
value = json.loads(payload)
|
||||
stream = claim.stream
|
||||
stream.media_type = value.get('content_type', value.get('content-type', 'application/octet-stream'))
|
||||
stream.source.sd_hash = value['sources']['lbry_sd_hash']
|
||||
stream.source.media_type = value.get(
|
||||
'content_type', value.get('content-type', 'application/octet-stream'))
|
||||
stream.title = value.get('title', '')
|
||||
stream.description = value.get('description', '')
|
||||
stream.thumbnail_url = value.get('thumbnail', '')
|
||||
if value.get('thumbnail', ''):
|
||||
stream.thumbnail.url = value.get('thumbnail', '')
|
||||
stream.author = value.get('author', '')
|
||||
stream.license = value.get('license', '')
|
||||
stream.license_url = value.get('license_url', '')
|
||||
|
@ -26,7 +29,6 @@ def from_old_json_schema(claim, payload: bytes):
|
|||
stream.languages.append(language)
|
||||
except:
|
||||
pass
|
||||
stream.sd_hash = value['sources']['lbry_sd_hash']
|
||||
if value.get('nsfw', False):
|
||||
stream.tags.append('mature')
|
||||
if "fee" in value:
|
||||
|
@ -54,11 +56,11 @@ def from_types_v1(claim, payload: bytes):
|
|||
stream.author = old.stream.metadata.author
|
||||
stream.license = old.stream.metadata.license
|
||||
stream.license_url = old.stream.metadata.licenseUrl
|
||||
stream.thumbnail_url = old.stream.metadata.thumbnail
|
||||
stream.thumbnail.url = old.stream.metadata.thumbnail
|
||||
if old.stream.metadata.HasField('language'):
|
||||
stream.languages.add().message.language = old.stream.metadata.language
|
||||
stream.media_type = old.stream.source.contentType
|
||||
stream.sd_hash_bytes = old.stream.source.source
|
||||
stream.source.media_type = old.stream.source.contentType
|
||||
stream.source.sd_hash_bytes = old.stream.source.source
|
||||
if old.stream.metadata.nsfw:
|
||||
stream.tags.append('mature')
|
||||
if old.stream.metadata.HasField('fee'):
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -21,10 +21,10 @@ class TestOldJSONSchemaCompatibility(TestCase):
|
|||
self.assertEqual(stream.license, 'None')
|
||||
self.assertEqual(stream.author, 'root')
|
||||
self.assertEqual(stream.langtags, ['en'])
|
||||
self.assertEqual(stream.media_type, 'application/octet-stream')
|
||||
self.assertEqual(stream.thumbnail_url, '/home/robert/lbry/speed.jpg')
|
||||
self.assertEqual(stream.source.media_type, 'application/octet-stream')
|
||||
self.assertEqual(stream.thumbnail.url, '/home/robert/lbry/speed.jpg')
|
||||
self.assertEqual(
|
||||
stream.sd_hash,
|
||||
stream.source.sd_hash,
|
||||
'bbd1f68374ff9a1044a90d7dd578ce41979211c386caf19e'
|
||||
'6f496536db5f2c96b58fe2c7a6677b331419a117873b539f'
|
||||
)
|
||||
|
@ -52,9 +52,9 @@ class TestOldJSONSchemaCompatibility(TestCase):
|
|||
self.assertEqual(stream.license_url, 'https://creativecommons.org/licenses/by/3.0/us/legalcode')
|
||||
self.assertEqual(stream.author, 'Mii')
|
||||
self.assertEqual(stream.langtags, ['en'])
|
||||
self.assertEqual(stream.media_type, 'application/x-msdownload')
|
||||
self.assertEqual(stream.source.media_type, 'application/x-msdownload')
|
||||
self.assertEqual(
|
||||
stream.sd_hash,
|
||||
stream.source.sd_hash,
|
||||
'c5ffee0fa5168e16681b519d9d85446e8d1d818a616bd555'
|
||||
'40aa7374d2321b51abf2ac3dae1443a03dadcc8f7affaa62'
|
||||
)
|
||||
|
@ -78,9 +78,9 @@ class TestOldJSONSchemaCompatibility(TestCase):
|
|||
self.assertEqual(stream.license, 'Creative Commons Attribution 4.0 International')
|
||||
self.assertEqual(stream.author, 'sgb')
|
||||
self.assertEqual(stream.langtags, ['en'])
|
||||
self.assertEqual(stream.media_type, 'video/mp4')
|
||||
self.assertEqual(stream.source.media_type, 'video/mp4')
|
||||
self.assertEqual(
|
||||
stream.sd_hash,
|
||||
stream.source.sd_hash,
|
||||
'd83db664c6d7d570aa824300f4869e0bfb560e765efa477a'
|
||||
'ebf566467f8d3a57f4f8c704cab1308eb75ff8b7e84e3caf'
|
||||
)
|
||||
|
@ -121,10 +121,10 @@ class TestTypesV1Compatibility(TestCase):
|
|||
self.assertEqual(stream.license, 'Copyrighted (contact author)')
|
||||
self.assertEqual(stream.author, 'The Linux Gamer')
|
||||
self.assertEqual(stream.langtags, ['en'])
|
||||
self.assertEqual(stream.media_type, 'video/mp4')
|
||||
self.assertEqual(stream.thumbnail_url, 'https://berk.ninja/thumbnails/FrTdBCOS_fc')
|
||||
self.assertEqual(stream.source.media_type, 'video/mp4')
|
||||
self.assertEqual(stream.thumbnail.url, 'https://berk.ninja/thumbnails/FrTdBCOS_fc')
|
||||
self.assertEqual(
|
||||
stream.sd_hash,
|
||||
stream.source.sd_hash,
|
||||
'040e8ac6e89c061f982528c23ad33829fd7146435bf7a4cc'
|
||||
'22f0bff70c4fe0b91fd36da9a375e3e1c171db825bf5d1f3'
|
||||
)
|
||||
|
@ -158,9 +158,9 @@ class TestTypesV1Compatibility(TestCase):
|
|||
self.assertEqual(stream.license, 'Creative Commons Attribution 4.0 International')
|
||||
self.assertEqual(stream.author, 'rpg midi')
|
||||
self.assertEqual(stream.langtags, ['en'])
|
||||
self.assertEqual(stream.media_type, 'application/x-zip-compressed')
|
||||
self.assertEqual(stream.source.media_type, 'application/x-zip-compressed')
|
||||
self.assertEqual(
|
||||
stream.sd_hash,
|
||||
stream.source.sd_hash,
|
||||
'1f41eb0312aa7e8a5ce49349bc77d811da975833719d7515'
|
||||
'23b19f123fc3d528d6a94e3446ccddb7b9329f27a9cad7e3'
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue