feat: lyrics for youtube music
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -3,7 +3,7 @@ from pathlib import Path
|
||||
import json
|
||||
import logging
|
||||
import inspect
|
||||
from typing import List
|
||||
from typing import List, Union
|
||||
|
||||
from .shared import DEBUG, DEBUG_LOGGING, DEBUG_DUMP, DEBUG_TRACE, DEBUG_OBJECT_TRACE, DEBUG_OBJECT_TRACE_CALLSTACK
|
||||
from .config import config, read_config, write_config
|
||||
@@ -77,6 +77,37 @@ def object_trace(obj):
|
||||
misc functions
|
||||
"""
|
||||
|
||||
def traverse_json_path(data, path: Union[str, List[str]], default=None):
|
||||
"""
|
||||
Path parts are concatenated with . or wrapped with [""] for object keys and wrapped in [] for array indices.
|
||||
"""
|
||||
|
||||
if isinstance(path, str):
|
||||
path = path.replace('["', '.').replace('"]', '.').replace("[", ".").replace("]", ".")
|
||||
path = [p for p in path.split(".") if len(p) > 0]
|
||||
|
||||
if len(path) <= 0:
|
||||
return data
|
||||
|
||||
current = path[0]
|
||||
path = path[1:]
|
||||
|
||||
new_data = None
|
||||
|
||||
if isinstance(data, dict):
|
||||
new_data = data.get(current)
|
||||
|
||||
elif isinstance(data, list):
|
||||
try:
|
||||
new_data = data[int(current)]
|
||||
except (IndexError, ValueError):
|
||||
pass
|
||||
|
||||
if new_data is None:
|
||||
return default
|
||||
|
||||
return traverse_json_path(data=new_data, path=path, default=default)
|
||||
|
||||
_auto_increment = 0
|
||||
def generate_id() -> int:
|
||||
global _auto_increment
|
||||
|
||||
Reference in New Issue
Block a user