wmrsp/bluebillywig-youtube-importer

Composer 包,允许您轻松地将YouTube频道中的视频导入到Blue Billywig VMS出版物。

1.1.1 2019-04-03 14:20 UTC

This package is auto-updated.

Last update: 2024-09-29 05:29:30 UTC


README

Composer 包,允许您轻松地将YouTube频道中的视频导入到Blue Billywig VMS出版物。

注意

所有视频都必须公开可访问。

免责声明

youtube-dl不使用YouTube API,而是抓取网页以从YouTube视频收集数据。这可能导致youtube-dl或此包未提前通知而停止工作。

入门

要求

此包在底层使用命令行软件youtube-dl。为了使用此包,此软件必须在您的计算机上安装。在此处遵循这些说明来安装youtube-dl。

为了与Blue Billywig API通信,需要一个共享密钥。可以通过访问https://YourPublication.bbvms.com/ovp/#/publication/api-keys(其中YourPublication需要替换为您的出版物名称)并点击创建新密钥来生成共享密钥。

为什么使用youtube-dl?为什么不直接使用YouTube API?

为了与YouTube API通信,需要一个特殊的API密钥。为了获取此类密钥,需要创建一个Google帐户,在开发者控制台内部创建一个项目,然后遵循一些详细的说明。此外,只能使用此密钥免费发送一定数量的请求。

由于涉及安全风险以及可以使用YouTube API密钥进行的API调用数量有限,因此无法将YouTube API密钥包含在此包中。

由于强迫您创建Google帐户并跳过各种步骤以创建YouTube API密钥非常麻烦,因此此包使用youtube-dl。是的,这确实需要您在计算机上安装额外的软件,但与Google帐户相比,安装和删除它要容易得多。此外,youtube-dl不仅支持YouTube,还支持数百个其他网站

总的来说,youtube-dl是从您YouTube频道的视频收集信息的一个更灵活和更开放的解决方案。

用法

将bluebillywig-youtube-importer包含到您的项目中

在您的项目根目录中运行以下命令

composer require wmrsp/bluebillywig-youtube-importer

下载元数据

<?php

require dirname(__FILE__) . "/vendor/autoload.php";

use wmrsp\BlueBillywig\YouTubeImporter\Importer;

$youtube_url = "https://www.youtube.com/user/myawesomeusername";
$publication_name = "YourPublication";
$publication_shared_secret = "123-1234567890abcdefghijklmnopqrstuv";

$importer = new Importer($youtube_url, $publication_name, $publication_shared_secret);

$importer->downloadYouTube();

这将为您的YouTube频道/账户中的每个视频下载一个json文件。这些json文件包含有关YouTube视频的信息,其中包含特定视频的url。在下一步中,此url将被传递给Blue Billywig API,以便将视频导入到您的Blue Billywig VMS账户中。

视频导入到Blue Billywig VMS的顺序是json文件在下载文件夹../vendor/wmrsp/bluebillywig-youtube-importer/downloads中的顺序。

导入到Blue Billywig VMS

<?php

require dirname(__FILE__) . "/vendor/autoload.php";

use wmrsp\BlueBillywig\YouTubeImporter\Importer;

$youtube_url = "https://www.youtube.com/user/myawesomeusername";
$publication_name = "YourPublication";
$publication_shared_secret = "123-1234567890abcdefghijklmnopqrstuv";

$importer = new Importer($youtube_url, $publication_name, $publication_shared_secret);

// FALSE may be passed as a parameter to the 'importDownloads' method in order to skip the duplicates check.
// This check will make sure that the video to be imported has not already been imported into the Blue Billywig VMS before.
// In most cases TRUE would be the desired setting in order to prevent duplicate video's in your VMS environment.
$import_results = $importer->importDownloads(TRUE);

print_r($import_results);

这将从每个json文件中提取视频的url并将其传递给Blue Billywig API,后者将视频导入VMS。当一切设置完毕并完成后,导入结果将返回并保存在日志文件夹../vendor/wmrsp/bluebillywig-youtube-importer/logs中的日志文件中。

每次成功导入后,相应的json文件将从下载文件夹中删除。但是日志文件不会删除。它可能用于以后的参考。

请记住,为了防止Blue Billywig API过载,每个视频导入之间有一个30秒的超时时间。

完整示例

<?php

require dirname(__FILE__) . "/vendor/autoload.php";

use wmrsp\BlueBillywig\YouTubeImporter\Importer;

$youtube_url = "https://www.youtube.com/user/myawesomeusername";
$publication_name = "YourPublication";
$publication_shared_secret = "123-1234567890abcdefghijklmnopqrstuv";

$importer = new Importer($youtube_url, $publication_name, $publication_shared_secret);

$importer->downloadYouTube();
// FALSE may be passed as a parameter to the 'importDownloads' method in order to skip the duplicates check.
// This check will make sure that the video to be imported has not already been imported into the Blue Billywig VMS before.
// In most cases TRUE would be the desired setting in order to prevent duplicate video's in your VMS environment.
$import_results = $importer->importDownloads(TRUE);

print_r($import_results);

检索导入结果

导入的每个视频的结果都会记录在日志文件中。可以使用Importer对象的getLogAsArray方法将这些结果从日志文件中检索出来,作为数组。

<?php

require dirname(__FILE__) . "/vendor/autoload.php";

use wmrsp\BlueBillywig\YouTubeImporter\Importer;

$youtube_url = "https://www.youtube.com/user/myawesomeusername";
$publication_name = "YourPublication";
$publication_shared_secret = "123-1234567890abcdefghijklmnopqrstuv";

$importer = new Importer($youtube_url, $publication_name, $publication_shared_secret);

$import_results = $importer->getLogAsArray();

print_r($import_results);

如果需要,可以通过传递DateTime对象实例到getLogAsArray方法,从日志文件中检索到一定日期之前(忽略该日期之前的所有导入结果)的导入结果。

<?php

require dirname(__FILE__) . "/vendor/autoload.php";

use wmrsp\BlueBillywig\YouTubeImporter\Importer;
use DateTime;

$youtube_url = "https://www.youtube.com/user/myawesomeusername";
$publication_name = "YourPublication";
$publication_shared_secret = "123-1234567890abcdefghijklmnopqrstuv";
$as_of_date = new DateTime("Monday last week");

$importer = new Importer($youtube_url, $publication_name, $publication_shared_secret);

$import_results = $importer->getLogAsArray($as_of_date);

print_r($import_results);

单元测试

要运行PHP单元测试,将tests/config.example.yaml复制到tests/config.yaml,并用适用于您的出版物的设置更新tests/config.yml

使用以下命令运行测试。

./vendor/bin/phpunit --bootstrap ./vendor/autoload.php ./vendor/wmrsp/bluebillywig-youtube-importer/tests/ImporterTest.php