使用 Pydrive 上传具有可共享 link 的视频,但未处理

Uploading a video with a shareable link using Pydrive but it doesn't process

我正在尝试使用 Pydrive 上传带有可共享 link 的视频,但是当我尝试使用 link 查看视频时,我收到一条错误消息:无法处理视频。

我试过使用小尺寸视频 (7MB) 并使用不同的格式,例如 MP4、WEBM 和 MOV。但我得到了同样的错误。 我想知道你是否可以帮助我。非常感谢。

这是我的代码:

folderName = 'Videos'

folders = drive.ListFile({'q': "title='" + folderName + "' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList()
for folder in folders:
    if folder['title'] == folderName:
        folderId = folder['id']

import glob, os
os.chdir("C:/upload_recording/videos")
for file in glob.glob("*.webm"):
    with open(file,"r") as f:
        fn = os.path.basename(f.name)
        file_drive = drive.CreateFile({'title':fn,'parents': [{'id': folderId}], 'copyRequiresWriterPermission': True, 'writersCanShare': False})
        file_drive.Upload()
        file_drive.InsertPermission({
                        'type': 'anyone',
                        'value': 'anyone',
                        'role': 'reader'})
                               
files = drive.ListFile({"q": "'" + folderId + "' in parents and trashed=false"}).GetList()
for file in files:
    keys = file.keys()
    if file['shared'] and 'alternateLink' in keys:
        link = file['alternateLink']
    else:
        link = 'No Link Available. Check your sharing settings.'
        
    name = file['id']
    
    print('name: {}  link: {}'.format(name, link))

我忘了定义 mimetype(@Tanaike 谢谢):

drive.CreateFile({'title':fn, 'mimetype': 'video/mp4','parents': [{'id': folderId}], 'copyRequiresWriterPermission': True, 'writersCanShare': False})