我正在尝试构建一个自动程序,以提醒我视频中是否有草稿字幕。最近,我的视频中添加了一些粗俗的字幕,但它们是作为草稿捕获的。
我以此示例为基础,但是当我尝试检查视频时,它仅提供已发布的视频字幕信息。我看了api文档,看来我也应该看到草稿状态的标题。
https://github.com/youtube/api-samples/blob/master/python/captions.py
def get_authenticated_service(args):
flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE, scope=YOUTUBE_READ_WRITE_SSL_SCOPE,
message=MISSING_CLIENT_SECRETS_MESSAGE)
storage = Storage("%s-oauth2.json" % sys.argv[0])
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = run_flow(flow, storage, args)
# Trusted testers can download this discovery document from the developers page
# and it should be in the same directory with the code.
with open("youtube-v3-api-captions.json", "r") as f:
doc = f.read()
return build_from_document(doc, http=credentials.authorize(httplib2.Http()))
# Call the API's captions.list method to list the existing caption tracks.
def list_captions(youtube, video_id):
results = youtube.captions().list(
part="snippet",
videoId=video_id
).execute()
for item in results["items"]:
id = item["id"]
name = item["snippet"]["name"]
language = item["snippet"]["language"]
print("Caption track '%s(%s)' in '%s' language." % (name, id, language))
return results["items"]
args = argparser.parse_args()
youtube = get_authenticated_service(args)
print(list_captions(youtube,"my-video"))
我希望print(list_captions(youtube,“ my-video”))将有关视频可用的所有字幕的信息打印到控制台,包括以不同语言处于草稿模式的字幕。我对其中一个视频进行了测试,希望以波兰语显示字幕草稿轨道,但只会显示英语和自动字幕:
Caption track '(XP6L39GAE3cGDethMwzyWkLZChESxt5MnCNokggzJnY=)' in 'ja' language.
Caption track '(zKBRyKIAn6BOtdpekvePw4qtM-_w7Jcv)' in 'en' language.
[{'kind': 'youtube#caption', 'etag': '"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/9AEECTD98uML9khnVlJ9I3nZyBk"', 'id': 'XP6L39GAE3cGDethMwzyWkLZChESxt5MnCNokggzJnY=', 'snippet': {'videoId': 'RYx1P_z9tNk', 'lastUpdated': '2019-02-20T09:07:56.247Z', 'trackKind': 'ASR', 'language': 'ja', 'name': '', 'audioTrackType': 'unknown', 'isCC': False, 'isLarge': False, 'isEasyReader': False, 'isDraft': False, 'isAutoSynced': False, 'status': 'serving'}}, {'kind': 'youtube#caption', 'etag': '"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/kxbjbXbUxo9fiHaH8bj_pUuttwg"', 'id': 'zKBRyKIAn6BOtdpekvePw4qtM-_w7Jcv', 'snippet': {'videoId': 'RYx1P_z9tNk', 'lastUpdated': '2019-02-20T16:43:48.873Z', 'trackKind': 'standard', 'language': 'en', 'name': '', 'audioTrackType': 'unknown', 'isCC': False, 'isLarge': False, 'isEasyReader': False, 'isDraft': False, 'isAutoSynced': False, 'status': 'serving'}}]
Caption track '(XP6L39GAE3cGDethMwzyWkLZChESxt5MnCNokggzJnY=)' in 'ja' language.
Caption track '(zKBRyKIAn6BOtdpekvePw4qtM-_w7Jcv)' in 'en' language.
有关字幕的屏幕截图存在于视频中: