Pyhton - Auto upload video pe youtube din folder

AlexH

Merg pe strada catre Mine...
Membru personal
Administrative
Freelancer
SEO Expert
Acest script face urmatoarele:

1. upload 6 video pe zi din folderul unde aveti video
2. seteaza din titlul hashtag si descriere
3. dupa ce este publicat cu succes, sterge video din folder.

Codul python:
Cod:
import os
import datetime
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
import googleapiclient.http

# Disable OAuthlib's HTTPs verification when running locally.
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "YOUR_CLIENT_SECRETS_FILE.json"
scopes = ["https://www.googleapis.com/auth/youtube.upload"]

# Get credentials and create an API client
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
    client_secrets_file, scopes)
credentials = flow.run_console()
youtube = googleapiclient.discovery.build(
    api_service_name, api_version, credentials=credentials)

def upload_video(file_name, title, description, category_id, keywords):
    body = {
        "snippet": {
            "categoryId": category_id,
            "title": title,
            "description": description,
            "tags": keywords
        },
        "status": {
            "privacyStatus": "public"
        }
    }

    # Call the API's videos.insert method to create and upload the video.
    media_file = googleapiclient.http.MediaFileUpload(file_name)
    request = youtube.videos().insert(
        part="snippet,status",
        body=body,
        media_body=media_file
    )
    response = request.execute()

    print(f"Video uploaded. Video ID: {response['id']}")

def main():
    video_folder = "/path/to/your/video/folder"
    videos_uploaded_today = 0
    max_uploads_per_day = 6

    for filename in os.listdir(video_folder):
        if videos_uploaded_today >= max_uploads_per_day:
            break
        if filename.endswith(".mp4"):
            file_path = os.path.join(video_folder, filename)
            title = os.path.splitext(filename)[0]
            description = f"{title} uploaded via API"
            category_id = "22"  # Choose appropriate category ID
            keywords = ["keyword1", "keyword2"]  # Customize your keywords

            upload_video(file_path, title, description, category_id, keywords)
            os.remove(file_path)
            videos_uploaded_today += 1
            print(f"Uploaded and deleted {filename}")

if __name__ == "__main__":
    main()


YOUR_CLIENT_SECRETS_FILE.json gasiti in consola de api de la google
La Authorized redirect URIs puneti http://localhost:8080/


Spor la urcat.
 
Loading...
Back
Sus