implemented objects standard in deezloader

This commit is contained in:
Xoconoch
2025-06-11 09:09:59 -06:00
parent ed8f41d45f
commit 3debf689f2
8 changed files with 1407 additions and 1647 deletions

View File

@@ -150,6 +150,22 @@ class ProgressReporter:
# }
#
def _remove_nulls(data):
"""
Recursively remove null values from dictionaries and lists.
Args:
data: Any Python data structure (dict, list, etc.)
Returns:
The same structure with null values removed
"""
if isinstance(data, dict):
return {k: _remove_nulls(v) for k, v in data.items() if v is not None}
elif isinstance(data, list):
return [_remove_nulls(item) for item in data if item is not None]
return data
def report_progress(
reporter: Optional["ProgressReporter"],
callback_obj: Union[trackCallbackObject, albumCallbackObject, playlistCallbackObject]
@@ -165,8 +181,9 @@ def report_progress(
if not isinstance(callback_obj, (trackCallbackObject, albumCallbackObject, playlistCallbackObject)):
raise TypeError(f"callback_obj must be of type trackCallbackObject, albumCallbackObject, or playlistCallbackObject, got {type(callback_obj)}")
# Convert the callback object to a dictionary and report it
report_dict = asdict(callback_obj)
# Convert the callback object to a dictionary and filter out null values
report_dict = _remove_nulls(asdict(callback_obj))
if reporter:
reporter.report(report_dict)
else:

View File

@@ -164,6 +164,13 @@ def apply_custom_format(format_str, metadata: dict, pad_tracks=True) -> str:
# Original non-indexed placeholder logic (for %album%, %title%, %artist%, %ar_album%, etc.)
value = metadata.get(full_key, '')
# Handle None values safely
if value is None:
if full_key in ['tracknum', 'discnum']:
value = '1' if full_key == 'discnum' else '0'
else:
value = ''
if full_key == 'year' and value:
if isinstance(value, datetime):
return str(value.year)