forked from LBRYCommunity/lbry-sdk
add LBRYMetadata.py
This commit is contained in:
parent
5221631b40
commit
2dcd2b13be
1 changed files with 28 additions and 0 deletions
28
lbrynet/core/LBRYMetadata.py
Normal file
28
lbrynet/core/LBRYMetadata.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
BASE_METADATA_FIELDS = ['title', 'description', 'author', 'language', 'license', 'content-type']
|
||||||
|
OPTIONAL_METADATA_FIELDS = ['thumbnail', 'preview', 'fee', 'contact', 'pubkey']
|
||||||
|
|
||||||
|
#v0.0.1 metadata
|
||||||
|
METADATA_REVISIONS = {'0.0.1': {'required': BASE_METADATA_FIELDS, 'optional': OPTIONAL_METADATA_FIELDS}}
|
||||||
|
|
||||||
|
#v0.0.2 metadata additions
|
||||||
|
METADATA_REVISIONS['0.0.2'] = {'required': ['nsfw'], 'optional': []}
|
||||||
|
|
||||||
|
|
||||||
|
class Metadata(dict):
|
||||||
|
def __init__(self, metadata):
|
||||||
|
dict.__init__(self)
|
||||||
|
self.metaversion = None
|
||||||
|
m = metadata.copy()
|
||||||
|
for version in METADATA_REVISIONS:
|
||||||
|
for k in METADATA_REVISIONS[version]['required']:
|
||||||
|
assert k in metadata, "Missing required metadata field: %s" % k
|
||||||
|
self.update({k: m.pop(k)})
|
||||||
|
for k in METADATA_REVISIONS[version]['optional']:
|
||||||
|
if k in metadata:
|
||||||
|
self.update({k: m.pop(k)})
|
||||||
|
if not len(m):
|
||||||
|
self.metaversion = version
|
||||||
|
break
|
||||||
|
assert m == {}, "Unknown metadata keys: %s" % json.dumps(m.keys())
|
Loading…
Reference in a new issue