added converter for date range objects param
This commit is contained in:
parent
2e9c76a1f7
commit
b116d48da6
4 changed files with 19 additions and 1 deletions
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
|
@ -17,6 +17,7 @@
|
|||
"aiocron",
|
||||
"arrowless",
|
||||
"copyts",
|
||||
"daterange",
|
||||
"dotenv",
|
||||
"finaldir",
|
||||
"getpid",
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue