YouTube Auto-Uploader — Vollautomatischer Video-Upload mit Google API

Python-gesteuerter Bulk-Uploader: MySQL-Video-Queue, Google OAuth2, Thumbnail-Upload und automatische Playlist-Erstellung

PythonGoogle API v3MySQLOAuth2pytube

📤 Videos automatisch auf YouTube hochladen

MySQL-Queue → Google API → YouTube. Vollautomatisch, kein manueller Upload nötig.

📞 02406 803 7603 ✉️ info@computerkumpel.de

📊 Projektübersicht

Dieses Python-Skript-Set automatisiert den kompletten YouTube-Upload-Workflow: Videos werden aus einer MySQL-Datenbank abgerufen (inkl. Titel, Beschreibung, Tags), via Google YouTube API v3 mit OAuth2-Authentifizierung hochgeladen, Thumbnails gesetzt und optional in Playlists organisiert. Ideal für Content-Pipelines und Bulk-Uploads.

🗄️
MySQL-Queue
Video-Metadaten (Titel, Beschreibung, Tags) in MySQL. Random-Auswahl aus created=1, uploaded=0 für gleichmäßige Verteilung.
🔐
OAuth2-Flow
Automatischer Google OAuth2-Login mit Token-Caching. Refresh-Token-Handling für dauerhaften Betrieb ohne Neueinloggen.
⬆️
Resumable Upload
Google API MediaFileUpload mit Chunked/Resumable-Mode. Abbruchsicher – große Videodateien kein Problem.
📋
Playlist-Auto
Nach Upload automatische Playlist-Erstellung oder Hinzufügen zu bestehenden Playlisten via Google API.

⚙️ Funktionsweise

1
🗄️

DB-Query

MySQL: SELECT aus Videos-Tabelle WHERE created=1 AND uploaded=0 ORDER BY RAND() LIMIT 1

2
🔐

OAuth2 Auth

Google OAuth2 mit token.json: Auto-Refresh bei Ablauf, Fallback auf Interactive-Login.

3
📤

API Upload

videos().insert() mit snippet (Titel, Tags) + status (public) + MediaFileUpload resumable.

4

DB-Update

MySQL UPDATE: ytID setzen, uploaded=1. Playlist via playlists().insert() erstellen.

💻 Quellcode

Haupt-Routine: DB → OAuth → Upload

import pymysql
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from googleapiclient.http import MediaFileUpload
from playlist_ytvid import playlistYtvid
import os, datetime, random, schedule, time

def routine():
    conn = pymysql.connect(
        user='politik', password='DEIN_MYSQL_PASSWORT',
        host='localhost', database='euchannel')
    cursor = conn.cursor()
    cursor.execute("""
        SELECT mediaID, link, title, description, tags
        FROM Videos
        WHERE created = 1 AND uploaded = 0
        ORDER BY RAND() LIMIT 1""")
    row = cursor.fetchone()
    mediaID, link, title, description, tags = row

OAuth2 mit Token-Caching & Auto-Refresh

    creds = None
    if os.path.exists(TOKEN_NAME):
        creds = Credentials.from_authorized_user_file(
            TOKEN_NAME, SCOPES)
    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(
                client_secrets_file, SCOPES)
            creds = flow.run_console()
        with open(TOKEN_NAME, 'w') as token:
            token.write(creds.to_json())

    googleAPI = build('youtube', 'v3', credentials=creds)

Resumable Upload mit Metadaten

def uploadYtvid(VIDEO_FILE_NAME, title, description,
                tags, thumb, mediaID, googleAPI):
    request_body = {
        'snippet': {
            'categoryId': 27, 'title': title,
            'description': description, 'tags': tags,
            'playlistId': playlistID
        },
        'status': {
            'privacyStatus': 'public',
            'selfDeclaredMadeForKids': False
        },
        'notifySubscribers': False,
        'defaultLanguage': 'en',
        'embeddable': True,
        'license': 'youtube',
        'publicStatsViewable': True
    }
    mediaFile = MediaFileUpload(
        VIDEO_FILE_NAME, chunksize=-1, resumable=True)
    response = googleAPI.videos().insert(
        part='snippet,status',
        body=request_body,
        media_body=mediaFile).execute()
    return response.get('id')

Eigene YouTube-Upload-Automation?

Von MySQL-gesteuerten Upload-Queues bis zur vollautomatischen Content-Pipeline – ich entwickle Ihre maßgeschneiderte YouTube-Automationslösung.

📞 Jetzt anrufen ✉️ E-Mail senden