Skip to content

feat: Robust Date Guessing, API Fixes, and Project Modernization#2

Merged
Adios merged 3 commits intomainfrom
feat/date-guessing
Nov 10, 2025
Merged

feat: Robust Date Guessing, API Fixes, and Project Modernization#2
Adios merged 3 commits intomainfrom
feat/date-guessing

Conversation

@Adios
Copy link
Copy Markdown
Owner

@Adios Adios commented Nov 10, 2025

This Pull Request introduces significant improvements to the onsengo CLI tool, focusing on more accurate date handling, enhanced API robustness, and modernization of the project's development infrastructure.

Key Changes Included in this PR:

  1. Robust Chronological Date Guessing (feat(onsen)):

    • Problem Addressed: The previous date guessing logic for onsen.ag episodes often resulted in incorrect year assignments, especially for programs spanning multiple years.
    • Solution Implemented: A new hybrid, chained chronological guessing mechanism has been implemented. This approach first "anchors" the date guess using YYYYMM from the streaming_url of the newest episodes. Subsequent older episodes' dates are then guessed chronologically,
      using the previously determined episode's date as a reference. This ensures strict chronological order and correct year assignment.
    • Impact: Greatly improves the accuracy of delivery_date for all episodes, providing more reliable information to users.
  2. API Robustness for poster_image_url (fix(onsen)):

    • Problem Addressed: The onsen.ag API occasionally returns a numeric type for poster_image_url instead of the expected string, causing JSON unmarshaling errors.
    • Solution Implemented: The PosterImageUrl field in the Content struct (within onsen/nuxt/nuxt.go) has been changed to interface{}. The Episode.Poster() method (onsen/onsen.go) now uses a type switch to gracefully handle both string and numeric values, preventing crashes
      and ensuring correct URL extraction.
    • Impact: Increases the tool's resilience to API inconsistencies, making it more stable.
  3. Project Modernization (chore(deps, ci)):

    • Go Version Update: The project's Go version in go.mod has been upgraded from 1.16 to 1.22, bringing performance improvements, new language features, and better security. go.sum has been updated accordingly.
    • GitHub Actions Workflows: Both deploy.yml and go.yml workflows have been updated to use the latest actions/checkout@v4, actions/setup-go@v5, and go-version: '1.22'. The deploy.yml also now uses softprops/action-gh-release@v2 for improved release management.
    • Impact: Ensures the project leverages modern Go features and maintains efficient, secure, and up-to-date CI/CD pipelines.

This Pull Request collectively enhances the onsengo CLI tool's functionality, stability, and maintainability.

The `onsen.ag` API has been observed to return a numeric type for the `poster_image_url` field in some cases, instead of the expected string. This caused JSON unmarshaling to fail when the corresponding struct field was strictly typed as `string`.

This commit addresses the issue by:
1.  Changing the type of `PosterImageUrl` in the `onsen/nuxt/nuxt.go` `Content` struct to `interface{}`. This allows the JSON to be decoded successfully regardless of whether the value is a string or a number.
2.  Updating the `Episode.Poster()` method in `onsen/onsen.go` with a type switch to safely handle the different possible types of `PosterImageUrl`. It now correctly processes both string and numeric values, returning an empty string for any other unexpected types.

This change makes the program more resilient to inconsistencies in the API's data format, preventing crashes and ensuring poster URLs are processed correctly.
The date guessing logic has been significantly improved to correctly handle programs spanning multiple years. The previous implementation led to incorrect year assignments for older episodes.

This commit introduces a hybrid, chained chronological guessing mechanism:
- For each radio program, it first attempts to find a reliable "anchor" date by parsing the `streaming_url` of the newest episodes.
- This anchor (or a global default) is used as a starting point.
- A "chained" guessing logic is then applied, where each episode's date is guessed using the previously determined episode's date as a reference, ensuring strict chronological order.

Changes include:
- The `Episode` struct now holds a `GuessedDate` to store the corrected time.
- `Radio.Episodes()` contains the new guessing logic.
- `Radio.JstUpdatedAt()` was updated to use the corrected date of the latest episode, ensuring the parent "directory" shows a consistent date.
- The test server in `cmd/cmd_test.go` was made more robust with proper error handling and resource cleanup.
- A test case for `lsm` was updated to verify the new logic.
This commit modernizes the project's Go toolchain and updates the GitHub Actions workflows to use the latest versions and best practices.

**Go Version Update:**
- The project's Go version in `go.mod` has been updated from `1.16` to `1.22`. This brings the project to a currently supported Go release, benefiting from performance improvements, new language features, and security updates.
- The `go.sum` file has been updated accordingly by `go mod tidy` to reflect the new dependency graph compatible with Go `1.22`.

**GitHub Actions Workflow Updates:**
- Both `.github/workflows/deploy.yml` and `.github/workflows/go.yml` have been updated:
    - `actions/checkout` was upgraded from `v2` to `v4`.
    - `actions/setup-go` was upgraded from `v2` to `v5`.
    - The `go-version` in both workflows was set to `1.22`, aligning with the `go.mod` file.
- For the deployment workflow (`deploy.yml`):
    - `softprops/action-gh-release` was upgraded from `v1` to `v2`.
    - The explicit `GITHUB_TOKEN` environment variable was removed, as `v2` of the action handles this automatically.

These updates ensure the project's CI/CD pipelines are running on modern, secure, and efficient versions of Go and GitHub Actions.
@Adios Adios merged commit 8f712aa into main Nov 10, 2025
1 check passed
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.

1 participant