added converter for date range objects param

This commit is contained in:
ArabCoders 2025-03-16 20:12:18 +03:00
parent 2e9c76a1f7
commit b116d48da6
4 changed files with 19 additions and 1 deletions

View file

@ -17,6 +17,7 @@
"aiocron",
"arrowless",
"copyts",
"daterange",
"dotenv",
"finaldir",
"getpid",

View file

@ -424,6 +424,7 @@ def arg_converter(args: str) -> dict:
"""
import yt_dlp.options
from yt_dlp.utils import DateRange
create_parser = yt_dlp.options.create_parser
@ -443,7 +444,9 @@ def arg_converter(args: str) -> dict:
if "postprocessors" in diff:
diff["postprocessors"] = [pp for pp in diff["postprocessors"] if pp not in default_opts["postprocessors"]]
return json.loads(json.dumps(diff))
from .encoder import Encoder
return json.loads(json.dumps(diff, cls=Encoder))
def validate_uuid(uuid_str: str, version: int = 4) -> bool:

View file

@ -132,4 +132,9 @@ class YTDLPOpts(metaclass=Singleton):
if "format" in data and data["format"] in ["not_set", "default"]:
data["format"] = None
if "daterange" in data and isinstance(data["daterange"], dict):
from yt_dlp.utils import DateRange
data["daterange"] = DateRange(data["daterange"]["start"], data["daterange"]["end"])
return data

View file

@ -1,6 +1,9 @@
import json
from datetime import date
from pathlib import Path
from yt_dlp.utils import DateRange
class Encoder(json.JSONEncoder):
"""
@ -13,6 +16,12 @@ class Encoder(json.JSONEncoder):
if isinstance(o, Path):
return str(o)
if isinstance(o, DateRange):
return {"start": str(o.start).replace("-", ""), "end": str(o.end).replace("-", "")}
if isinstance(o, date):
return str(o)
if isinstance(o, object):
if hasattr(o, "serialize"):
return o.serialize()