Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Conversation

@Np3ir
Copy link

@Np3ir Np3ir commented Jun 3, 2025

πŸ”§ Summary of Changes

This pull request includes two key improvements to enhance stability when handling edge cases in both date parsing and Deezer track metadata.


πŸ—“οΈ 1. Improved Date Parsing in str_to_datetime_obj()

Before:

def str_to_datetime_obj(d: str) -> datetime:
if d == "0000-00-00":
d = "1980-01-01"
return datetime.strptime(d, "%Y-%m-%d")

After:

def str_to_datetime_obj(d: str) -> datetime | None:
try:
if not d or d.strip() == "" or d.startswith("0000"):
logger.warning(f"[dates] Invalid date detected ('{d}'), defaulting to 1980-01-01.")
return datetime.strptime("1980-01-01", "%Y-%m-%d")
return datetime.strptime(d, "%Y-%m-%d")
except Exception as e:
logger.error(f"[dates] Error parsing date '{d}': {e}")
return None

Benefits:

  • Handles empty, null, and invalid date strings safely
  • Logs warnings and errors with context
  • Returns None instead of crashing

Note: Although the fix was applied in the deezer/utils.py dependency folder, it is required to prevent crashes caused by invalid API data. If this module is bundled in this repo, the patch ensures stability."

🎡 2. Safe Access to track['MEDIA'] in Deezer Track Mapping

Before:

result['preview'] = track['MEDIA'][0]['HREF']

After:

if 'MEDIA' in track and isinstance(track['MEDIA'], list) and len(track['MEDIA']) > 0:
result['preview'] = track['MEDIA'][0].get('HREF')
else:
result['preview'] = None

Benefits:

  • Prevents IndexError on empty or missing MEDIA lists
  • Uses .get() for safe dictionary access
  • Keeps the download process running even with incomplete track data

πŸ“Œ These changes improve fault tolerance and make the tool more reliable when interacting with Deezer.

Np3ir added 2 commits June 2, 2025 20:48
 Change Summary: Improved str_to_datetime_obj() for safer date parsing
Previous behavior:
The function only handled the specific case "0000-00-00" by replacing it with "1980-01-01". It did not handle other malformed or missing inputs and could raise exceptions without logging.

New behavior:
The updated version introduces input validation and exception handling:
   Handles None, empty strings, and any value starting with "0000"
   Logs a warning when an invalid date is found and defaults to "1980-01-01"
   Catches parsing errors and logs them as errors
   Returns None on failure

Benefits:
Prevents crashes from malformed or missing date strings
Adds meaningful logs for debugging
Improves reliability when consuming date data from external APIs
@tangsgod
Copy link

πŸ”§ Summary of Changes

This pull request includes two key improvements to enhance stability when handling edge cases in both date parsing and Deezer track metadata.

πŸ—“οΈ 1. Improved Date Parsing in str_to_datetime_obj()

Before:

def str_to_datetime_obj(d: str) -> datetime: if d == "0000-00-00": d = "1980-01-01" return datetime.strptime(d, "%Y-%m-%d")

After:

def str_to_datetime_obj(d: str) -> datetime | None: try: if not d or d.strip() == "" or d.startswith("0000"): logger.warning(f"[dates] Invalid date detected ('{d}'), defaulting to 1980-01-01.") return datetime.strptime("1980-01-01", "%Y-%m-%d") return datetime.strptime(d, "%Y-%m-%d") except Exception as e: logger.error(f"[dates] Error parsing date '{d}': {e}") return None

Benefits:

  • Handles empty, null, and invalid date strings safely
  • Logs warnings and errors with context
  • Returns None instead of crashing

Note: Although the fix was applied in the deezer/utils.py dependency folder, it is required to prevent crashes caused by invalid API data. If this module is bundled in this repo, the patch ensures stability."

🎡 2. Safe Access to track['MEDIA'] in Deezer Track Mapping

Before:

result['preview'] = track['MEDIA'][0]['HREF']

After:

if 'MEDIA' in track and isinstance(track['MEDIA'], list) and len(track['MEDIA']) > 0: result['preview'] = track['MEDIA'][0].get('HREF') else: result['preview'] = None

Benefits:

  • Prevents IndexError on empty or missing MEDIA lists
  • Uses .get() for safe dictionary access
  • Keeps the download process running even with incomplete track data

πŸ“Œ These changes improve fault tolerance and make the tool more reliable when interacting with Deezer.

Hi Np3ir,

Each time i run deemon refresh i have those errors, is it releated to the changes you suggest?
If not, could you help me with this?

:: Scanning release data for new releases... 62%
Traceback (most recent call last):
File "", line 198, in run_module_as_main
File "", line 88, in run_code
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Scripts\deemon.exe_main
.py", line 7, in
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon_main
.py", line 5, in main
cli.run()
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1157, in call
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon\cli.py", line 302, in refresh_command
refresh.run()
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon\cmd\refresh.py", line 250, in run
self.prep_payload(payload)
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon\cmd\refresh.py", line 202, in prep_payload
self.filter_artist_releases(p)
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon\cmd\refresh.py", line 84, in filter_artist_releases
release['future'] = self.is_future_release(release['release_date'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon\cmd\refresh.py", line 149, in is_future_release
release_date_dt = dates.str_to_datetime_obj(release_date)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon\utils\dates.py", line 40, in str_to_datetime_obj
return datetime.strptime(d, "%Y-%m-%d")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib_strptime.py", line 554, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib_strptime.py", line 520, in _strptime
julian = datetime_date(year, month, day).toordinal() -
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: year 0 is out of range

@tangsgod
Copy link

When changing the dates.py with yours, i have this errors :

PS C:\Users\tangs> deemon refresh
Traceback (most recent call last):
File "", line 198, in run_module_as_main
File "", line 88, in run_code
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Scripts\deemon.exe_main
.py", line 4, in
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon_main
.py", line 1, in
from deemon import cli
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon\cli.py", line 11, in
from deemon.cmd import download, rollback, backup, extra, tests, upgradelib
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon\cmd\download.py", line 17, in
from deemon.core import dmi, db, api, common
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon\core\dmi.py", line 19, in
from deemon.core.db import Database
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon\core\db.py", line 11, in
from deemon.utils import startup, performance, dates
File "C:\Users\tangs\AppData\Local\Programs\Python\Python312\Lib\site-packages\deemon\utils\dates.py", line 37
ddef str_to_datetime_obj(d: str) -> datetime | None:
^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax

@tangsgod
Copy link

I fixed the syntax erreor like this:

  • Open it in your Notepad and modify the line 37, from ddef to def (if noteyou will have a syntax error)

Thank you really much for this fix!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants