使用Pydrive上传具有共享链接的视频,但无法处理 [英] Uploading a video with a shareable link using Pydrive but it doesn't process

查看:57
本文介绍了使用Pydrive上传具有共享链接的视频,但无法处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Pydrive上传具有共享链接的视频,但是当我尝试使用链接查看视频时,出现一条错误消息:无法处理该视频.

I'm trying to upload a video with a shareable link using Pydrive, but when I try to see the video using the link I get an error message: couldn't process the video.

我尝试使用小尺寸视频(7MB),并使用不同的格式,例如MP4,WEBM和MOV.但是我得到了同样的错误.我想知道您是否能帮助我.我真的很感激.

I've tried with a small size video (7MB) and using different formats, such as MP4, WEBM, and MOV. But I get the same error. I wonder if you could help me. I really appreciate it.

这是我的代码:

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谢谢):

I forgot to define the mimetype (@Tanaike thank you):

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

这篇关于使用Pydrive上传具有共享链接的视频,但无法处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆