gpt4 book ai didi

python - 如何更新播放列表中的所有 Youtube 视频描述?

转载 作者:太空狗 更新时间:2023-10-29 21:59:10 25 4
gpt4 key购买 nike

我已经创建了一个 client_secrets.json 文件并写入了我从 Google API 控制台获得的所有必填字段。现在我有一个测试播放列表,它对该播放列表中的所有视频都有相同的描述,我想通过使用 Python 代码更改它的描述来更新该播放列表。我已经从开发者谷歌提供的这个链接 https://developers.google.com/youtube/v3/docs/playlists/update#usage 复制了代码,现在我不知道是什么由于我是 Python 编程的新手,因此需要继续接下来的步骤。谁能指导我运行这个程序并更新播放列表描述。

提前致谢

这是我复制的代码

import os

import google.oauth2.credentials

import google_auth_oauthlib.flow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from google_auth_oauthlib.flow import InstalledAppFlow

CLIENT_SECRETS_FILE = "client_secrets.json"

SCOPES = ['https://www.googleapis.com/auth/youtube.force-ssl']
API_SERVICE_NAME = 'youtube'
API_VERSION = 'v3'

def get_authenticated_service():
flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)
credentials = flow.run_console()
return build(API_SERVICE_NAME, API_VERSION, credentials = credentials)

def print_response(response):
print(response)

def build_resource(properties):
resource = {}
for p in properties:
prop_array = p.split('.')
ref = resource
for pa in range(0, len(prop_array)):
is_array = False
key = prop_array[pa]

if key[-2:] == '[]':
key = key[0:len(key)-2:]
is_array = True

if pa == (len(prop_array) - 1):
if properties[p]:
if is_array:
ref[key] = properties[p].split(',')
else:
ref[key] = properties[p]
elif key not in ref:
ref[key] = {}
ref = ref[key]
else:
ref = ref[key]
return resource

def remove_empty_kwargs(**kwargs):
good_kwargs = {}
if kwargs is not None:
for key, value in kwargs.iteritems():
if value:
good_kwargs[key] = value
return good_kwargs

def playlists_update(client, properties, **kwargs):
resource = build_resource(properties)

kwargs = remove_empty_kwargs(**kwargs)

response = client.playlists().update(
body=resource,
**kwargs
).execute()

return print_response(response)


if __name__ == '__main__':
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
client = get_authenticated_service()

playlists_update(client,
{'id': '',
'snippet.title': '',
'snippet.description': '',
'snippet.tags[]': '',
'status.privacyStatus': ''},
part='snippet,status',
onBehalfOfContentOwner='')

最佳答案

我找不到直接的解决方案。但经过一些研究,我可以给你以下指示。

  1. 上述代码段仅用于管理播放列表数据,而不用于管理播放列表中的视频。您只能按照文档中的说明更改播放列表的数据。
  2. 您可以尝试以下几种方法来获得结果。
    • 尝试使用这些方法来代替 PlaylistItems获取播放列表中的项目,即视频。
    • 然后你可以使用Videos像您的案例描述中那样更改给定视频的属性。

在我看来 map 是这样的

  1. 从所需的播放列表中获取项目列表
  2. 遍历列表
  3. 选择每个视频并更新其数据

据我所知似乎没有直接的方法。

关于python - 如何更新播放列表中的所有 Youtube 视频描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49956100/

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