mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-22 04:56:35 +00:00
Add json_serial
to json.py
This commit is contained in:
parent
3abab98f64
commit
1ba4bca58b
@ -1,4 +1,6 @@
|
||||
from datetime import datetime
|
||||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from yt_dlp.utils import LazyList
|
||||
|
||||
|
||||
class JSONEncoder(DjangoJSONEncoder):
|
||||
@ -14,3 +16,11 @@ class JSONEncoder(DjangoJSONEncoder):
|
||||
return list(iterable)
|
||||
return super().default(obj)
|
||||
|
||||
|
||||
def json_serial(obj):
|
||||
if isinstance(obj, datetime):
|
||||
return obj.isoformat()
|
||||
if isinstance(obj, LazyList):
|
||||
return list(obj)
|
||||
raise TypeError(f'Type {type(obj)} is not json_serial()-able')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user