inspiredminds / contao-youtube-sync
Contao extension to synchronize a contao news archive with a YouTube playlist.
Fund package maintenance!
fritzmg
Installs: 1 215
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 5
Forks: 1
Type:contao-bundle
Requires
- php: >=7.1
- contao/core-bundle: ^4.9 || ^5.0
- contao/news-bundle: ^4.9 || ^5.0
- doctrine/dbal: ^2.11 || ^3.0
- google/apiclient: ^2.0
- guzzlehttp/guzzle: ^6.0 || ^7.0
- symfony/config: ^4.4 || ^5.1 || ^6.0
- symfony/dependency-injection: ^4.4 || ^5.1 || ^6.0
- symfony/event-dispatcher: ^4.4 || ^5.1 || ^6.0
- symfony/http-foundation: ^4.4 || ^5.1 || ^6.0
- symfony/http-kernel: ^4.4 || ^5.1 || ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16 || ^3.0
README
Contao YouTube Sync
This extension allows you to automatically import all videos of a YouTube playlist as news entries in Contao.
Configuration
First you need to obtain a Google API key.
- Go to console.developers.google.com and create a project, or use an existing one.
- Go to the API Library and search for YouTube Data API v3.
- Enable the YouTube Data API v3 for your project.
- Go to the Credentials of your project and choose Create Credentials ยป API key. You can also use an existing key.
- Copy the API key for later use.
After obtaining the API key it can be configured for the extension:
# config/config.yml contao_youtube_sync: developer_key: <YOUR-API-KEY>
Once this extension is installed, you will have additional options in the settings of your Contao news archives:
Enable the synchronisation and set the YouTube playlist ID from which to import videos as news entries. You also need to define a default author for the synchronised entries and a target directory for the downloaded thumbnail images. Optionally you can define whether new entries should be published by default or not and if already synchronised entries should always be updated (this will not update the alias or author).
Synchronisation
Synchronisation can be triggered in three ways:
- Cronjob: executed hourly.
- Command:
contao_youtube_sync:sync
- Back end: in the article overview, use the YouTube sync link in the global operations.
Events
Whenever a YouTube video is imported as a news article (or whenever a news article is updated), the following event will be dispatched:
InspiredMinds\ContaoYouTubeSync\Event\NewsYouTubeSyncEvent
This event lets you retrieve the \Contao\NewsModel
to be saved to the database, as well as the \Google_Service_YouTube_PlaylistItem
instance of the YouTube video. It also allows you to discard the news article (or the changes added to it) by setting $event->setDiscard(true)
.
Templates
There will be two additional variables available within a news template:
$this->youtube_id
: This will contain the video ID of the YouTube video, if the news article was imported from a YouTube playlist.$this->youtube_data
: This is an object containing the original data of the video from the Google YouTube API.
The extension also provides a basic news_youtube
template, which can be used instead of the news_full
template for the newsreader of YouTube videos. The template contains markup to show the YouTube video embedded in an iframe.