在过去的几周里,我和我的同事一直致力于通过 v3 API 为我们客户的 YouTube 视频获取字幕。大约一周后,我们终于能够顺利上传字幕,但是 YouTube 会在 UI 中给我们这条消息“未处理轨道内容”,并且不显示我们上传的字幕.但是,我们可以下载上传的原始格式;所以我们知道文件已成功上传。
我们还能够让同步标志起作用,告诉 YouTube 运行脚本并为视频设置时间,但它实际上不起作用。它返回告诉我们它正在同步,但是当我们转到视频的 UI 时,它只显示字幕轨道名称并给我们消息“轨道内容未处理。”。我们已经用完了所有的时间,现在我们正在用自己的时间来解决这个问题,但仍然没有成功。
有没有人遇到过这个问题?如果是这样,你能做些什么来让它发挥作用?
我将在下面发布我的代码片段,其中显示了我们脚本的上传部分。
# Insert a video caption.
# Create a caption snippet with video id, language, name and draft status.
$captionSnippet = new Google_Service_YouTube_CaptionSnippet();
$captionSnippet->setVideoId($videoId);
$captionSnippet->setLanguage($captionLanguage);
$captionSnippet->setName($captionName);
$captionSnippet->setIsDraft( true );
# Create a caption with snippet.
$caption = new Google_Service_YouTube_Caption();
$caption->setSnippet($captionSnippet);
// Setting the defer flag to true tells the client to return a request which can be called
$client->setDefer(false);
// Get the file content's of the uploaded file
$file = file_get_contents( $captionFile['tmp_name'] );
// Create a request for the API's captions.insert method to create and upload a caption.
$insertRequest = $youtube->captions->insert("snippet", $caption, array(
'sync' => true,
'data' => $file,
'mimeType' => 'application/octet-stream',
'uploadType' => 'multipart' )
);
echo '<pre>'; print_r( $insertRequest ); echo '</pre>';
// // Read the caption file and upload it chunk by chunk.
$status = $insertRequest;
fclose($handle);
// If you want to make other calls after the file upload, set setDefer back to false
$client->setDefer(false);
谢谢你,
泰勒·斯坦豪斯
最佳答案
您是否尝试过使用 Google 自己发布的功能来实现您想要的功能?
以下摘自 https://developers.google.com/youtube/v3/code_samples/php
/**
* Uploads a caption track in draft status that matches the API request parameters.
* (captions.insert)
*
* @param Google_Service_YouTube $youtube YouTube service object.
* @param Google_Client $client Google client.
* @param $videoId the YouTube video ID of the video for which the API should
* return caption tracks.
* @param $captionLanguage language of the caption track.
* @param $captionName name of the caption track.
* @param $captionFile caption track binary file.
* @param $htmlBody html body.
*/
function uploadCaption(Google_Service_YouTube $youtube, Google_Client $client, $videoId,
$captionFile, $captionName, $captionLanguage, &$htmlBody) {
# Insert a video caption.
# Create a caption snippet with video id, language, name and draft status.
$captionSnippet = new Google_Service_YouTube_CaptionSnippet();
$captionSnippet->setVideoId($videoId);
$captionSnippet->setLanguage($captionLanguage);
$captionSnippet->setName($captionName);
# Create a caption with snippet.
$caption = new Google_Service_YouTube_Caption();
$caption->setSnippet($captionSnippet);
// Specify the size of each chunk of data, in bytes. Set a higher value for
// reliable connection as fewer chunks lead to faster uploads. Set a lower
// value for better recovery on less reliable connections.
$chunkSizeBytes = 1 * 1024 * 1024;
// Setting the defer flag to true tells the client to return a request which can be called
// with ->execute(); instead of making the API call immediately.
$client->setDefer(true);
// Create a request for the API's captions.insert method to create and upload a caption.
$insertRequest = $youtube->captions->insert("snippet", $caption);
// Create a MediaFileUpload object for resumable uploads.
$media = new Google_Http_MediaFileUpload(
$client,
$insertRequest,
'*/*',
null,
true,
$chunkSizeBytes
);
$media->setFileSize(filesize($captionFile));
// Read the caption file and upload it chunk by chunk.
$status = false;
$handle = fopen($captionFile, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
// If you want to make other calls after the file upload, set setDefer back to false
$client->setDefer(false);
$htmlBody .= "<h2>Inserted video caption track for</h2><ul>";
$captionSnippet = $status['snippet'];
$htmlBody .= sprintf('<li>%s(%s) in %s language, %s status.</li>',
$captionSnippet['name'], $status['id'], $captionSnippet['language'],
$captionSnippet['status']);
$htmlBody .= '</ul>';
}
关于PHP:带有同步标志的 YouTube v3 API 字幕上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31408873/
我发现ActiveRecord::Base.transaction在复杂方法中非常有效。我想知道是否可以在如下事务中从AWSS3上传/删除文件:S3Object.transactiondo#writeintofiles#raiseanexceptionend引发异常后,每个操作都应在S3上回滚。S3Object这可能吗?? 最佳答案 虽然S3API具有批量删除功能,但它不支持事务,因为每个删除操作都可以独立于其他操作成功/失败。该API不提供任何批量上传功能(通过PUT或POST),因此每个上传操作都是通过一个独立的API调用完成的
我有用于控制用户任务的Rails5API项目,我有以下错误,但并非总是针对相同的Controller和路由。ActionController::RoutingError:uninitializedconstantApi::V1::ApiController我向您描述了一些我的项目,以更详细地解释错误。应用结构路线scopemodule:'api'donamespace:v1do#=>Loginroutesscopemodule:'login'domatch'login',to:'sessions#login',as:'login',via::postend#=>Teamroutessc
我有带有Logo图像的公司模型has_attached_file:logo我用他们的Logo创建了许多公司。现在,我需要添加新样式has_attached_file:logo,:styles=>{:small=>"30x15>",:medium=>"155x85>"}我是否应该重新上传所有旧数据以重新生成新样式?我不这么认为……或者有什么rake任务可以重新生成样式吗? 最佳答案 参见Thumbnail-Generation.如果rake任务不适合你,你应该能够在控制台中使用一个片段来调用重新处理!关于相关公司
我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt
文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co
我正在使用Mandrill的RubyAPIGem并使用以下简单的测试模板:testastic按照Heroku指南中的示例,我有以下Ruby代码:require'mandrill'm=Mandrill::API.newrendered=m.templates.render'test-template',[{:header=>'someheadertext',:main_section=>'Themaincontentblock',:footer=>'asdf'}]mail(:to=>"JaysonLane",:subject=>"TestEmail")do|format|format.h
文章目录1.开发板选择*用到的资源2.串口通信(个人理解)3.代码分析(注释比较详细)1.主函数2.串口1配置3.串口2配置以及中断函数4.注意问题5.源码链接1.开发板选择我用的是STM32F103RCT6的板子,不过代码大概在F103系列的板子上都可以运行,我试过在野火103的霸道板上也可以,主要看一下串口对应的引脚一不一样就行了,不一样的就更改一下。*用到的资源keil5软件这里用到了两个串口资源,采集数据一个,串口通信一个,板子对应引脚如下:串口1,TX:PA9,RX:PA10串口2,TX:PA2,RX:PA32.串口通信(个人理解)我就从串口采集传感器数据这个过程说一下我自己的理解,
我正在尝试使用Ruby2.0.0和Rails4.0.0提供的API从imgur中提取图像。我已尝试按照Ruby2.0.0文档中列出的各种方式构建http请求,但均无济于事。代码如下:require'net/http'require'net/https'defimgurheaders={"Authorization"=>"Client-ID"+my_client_id}path="/3/gallery/image/#{img_id}.json"uri=URI("https://api.imgur.com"+path)request,data=Net::HTTP::Get.new(path
使用rspec-rails3.0+,测试设置分为spec_helper和rails_helper我注意到生成的spec_helper不需要'rspec/rails'。这会导致zeus崩溃:spec_helper.rb:5:in`':undefinedmethod`configure'forRSpec:Module(NoMethodError)对thisissue最常见的回应是需要'rspec/rails'。但这是否会破坏仅使用spec_helper拆分rails规范和PORO规范的全部目的?或者这无关紧要,因为Zeus无论如何都会预加载Rails?我应该在我的spec_helper中做