alaouy / YouTube

🔥 Laravel PHP Facade/Wrapper for the Youtube Data API
MIT License
782 stars 204 forks source link

Improvements: Shorts video ID parsing support #186

Open hasnat-we opened 1 year ago

hasnat-we commented 1 year ago

@alaouy Thanks for this awesome plugin. We need to support new YouTube shorts.

I am using following for only parsing ID and everything is working fine including shorts videos.

    /**
     * @param string|null $url
     * @return string|null
     */
    public static function getYouTubeVideoIDFromUrl(?string $url)
    {
        // See https://stackoverflow.com/a/71006865/3501553

        preg_match('/(youtu.*be.*)\/(watch\?v=|embed\/|v|shorts|)(.*?((?=[&#?])|$))/', $url, $matches);

        return ($matches[3] ?? null);
    }

I hope we can use this logic in \Alaouy\Youtube\Youtube::parseVidFromURL().

alaouy commented 1 year ago

@hasnat-we Yes absolutely, if you can include it in a PR I will happily merge it ;)

On Sat, Mar 18, 2023 at 3:49 PM Hasnat WE @.***> wrote:

@alaouy https://github.com/alaouy Thanks for this awesome plugin. We need to support new YouTube shorts.

I am using following for only parsing ID and everything is working fine including shorts videos.

/**
 * @param string|null $url
 * @return string|null
 */
public static function getYouTubeVideoIDFromUrl(?string $url)
{
    // See https://stackoverflow.com/a/71006865/3501553

    preg_match('/(youtu.*be.*)\/(watch\?v=|embed\/|v|shorts|)(.*?((?=[&#?])|$))/', $url, $matches);

    return ($matches[3] ?? null);
}

I hope we can use this logic in \Alaouy\Youtube\Youtube::parseVidFromURL().

— Reply to this email directly, view it on GitHub https://github.com/alaouy/Youtube/issues/186, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXZOKK2BH22KE4I72WTPITW4XDNXANCNFSM6AAAAAAV7QMU44 . You are receiving this because you were mentioned.Message ID: @.***>