StarCitizenWiki / mediawiki-extensions-EmbedVideo

GDPR focused EmbedVideo. Supports YouTube, Twitch, Spotify and SoundCloud
https://www.mediawiki.org/wiki/Extension:EmbedVideo_(fork)
Other
27 stars 15 forks source link

Embed Service Request: VK video #104

Open aepot opened 1 month ago

aepot commented 1 month ago

Service Name VK video

URL to an example embed Direct URL: https://vk.com/video-183388314_456239065 Embed URL: https://vk.com/video_ext.php?oid=-183388314&id=456239065&hd=2

Additional notes VK video docs: https://dev.vk.com/en/widgets/video Privacy URL: https://vk.com/privacy

Note that Video ID constists of two numeric ids oid and id. Also any of them can be negative, so include a leading minus to the regexp which can be like (-?\d+)_(-?\d+)

Expected markup can be like {{#ev:vk|-183388314_456239065}}.

My try to implement just for consideration. I'm not a PHP programmer at all (don't trust my code).

<?php

declare( strict_types=1 );

namespace MediaWiki\Extension\EmbedVideo\EmbedService;

final class Vk extends AbstractEmbedService {
    /**
     * @inheritDoc
     */
    public function getBaseUrl(): string {
        return 'https://vk.com/video_ext.php?oid=%1$s&id=%2$s&hd=2';
    }

    /**
     * @inheritDoc
     */
    public function getUrl(): string {
        if ( $this->getUrlArgs() !== false ) {
            return sprintf( '%s&%s', sprintf( $this->getBaseUrl(), $this->getId(), ...$this->extraIds ), $this->getUrlArgs() );
        }

        return sprintf( $this->getBaseUrl(), $this->getId(), ...$this->extraIds );
    }

    /**
     * @inheritDoc
     */
    protected function getUrlRegex(): array {
        return [
            '#vk\.com/video(-?\d+)_(-?\d+)?#is',
        ];
    }

    /**
     * @inheritDoc
     */
    protected function getIdRegex(): array {
        return [
            '#(-?\d+)_(-?\d+)#is',
        ];
    }

    /**
     * @inheritDoc
     */
    public function getPrivacyPolicyUrl(): ?string {
        return 'https://vk.com/privacy';
    }

    /**
     * @inheritDoc
     */
    public function getCSPUrls(): array {
        return [
            'https://vk.com',
        ];
    }
}

Hovewer there's no easy way to get the thumbnail image using id of the video as it can be done for YouTube.