Как я могу загрузить несколько видео с помощью YouTube API PythonPython

Программы на Python
Anonymous
Как я могу загрузить несколько видео с помощью YouTube API Python

Сообщение Anonymous »

Я пытаюсь использовать YouTube API в Python для загрузки нескольких видео, но постоянно получаю сообщение об ошибке, в котором говорится, что мой strong>Квота YouTube превышена. Первое видео загружается успешно, но последующие загрузки завершаются неудачно. Я ищу решение этой проблемы, чтобы можно было загружать несколько видео без перерывов.
Вот мой код

Код: Выделить всё

import os
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.errors import HttpError
import datetime
from datetime import timedelta
from googleapiclient.http import MediaFileUpload
import time
import random
import pytz

# Set up OAuth2 credentials
creds = None
if os.path.exists('token2.json'):
creds = Credentials.from_authorized_user_file('api/token2.json')
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file('api/youtube2.json', scopes=['https://www.googleapis.com/auth/youtube.force-ssl'])
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.json', 'w') as token_file:
token_file.write(creds.to_json())
with open('token.json', 'w') as token_file:
token_file.write(creds.to_json())

# Set up YouTube API client
youtube = build('youtube', 'v3', credentials=creds)

print('Youtube Api Logged In')

with open('title.txt', 'r') as f:
title = f.read().strip()

# Set your timezone
local_tz = pytz.timezone('Asia/Kolkata')

# Set the initial scheduled upload time to the current time plus 15 minutes
scheduled_time = datetime.datetime.now(local_tz) + timedelta(minutes=15)

print(f'Current time : {scheduled_time}')

videoFolder = 'videos'
titleNum = 1

for video_file in os.listdir(videoFolder):
if video_file.endswith('.mp4'):
# Create a new video object and set its attributes
video_path = os.path.join(videoFolder, video_file)
video = {
'snippet': {
'title': f'{title} - # {titleNum}',
'description': '',
'categoryId': '22',
'tags': ['tag1', 'tag2', 'tag3'],
'defaultLanguage': 'en'
},
'status': {
'privacyStatus': 'unlisted',
'selfDeclaredMadeForKids': False,
}
}

# Upload the video to YouTube
try:
response = youtube.videos().insert(
part='snippet,status',
body=video,
media_body=MediaFileUpload(video_path)
).execute()

video_id = response['id']
print(f'The video was uploaded with ID: {video_id}')

# Schedule the video to be published
publish_time = scheduled_time
update = {'id': video_id, 'status': {'publishAt': publish_time.strftime('%Y-%m-%dT%H:%M:%SZ'), 'privacyStatus': 'private'}}
youtube.videos().update(part='status', body=update).execute()

print(f'Video "{video_file}" scheduled for {scheduled_time.strftime("%Y-%m-%d %H:%M:%S")} IST')

except HttpError as error:
print(f'An HTTP error {error.resp.status} occurred: {error.content}')

# Increment the scheduled upload time by 15 minutes for the next video
scheduled_time += timedelta(minutes=15)
titleNum += 1
randInt = random.randint(4,10)
time.sleep(randInt)
Вот изображение, которое вы просили прокомментировать мою текущую квоту
Изображение

Ваша помощь будет очень много значить для меня, и я буду глубоко благодарен за любую поддержку, которую вы можете оказать. Заранее благодарим вас за вашу любезную помощь.

Подробнее здесь: https://stackoverflow.com/questions/757 ... api-python

Вернуться в «Python»