Skip to content

Fix ISO 8601 timestamp conversion in preview generation#137

Open
tommasongr wants to merge 1 commit intoBenexl:masterfrom
tommasongr:patch-1
Open

Fix ISO 8601 timestamp conversion in preview generation#137
tommasongr wants to merge 1 commit intoBenexl:masterfrom
tommasongr:patch-1

Conversation

@tommasongr
Copy link
Copy Markdown

Hi everyone 👋

This PR solves an issue I was having with preview generation on macOS. Apparently the preview was failing due to some timestamp format mismatch between the YouTube API and the expected value on macOS.

To be fully transparent, the solution was one-shotted by Mistral AI. Looking at the resulted code I don't see obvious compatibility issues but I tested it on macOS only. Maybe someone should give it a try on other platforms before merging.

Here a rundown of the problem and solution.

Problem

The script fails to generate previews with the error:

"1772663922"` - "1772636400": syntax error: operand expected

This occurs because YouTube API returns timestamps in ISO 8601 format (e.g., "2024-09-15T12:34:56Z"), but the script tries to perform arithmetic directly on these string values.

Solution

Added cross-platform timestamp conversion that:

  1. Properly converts ISO 8601 timestamps to Unix timestamps
  2. Uses platform-appropriate date command syntax. macOS: date -j -f "%Y-%m-%dT%H:%M:%SZ" "timestamp" +%s. Linux/Other: date --date="timestamp" +%s
  3. Includes fallback to current time if conversion fails
  4. Fixes arithmetic syntax by removing unnecessary quotes

Replace timestamp extraction with ISO 8601 format conversion for better compatibility across platforms.
@arrietager
Copy link
Copy Markdown

If it helps, this works flawlessly. I just tested it because I was having the same issue. Thanks for solving it.

@Benexl
Copy link
Copy Markdown
Owner

Benexl commented Mar 8, 2026

it doesnt work on linux, in the else statement leave the value of timestamp as it originally was

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants