gpt4 book ai didi

google-apps-script - 气体 : Blob upload to YouTube fails for most files

转载 作者:行者123 更新时间:2023-12-01 15:20:17 24 4
gpt4 key购买 nike

我正在尝试使用 Google Apps 脚本将文件从 Google Drive 上传到 YouTube。

我只成功上传了大约 2MB 的视频。

这样做的主要原因是互联网连接速度慢,有时上传不可靠,因此让 Google 云端硬盘处理更容易,但是将大于 25MB 的文件上传到 YouTube 就很难...

脚本需要从“资源”>“高级 Google 服务...”启用“YouTube 数据 API”

函数代码:

// Upload Google Drive file to youtube
function uploadFileToYouTube(file) {
var name = file.getName();
var size = file.getSize();
var type = file.getMimeType();
var blob = file.getBlob();
var access = file.getSharingAccess();
var yt_privacy;
// Attempt to preserve permissions from Drive
switch(access) {
case DriveApp.Access.PRIVATE:
yt_privacy = "private";
break;
case DriveApp.Access.ANYONE:
yt_privacy = "public";
break;
case DriveApp.Access.ANYONE_WITH_LINK:
yt_privacy = "unlisted";
break;
default:
yt_privacy = "private";
}
Logger.log("File: "+name+" Size: "+size+" Type: "+type+" Access: "+access+" YT privacy: "+yt_privacy);
// Actually upload to YouTube....
var vid_res = {
snippet: {
title: name,
description: "Uploaded from Google Drive\nOriginal size: "+size+"\nOriginal filename: "+name+"\nOriginal mime type: "+type,
},
status: {
privacyStatus: yt_privacy
}
}
try {
var yt_upload = YouTube.Videos.insert(vid_res,"snippet,status",blob);
Logger.log(yt_upload);
} catch (e) {
Logger.log('Error uploading: '+ name + " Message: " + e.message);
}
return yt_upload;
}

// Test function. Needs test.avi on your Google drive
function testUpload() {
var file = DriveApp.getFilesByName("test.avi").next();
uploadFileToYouTube(file);
}

日志:

[13-12-30 13:18:34:924 SAST] File: SUNP0017.avi Size: 35258368 Type: video/x-msvideo Access: ANYONE_WITH_LINK YT privacy: unlisted
[13-12-30 13:18:45:924 SAST] Error uploading: SUNP0017.avi Message: We're sorry, a server error occurred. Please wait a bit and try again.

执行记录:

[13-12-30 13:18:33:518 SAST] Starting execution
[13-12-30 13:18:33:527 SAST] DriveApp.getFilesByName([SUNP0017.avi]) [0 seconds]
[13-12-30 13:18:34:799 SAST] (class).next() [1.271 seconds]
[13-12-30 13:18:34:799 SAST] File.getName() [0 seconds]
[13-12-30 13:18:34:799 SAST] File.getSize() [0 seconds]
[13-12-30 13:18:34:799 SAST] File.getMimeType() [0 seconds]
[13-12-30 13:18:34:799 SAST] File.getBlob() [0 seconds]
[13-12-30 13:18:34:921 SAST] File.getSharingAccess() [0.121 seconds]
[13-12-30 13:18:34:924 SAST] Logger.log([File: SUNP0017.avi Size: 35258368 Type: video/x-msvideo Access: ANYONE_WITH_LINK YT privacy: unlisted, []]) [0 seconds]
[13-12-30 13:18:40:474 SAST] Blob.getBytes() [5.549 seconds]
[13-12-30 13:18:40:504 SAST] Blob.getContentType() [0 seconds]
[13-12-30 13:18:45:924 SAST] Logger.log([Error uploading: SUNP0017.avi Message: We're sorry, a server error occurred. Please wait a bit and try again., []]) [0 seconds]
[13-12-30 13:18:45:924 SAST] Execution succeeded [12.398 seconds total runtime]

记录较小的文件:(有效)

[13-12-30 13:19:59:720 SAST] File: SUNP0024.avi Size: 3964928 Type: video/x-msvideo Access: ANYONE_WITH_LINK YT privacy: unlisted
[13-12-30 13:20:01:579 SAST] {id=<removed>, etag="<removed>", status={publicStatsViewable=true, privacyStatus=unlisted, embeddable=true, uploadStatus=uploaded, license=youtube}, snippet={publishedAt=2013-12-30T11:20:00.000Z, title=SUNP0024.avi, channelId=<removed>, description=Uploaded from Google Drive
Original size: 3964928
Original filename: SUNP0024.avi
Original mime type: video/x-msvideo, categoryId=22, channelTitle=Gert van den Berg, thumbnails={default={url=<removed>}, high={url=<removed>}, medium={url=<removed>}}, liveBroadcastContent=none}, kind=youtube#video}

较小文件的成绩单:(有效)

[13-12-30 13:19:58:311 SAST] Starting execution
[13-12-30 13:19:58:320 SAST] DriveApp.getFilesByName([SUNP0024.avi]) [0 seconds]
[13-12-30 13:19:59:549 SAST] (class).next() [1.229 seconds]
[13-12-30 13:19:59:550 SAST] File.getName() [0 seconds]
[13-12-30 13:19:59:554 SAST] File.getSize() [0.002 seconds]
[13-12-30 13:19:59:558 SAST] File.getMimeType() [0.002 seconds]
[13-12-30 13:19:59:559 SAST] File.getBlob() [0 seconds]
[13-12-30 13:19:59:719 SAST] File.getSharingAccess() [0.157 seconds]
[13-12-30 13:19:59:721 SAST] Logger.log([File: SUNP0024.avi Size: 3964928 Type: video/x-msvideo Access: ANYONE_WITH_LINK YT privacy: unlisted, []]) [0 seconds]
[13-12-30 13:20:00:756 SAST] Blob.getBytes() [1.034 seconds]
[13-12-30 13:20:00:759 SAST] Blob.getContentType() [0 seconds]
[13-12-30 13:20:01:579 SAST] Logger.log([{id=<removed>, etag="<removed>", status={publicStatsViewable=true, privacyStatus=unlisted, embeddable=true, uploadStatus=uploaded, license=youtube}, snippet={publishedAt=2013-12-30T11:20:00.000Z, title=SUNP0024.avi, channelId=<removed>, description=Uploaded from Google Drive
Original size: 3964928
Original filename: SUNP0024.avi
Original mime type: video/x-msvideo, categoryId=22, channelTitle=Gert van den Berg, thumbnails={default={url=<removed>}, high={url=<removed>}, medium={url=<removed>}}, liveBroadcastContent=none}, kind=youtube#video}, []]) [0 seconds]
[13-12-30 13:20:01:579 SAST] Execution succeeded [3.26 seconds total runtime]

最佳答案

目前,这是不可能的。 API 中有 blob 限制。由于他们为此创建了不同的方式,因此最好的办法是创建一个 Python 或 PHP 脚本并执行它,而不是 Apps 脚本

关于google-apps-script - 气体 : Blob upload to YouTube fails for most files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20838563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com