jikan-me / jikan

Unofficial MyAnimeList PHP+REST API which provides functions other than the official API
https://jikan.moe
MIT License
851 stars 94 forks source link

Youtube ID for trailer returns more than 11 characters #516

Closed ToshY closed 1 year ago

ToshY commented 1 year ago

Problem

Anime returns youtube id with 12 characters instead of 11.

Reproduction

Example 16904 gives yhNzL20gNX0/ instead of yhNzL20gNX0.

Cause

While the original embed URL (with additional /) does work, the regex does not take this into account that it should only be 11 characters for the id.

See this line in Media.php.

Possible fixes

Correct match for id, possible solutions:

  1. Change regex part ([^\?&\"'>]+) to ([^\?&\"'>]{11})
  2. Change statement for $matches[1] ?? null to empty($matches[1]) === false ? substr($matches[1], 0, 11) : null
ToshY commented 1 year ago

@irfan-dahir I can create a PR for this if you prefer one of the solutions I provided.