Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

media_descriptor.py 689 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  1. import json
  2. import os
  3. from copy import deepcopy
  4. class MediaDescriptor:
  5. '''
  6. Metadata associated with a single media file
  7. '''
  8. def __init__(self, path) -> None:
  9. self.path = path
  10. self.__data = None
  11. def update(self, new_data):
  12. if os.path.exists(self.path):
  13. self.__data = self.read()
  14. self.__data.update(new_data)
  15. else:
  16. self.__data = new_data
  17. with open(self.path, 'w') as f:
  18. json.dump(self.__data, f)
  19. def read(self):
  20. with open(self.path, 'r') as f:
  21. self.__data = json.load(f)
  22. return self.data()
  23. def data(self):
  24. return deepcopy(self.__data)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...