You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Python API客户端设置YouTube上传视频的语言及相关选项

问题:通过YouTube Python API设置视频语言及其他上传选项

我正按照YouTube官方指南通过代码上传视频,当前使用的Python代码片段如下:

body=dict(
    snippet=dict(
      title=title,
      description=description,
      tags=tags,
    ),
    status=dict(
      privacyStatus="public"
    )
  )

目前已实现视频上传,可设置标题、描述和缩略图,"Made for kids"选项会继承频道默认,但视频语言无法继承频道默认,需要通过代码设置(网页端对应设置如图:上传语言设置)。同时希望通过代码设置以下网页端选项:

  • altered content
  • Allow automatic chapters and key moments
  • Allow automatic concepts
  • Don't allow remixing

更新

尝试在snippet中添加defaultLanguage="fr-FR",但仅设置了标题和描述的语言,未设置视频语言(效果如图:API设置后的语言状态),改用defaultLanguage="fr"结果相同。


解决方案

1. 设置视频语言(网页端的视频语言选项)

你之前设置的defaultLanguage是标题和描述的语言,而网页端显示的视频语言需要设置snippet中的defaultAudioLanguage字段,它对应视频音频的语言。调整后的代码示例:

body=dict(
    snippet=dict(
      title=title,
      description=description,
      tags=tags,
      defaultLanguage="fr-FR",  # 标题、描述的语言
      defaultAudioLanguage="fr-FR"  # 视频语言(对应网页端设置)
    ),
    status=dict(
      privacyStatus="public"
    )
  )

2. 设置其他网页端选项

以下是各选项对应的API字段设置:

  • Allow automatic chapters and key moments:对应status.autoChapters,设为"allowed"开启,"disallowed"关闭
  • Allow automatic concepts:对应status.autoConcepts,设为"allowed"开启,"disallowed"关闭
  • Don't allow remixing:对应status.remixSettings.remixType,设为"noRemix"即可禁止混音
  • altered content:网页端的“此视频包含修改过的内容”对应status.license字段,若视频为改编/修改内容,可设为"creativeCommon",默认原创内容为"youtube"

整合后的完整代码示例:

body=dict(
    snippet=dict(
      title=title,
      description=description,
      tags=tags,
      defaultLanguage="fr-FR",
      defaultAudioLanguage="fr-FR"
    ),
    status=dict(
      privacyStatus="public",
      autoChapters="allowed",  # 开启自动章节和关键节点
      autoConcepts="allowed",  # 开启自动概念
      license="creativeCommon",  # 标记为修改内容
      remixSettings=dict(
          remixType="noRemix"  # 禁止混音
      )
    )
  )

上传后修改选项

如果视频已上传完成,可调用videos.update接口修改这些字段,示例代码:

# 构建更新内容
update_body = dict(
    id="你的视频ID",
    snippet=dict(
        defaultAudioLanguage="fr-FR"
    ),
    status=dict(
        autoChapters="allowed",
        autoConcepts="allowed",
        remixSettings=dict(remixType="noRemix")
    )
)

# 执行更新
response = youtube.videos().update(
    part="snippet,status",
    body=update_body
).execute()

内容的提问来源于stack exchange,提问作者ginjaemocoes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 20:44:52