如何安排将视频上传到 YouTube 频道?

问题描述 投票:0回答:2

我尝试使用 Python 自动上传到我的 YT 频道。

故事是这样的:

我有一个频道,每天上传多次。但现在我即将上大学,除了周末我没有时间上传。

编辑不是问题,我想完成的是上传。但我不想在周日上传全部(比如)50 个视频,而在本周剩余时间则不上传。这种不一致不利于 YouTube 的增长。

所以我的计划是在周末集中编辑和制作所有这些视频,然后让脚本在整个星期内上传这些现成的视频,间隔相等,定期和重复,而无需我每次都告诉它(例如,每天两次或每天五次)。

我需要的工作流程如下

  1. 脚本从指定文件夹上传视频

  2. 使用预设数据(标题、描述、标签...)将视频发布到 YT

  3. (只有上传成功)将该视频移动到另一个 文件夹以避免重新上传并跟踪(我不想 删除它们以备以后需要)

  4. 每隔一定时间重复该过程

我一直在思考如何创建上面的工作流程, 但我不能。

python automation youtube
2个回答
0
投票

我有适合你的脚本,但无法在这里上传,哈哈。 进口时间表 您可以使用该库来调度功能(上传功能), 但你可以让你的程序一直运行。 或使用微软调度程序,它将安排您的整个程序。


0
投票

下面的Python代码将递归上传所有视频文件

raw_uploads_folder
,等待指定的时间间隔(
24
小时) 本例),然后重复该过程。确保更换 '
path/to/raw_uploads_folder
' 和 '
path/to/successful_uploads_folder
' 与您的实际路径 文件夹。根据您的情况调整 upload_interval_hours 变量 要求。

import os
import time
from bot_studio import *

def upload_video(video_path, title, description, tags, kid_type):
    # Initialize the YouTube bot
    youtube = bot_studio.youtube()

    # Login using cookies
    cookie_list = 'list of cookies'
    youtube.login_cookie(cookies=cookie_list)

    # Upload the video
    response = youtube.upload(title=title, video_path=video_path, kid_type=kid_type, description=description, tags=tags, type='Public')
    body = response['body']
    video_link = body['VideoLink']

    return video_link

def move_video(source_path, destination_path):
    # Move the video from source to destination folder
    os.rename(source_path, destination_path)

# Define folders
raw_uploads_folder = 'path/to/raw_uploads_folder'
successful_uploads_folder = 'path/to/successful_uploads_folder'

# Define video details
description = 'It displays how to upload video to youtube using datakund'
tags = ['upload', 'tutorial', 'datakund']
kid_type = "Yes, it's made for kids"

# Define the number of hours to wait between uploads
upload_interval_hours = 24  # Change this value as needed

while True:
    # Iterate through all files in raw_uploads_folder
    for root, dirs, files in os.walk(raw_uploads_folder):
        for file in files:
            # Upload each video file
            video_file = os.path.join(root, file)
            title = os.path.splitext(file)[0]  # Extract title from file name
            video_link = upload_video(video_file, title, description, tags, kid_type)

            # Move the uploaded video to successful_uploads_folder if upload was successful
            if video_link:
                move_video(video_file, os.path.join(successful_uploads_folder, file))

    # Wait for the specified interval before next upload
    time.sleep(upload_interval_hours * 3600)  # Convert hours to seconds
© www.soinside.com 2019 - 2024. All rights reserved.