diff --git a/README.md b/README.md index ff77ccd..6079c04 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,7 @@ As of version 3.x, EmbedVideo supports embedding video content from the followin | Site | Service Name(s) | ID Example | URL Example(s) | |----------------------------------------------------------|---------------------------------|--------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------| | [Archive.org Videos](https://archive.org/details/movies) | `archiveorg` | electricsheep-flock-244-80000-6 | https://archive.org/details/electricsheep-flock-244-80000-6
https://archive.org/embed/electricsheep-flock-244-80000-6 | +| [Bandcamp](https://bandcamp.com/) | `bandcamp` | 1003592798 | https://emptyhousesmusic.bandcamp.com/album/empty-houses (Click on share/embed, and copy the id after `album=`) | | [Bilibili](https://www.bilibili.com/) | `bilibili` | BV1Hz4y1k7ae | https://player.bilibili.com/player.html?bvid=1Hz4y1k7ae&page=1 | | [DailyMotion](https://dailymotion.com/) | `dailymotion` | x1adiiw_archer-waking-up-as-h-jon-benjamin_shortfilms | http://www.dailymotion.com/video/x1adiiw_archer-waking-up-as-h-jon-benjamin_shortfilms | | [KakaoTV](https://tv.kakao.com/) | `kakaotv` | 301157950 | https://play-tv.kakao.com/embed/player/cliplink/301157950 | diff --git a/includes/EmbedService/AbstractEmbedService.php b/includes/EmbedService/AbstractEmbedService.php index 19bc2ff..06e7205 100644 --- a/includes/EmbedService/AbstractEmbedService.php +++ b/includes/EmbedService/AbstractEmbedService.php @@ -189,6 +189,10 @@ abstract public function getBaseUrl(): string; * @return float|null */ public function getAspectRatio(): ?float { + if ( $this->width !== null && $this->height !== null ) { + return $this->width / $this->height; + } + return $this->getDefaultWidth() / $this->getDefaultHeight(); } diff --git a/includes/EmbedService/Bandcamp.php b/includes/EmbedService/Bandcamp.php new file mode 100644 index 0000000..4a9e978 --- /dev/null +++ b/includes/EmbedService/Bandcamp.php @@ -0,0 +1,89 @@ +urlArgs ) ) { + // phpcs:ignore Generic.Files.LineLength.TooLong + return '//bandcamp.com/EmbeddedPlayer/album=%1$s/size=large/bgcol=181a1b/linkcol=056cc4/artwork=small/transparent=true/'; + } + + return '//bandcamp.com/EmbeddedPlayer/album=%1$s/'; + } + + /** + * @inheritDoc + */ + public function getUrl(): string { + if ( $this->getUrlArgs() !== false ) { + unset( $this->urlArgs['autoplay'] ); + + $args = array_shift( $this->urlArgs ); + return sprintf( '%s&%s', sprintf( $this->getBaseUrl(), $this->getId() ), $args ?? '' ); + } + + return parent::getUrl(); + } + + /** + * @inheritDoc + */ + protected function getUrlRegex(): array { + return [ + '#bandcamp\.com\/EmbeddedPlayer\/album=(\d+)(?:[\/\w=]+)?#is', + ]; + } + + /** + * @inheritDoc + */ + protected function getIdRegex(): array { + return [ + '#(?:album=)?(\d+)(?:[\/\w=]+)?#is', + ]; + } + + /** + * @inheritDoc + */ + public function getPrivacyPolicyUrl(): ?string { + return 'https://bandcamp.com/privacy'; + } + + /** + * @inheritDoc + */ + public function getCSPUrls(): array { + return [ + 'https://bandcamp.com', + ]; + } + + /** + * @inheritDoc + */ + public function getContentType(): ?string { + return 'audio'; + } +} diff --git a/includes/EmbedService/EmbedServiceFactory.php b/includes/EmbedService/EmbedServiceFactory.php index b1f71b9..69b0ceb 100644 --- a/includes/EmbedService/EmbedServiceFactory.php +++ b/includes/EmbedService/EmbedServiceFactory.php @@ -25,6 +25,7 @@ final class EmbedServiceFactory { */ private static $availableServices = [ ArchiveOrg::class, + Bandcamp::class, Bilibili::class, Ccc::class, DailyMotion::class, @@ -61,6 +62,9 @@ public static function newFromName( string $serviceName, string $id ): AbstractE case 'archive.org': return new ArchiveOrg( $id ); + case 'bandcamp': + return new Bandcamp( $id ); + case 'bilibili': case 'player.bilibili': return new Bilibili( $id );