### PublishTaskScheduler Usage Example Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Demonstrates how to use the PublishTaskScheduler for managing video publishing tasks. Shows how to instantiate the scheduler, start it, enqueue new tasks, and cancel or retry existing tasks. Also includes examples of how to subscribe to task status and progress change events. ```csharp // 任务调度器核心功能 PublishTaskScheduler scheduler = new PublishTaskScheduler(dbContext); // 启动调度器 scheduler.Start(); // 添加任务到队列 long taskId = await scheduler.EnqueueAsync(publishTask); // 取消任务 await scheduler.CancelTaskAsync(taskId); // 重试失败任务 await scheduler.RetryTaskAsync(taskId); // 事件监听 scheduler.TaskStatusChanged += (s, e) => { /* 状态变更处理 */ }; scheduler.TaskProgressChanged += (s, e) => { /* 进度更新处理 */ }; ``` -------------------------------- ### Start WPF Desktop Application Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/docs/OpenClaw使用指南.md Navigate to the application's debug directory and run the executable to start the WPF desktop application. ```bash cd src/ShortVideo.AutoPublisher/bin/Debug/net8.0-windows ./ShortVideo.AutoPublisher.exe ``` -------------------------------- ### Start Scheduler via CLI Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/docs/OpenClaw使用指南.md Use the 'autopub scheduler start' command to begin the automated publishing process. ```bash autopub scheduler start ``` -------------------------------- ### AI Agent Usage Examples Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Examples of how to interact with the AutoPublisher tools through an AI Agent like Claude. ```text 用户: 帮我列出视频库中的所有视频 Claude: [调用 list_videos 工具] 用户: 把视频ID为1的视频发布到抖音 Claude: [调用 publish_video 工具,参数: video_id=1, platform="douyin"] 用户: 查看任务状态 Claude: [调用 list_tasks 工具] ``` -------------------------------- ### Scheduler Commands Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Commands to start and check the status of the task scheduler. ```bash # 启动调度器(前台运行) autopub scheduler start ``` ```bash # 查看调度器状态 autopub scheduler status ``` -------------------------------- ### Call AutoPublisher Tools in Claude Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/docs/OpenClaw使用指南.md Interact with the AutoPublisher through Claude by issuing commands like listing videos, publishing a specific video, or starting the scheduler. ```text 用户: 帮我列出视频库中的所有视频 用户: 把视频ID为1的视频发布到抖音 用户: 启动调度器开始发布 ``` -------------------------------- ### Run CLI from Output Directory Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Navigate to the CLI's output directory and execute the help command to see available options. ```bash # 从输出目录运行 cd src/ShortVideo.AutoPublisher.Cli/bin/Debug/net8.0-windows ./autopub.exe --help ``` -------------------------------- ### ShortVideo.AutoPublisher Project Structure Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Detailed breakdown of the project's directory structure, including the WPF desktop application, core libraries, CLI tools, and MCP server. ```text src/ ├── ShortVideo.AutoPublisher/ # WPF 桌面应用 │ ├── Core/ # 核心基础设施 │ │ └── Configuration/ # 应用配置管理 │ │ │ ├── Domain/ # 领域层 │ │ ├── Entities/ # 实体类 │ │ │ ├── VideoContent.cs # 视频内容 │ │ │ ├── PublishTask.cs # 发布任务 │ │ │ ├── CookieSession.cs # Cookie会话 │ │ │ └── CoverImage.cs # 封面图片 │ │ └── Enums/ # 枚举定义 │ │ ├── PlatformType.cs # 平台类型 │ │ └── PublishTaskStatus.cs # 任务状态 │ │ │ ├── Infrastructure/ # 基础设施层 │ │ ├── Data/ # 数据访问 │ │ │ ├── AppDbContext.cs # SQLite上下文 │ │ │ └── Repositories/ # 仓储实现 │ │ ├── Network/ # 网络服务 │ │ │ └── NetworkMonitor.cs # 网络状态监控 │ │ └── FileSystem/ # 文件系统 │ │ └── FileDownloader.cs # 大文件下载器 │ │ │ ├── OpenClaw/ # AI代理模块 │ │ ├── Abstractions/ # 抽象接口 │ │ │ └── IAiAgent.cs # AI代理接口 │ │ ├── Agents/ # 平台代理实现 │ │ │ ├── AgentBase.cs # 代理基类 │ │ │ ├── DouyinAgent.cs # 抖音代理 │ │ │ ├── XiaohongshuAgent.cs # 小红书代理 │ │ │ ├── BaijiahaoAgent.cs # 百家号代理 │ │ │ ├── WeixinChannelAgent.cs # 视频号代理 │ │ │ └── ToutiaoAgent.cs # 头条代理 │ │ ├── TaskScheduler/ # 任务调度 │ │ │ └── PublishTaskScheduler.cs # 任务调度器 │ │ └── Browser/ # 浏览器控制 │ │ └── BrowserManager.cs # Playwright管理器 │ │ │ ├── Services/ # 应用服务层 │ │ ├── VideoContentService.cs # 视频内容服务 │ │ ├── PublishService.cs # 发布服务 │ │ └── CookieSessionService.cs # Cookie会话服务 │ │ │ ├── ViewModels/ # 视图模型层 │ │ └── Pages/ │ │ ├── DashboardViewModel.cs # 仪表盘 │ │ ├── VideoManageViewModel.cs # 视频管理 │ │ ├── PublishTaskViewModel.cs # 发布任务 │ │ └── SettingsViewModel.cs # 系统设置 │ │ │ └── Views/ # 视图层 │ ├── Windows/ │ │ └── MainWindow.xaml # 主窗口 │ └── Pages/ │ ├── DashboardPage.xaml # 仪表盘页面 │ ├── VideoManagePage.xaml # 视频管理页面 │ ├── PublishTaskPage.xaml # 发布任务页面 │ ├── CookieSessionPage.xaml # 账号管理页面 │ └── SettingsPage.xaml # 设置页面 │ ├── ShortVideo.AutoPublisher.Core/ # 核心业务库(共享) │ ├── Domain/ # 领域层(共享) │ ├── Infrastructure/ # 基础设施层(共享) │ ├── OpenClaw/ # AI代理模块(共享) │ ├── Services/ # 服务层(共享) │ └── Core/ # 配置(共享) │ ├── ShortVideo.AutoPublisher.Cli/ # CLI 命令行工具 │ ├── Program.cs # 入口点 │ └── Commands/ # 命令实现 │ ├── VideoCommand.cs # 视频命令 │ ├── AccountCommand.cs # 账号命令 │ ├── PublishCommand.cs # 发布命令 │ ├── TaskCommand.cs # 任务命令 │ └── SchedulerCommand.cs # 调度器命令 │ └── ShortVideo.AutoPublisher.Mcp/ # MCP Server(AI Agent 集成) ├── Program.cs # MCP 入口点 └── Tools/ # MCP 工具 ├── VideoTools.cs # 视频工具 ├── AccountTools.cs # 账号工具 └── PublishTools.cs # 发布工具 ``` -------------------------------- ### Add Account via CLI Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/docs/OpenClaw使用指南.md Use the 'autopub account add' command to add a new account. Specify the platform, account name, and your cookie data. ```bash autopub account add -p douyin -n "我的账号" -c "你的cookie数据" ``` -------------------------------- ### Add Video via CLI Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/docs/OpenClaw使用指南.md Use the 'autopub video add' command to add a video to the library. Provide the video file path, title, and tags. ```bash autopub video add -f "D:/Videos/demo.mp4" -t "视频标题" --tags "测试,演示" ``` -------------------------------- ### Publishing Task Commands Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Commands for publishing videos to specified platforms, scheduling, and managing tasks. ```bash # 发布视频到指定平台 autopub publish -v -p douyin ``` ```bash # 发布到所有已配置平台 autopub publish -v --all ``` ```bash # 定时发布 autopub publish -v -p xiaohongshu -s "2026-04-01 10:00" ``` ```bash # 查看任务列表 autopub task list ``` ```bash # 按状态筛选 autopub task list -s failed ``` ```bash # 重试失败任务 autopub task retry ``` ```bash # 取消任务 autopub task cancel ``` -------------------------------- ### Video Management Commands Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Commands for listing, adding, viewing details, and deleting videos from the library. ```bash # 列出所有视频 autopub video list ``` ```bash # 添加视频 autopub video add -f "D:/Videos/demo.mp4" -t "视频标题" --tags "测试,演示" ``` ```bash # 查看视频详情 autopub video info ``` ```bash # 删除视频 autopub video delete ``` -------------------------------- ### appsettings.json Configuration for OpenClaw AI Agent Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/docs/OpenClaw使用指南.md This JSON configuration file sets up parameters for database, network, browser, and AI agent behavior in ShortVideo.AutoPublisher. Adjust these settings to control timeouts, retries, delays, and AI agent concurrency. ```json { "Database": { "FilePath": "Data/autopublisher.db" // SQLite 数据库路径 }, "Network": { "ConnectionTimeoutSeconds": 30, // 连接超时 "MaxRetries": 3, // 最大重试次数 "InitialRetryDelaySeconds": 1, // 初始重试延迟 "MaxRetryDelaySeconds": 30, // 最大重试延迟 "NetworkCheckIntervalSeconds": 5 // 网络检查间隔 }, "Browser": { "Headless": false, // 是否无头模式(调试时设为 false) "PageLoadTimeoutSeconds": 60, // 页面加载超时 "ActionTimeoutSeconds": 30, // 操作超时 "DefaultDelayMs": 1000, // 默认延迟 "MinDelayMs": 500, // 最小延迟 "MaxDelayMs": 2000 // 最大延迟 }, "Agent": { "EnableAiAgent": true, // 启用 AI 代理 "MaxConcurrentTasks": 3, // 最大并发任务数 "TaskQueueSize": 100, // 任务队列大小 "EnableAutoRetry": true, // 自动重试 "RetryCount": 3, // 重试次数 "RetryDelaySeconds": 5, // 重试延迟 "EnableAntiDetection": true // 反检测机制 } } ``` -------------------------------- ### Application Configuration Settings Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md The appsettings.json file contains configuration for database, network, browser, download, and logging settings. Adjust these values to suit your environment and requirements. ```json { "Database": { "FilePath": "Data/autopublisher.db" }, "Network": { "ConnectionTimeoutSeconds": 30, "MaxRetries": 3, "InitialRetryDelaySeconds": 1, "MaxRetryDelaySeconds": 30, "NetworkCheckIntervalSeconds": 5 }, "Browser": { "Headless": false, "PageLoadTimeoutSeconds": 60, "ActionTimeoutSeconds": 30, "DefaultDelayMs": 1000 }, "Download": { "MaxFileSizeBytes": 1073741824, "BufferSize": 81920, "EnableResume": true }, "Log": { "LogDirectory": "Logs", "MinimumLevel": "Information", "RetainedFileDays": 30 } } ``` -------------------------------- ### Implement New Platform Agent Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md To add support for a new platform, create a new agent class inheriting from AgentBase and implement the IAiAgent interface. Register the new agent in AgentFactory. ```csharp public class NewPlatformAgent : AgentBase { public override PlatformType Platform => PlatformType.NewPlatform; public override string Name => "新平台"; protected override async Task DoLoginAsync(CookieSession session, CancellationToken ct) { // 实现登录逻辑 } protected override async Task DoUploadVideoAsync(VideoContent video, IProgress? progress, CancellationToken ct) { // 实现上传逻辑 } // ... 实现其他方法 } ``` -------------------------------- ### Create Publish Task via CLI Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/docs/OpenClaw使用指南.md Use the 'autopub publish' command to create a publishing task. You can specify a single platform, all configured platforms, or a scheduled time. ```bash # 发布到指定平台 autopub publish -v 1 -p douyin # 发布到所有已配置平台 autopub publish -v 1 --all # 定时发布 autopub publish -v 1 -p xiaohongshu -s "2026-04-01 10:00" ``` -------------------------------- ### Network Monitoring Implementation Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Initializes a NetworkMonitor to track network connectivity, measure latency, and handle status changes. Use this to build resilient network operations. ```csharp NetworkMonitor monitor = new NetworkMonitor(); monitor.Start(); // 检查网络连通性 bool isConnected = await monitor.CheckConnectivityAsync(); // 测量网络延迟 int latencyMs = await monitor.MeasureLatencyAsync("www.baidu.com"); // 等待网络恢复 await monitor.WaitForConnectivityAsync(cancellationToken); // 监听状态变化 monitor.StatusChanged += (s, e) => { Console.WriteLine($"网络状态: {(e.IsConnected ? "已连接" : "已断开")}"); }; ``` -------------------------------- ### Automated Publishing Workflow Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/docs/OpenClaw使用指南.md Flowchart illustrating the steps involved in the automated video publishing process, from account addition to completion. ```text ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ 添加账号 │───▶│ 导入视频 │───▶│ 创建任务 │ └─────────────┘ └─────────────┘ └─────────────┘ │ ▼ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ 发布完成 │◀───│ AI代理执行 │◀───│ 启动调度器 │ └─────────────┘ └─────────────┘ └─────────────┘ │ ┌────────────┼────────────┐ ▼ ▼ ▼ ┌───────┐ ┌───────┐ ┌───────┐ │ 登录 │───▶│ 上传 │───▶│ 发布 │ └───────┘ └───────┘ └───────┘ ``` -------------------------------- ### Browser Mode Configuration Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/OpenClaw使用指南.md Configure browser mode for debugging or production. `Headless: false` shows the browser for debugging, while `Headless: true` runs in the background for automated tasks. ```yaml Headless: false # Headless: true ``` -------------------------------- ### Production Environment Configuration Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/docs/OpenClaw使用指南.md JSON configuration for the production environment, running in headless mode with increased concurrency and auto-retry enabled. ```json { "Browser": { "Headless": true, "DefaultDelayMs": 1000 }, "Agent": { "MaxConcurrentTasks": 3, "EnableAutoRetry": true, "RetryCount": 3 } } ``` -------------------------------- ### Account Management Commands Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Commands for managing platform accounts, including listing, adding, validating, and deleting. ```bash # 列出所有账号 autopub account list ``` ```bash # 添加账号 autopub account add -p douyin -n "账号名称" -c "cookie数据" ``` ```bash # 验证账号 autopub account validate ``` ```bash # 删除账号 autopub account delete ``` -------------------------------- ### Configure MCP Server for AutoPublisher Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/docs/OpenClaw使用指南.md Edit the 'claude_desktop_config.json' file to configure the MCP server settings for the AutoPublisher. This involves specifying the command and arguments to run the project. ```json { "mcpServers": { "autopublisher": { "command": "dotnet", "args": ["run", "--project", "D:/Git/ShortVideo.AutoPublisher/src/ShortVideo.AutoPublisher.Mcp"] } } } ``` -------------------------------- ### ShortVideo.AutoPublisher System Architecture Layers Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Visual representation of the application's layered architecture, from the Presentation layer (Views) down to the Domain layer. ```text ┌─────────────────────────────────────────────────────────┐ │ 表现层 (Views) │ │ WPF-UI 3.0.4 · Fluent Design · MVVM │ ├─────────────────────────────────────────────────────────┤ │ 视图模型层 (ViewModels) │ │ CommunityToolkit.Mvvm · 数据绑定 │ ├─────────────────────────────────────────────────────────┤ │ 服务层 (Services) │ │ VideoContentService · PublishService · ... │ ├─────────────────────────────────────────────────────────┤ │ OpenClaw AI 代理模块 │ │ IAiAgent · 平台代理 · 任务调度器 · 浏览器管理 │ ├─────────────────────────────────────────────────────────┤ │ 基础设施层 (Infrastructure) │ │ SQLite/Dapper · NetworkMonitor · FileDownloader │ ├─────────────────────────────────────────────────────────┤ │ 领域层 (Domain) │ │ 实体 · 枚举 · 仓储接口 · 领域事件 │ └─────────────────────────────────────────────────────────┘ ``` -------------------------------- ### IAiAgent Interface Definition Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Defines the core interface for AI agents, outlining properties and essential methods for interacting with various platforms. Includes methods for initialization, login, video upload, metadata and cover image setting, and publishing. Also defines events for status and progress changes. ```csharp public interface IAiAgent : IDisposable { // 属性 PlatformType Platform { get; } string Name { get; } AgentStatus Status { get; } // 核心方法 Task InitializeAsync(CancellationToken ct = default); Task LoginAsync(CookieSession session, CancellationToken ct = default); Task UploadVideoAsync(VideoContent video, IProgress? progress = null, CancellationToken ct = default); Task SetVideoMetadataAsync(string title, string[] tags, string description, CancellationToken ct = default); Task SetCoverImageAsync(CoverImage cover, CancellationToken ct = default); Task PublishAsync(CancellationToken ct = default); // 事件 event EventHandler? StatusChanged; event EventHandler? ProgressChanged; } ``` -------------------------------- ### OpenClaw Technical Architecture Diagram Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/docs/OpenClaw使用指南.md Illustrates the layered architecture of OpenClaw, showing the IAiAgent interface, AgentBase class functionalities, and platform-specific agent implementations. This diagram helps understand the system's components and their interactions. ```text ┌──────────────────────────────────────────────────────┐ │ IAiAgent 接口 │ │ - LoginAsync() 登录验证 │ │ - UploadVideoAsync() 上传视频 │ │ - SetVideoMetadataAsync() 设置元数据 │ │ - SetCoverImageAsync() 设置封面 │ │ - PublishAsync() 发布视频 │ ├──────────────────────────────────────────────────────┤ │ AgentBase 基类 │ │ - 重试策略 (Polly) │ │ - 浏览器控制 (Playwright) │ │ - 验证码检测与处理 │ │ - 统一的状态和进度事件 │ ├──────────────────────────────────────────────────────┤ │ 平台专用代理实现 │ │ DouyinAgent │ XiaohongshuAgent │ BaijiahaoAgent │ │ WeixinChannelAgent │ ToutiaoAgent │ └──────────────────────────────────────────────────────┘ ``` -------------------------------- ### Debug Mode Configuration Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/docs/OpenClaw使用指南.md JSON configuration for the debug environment, enabling visible browser windows and limiting concurrent tasks. ```json { "Browser": { "Headless": false, "DefaultDelayMs": 2000 }, "Agent": { "MaxConcurrentTasks": 1, "EnableAutoRetry": false } } ``` -------------------------------- ### Large File Downloader with Progress Reporting Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Downloads large files, supporting resumable downloads and providing real-time progress updates. It's designed to handle files up to 1GB and automatically waits for network recovery. ```csharp FileDownloader downloader = new FileDownloader(networkMonitor); var result = await downloader.DownloadAsync( url: "https://example.com/video.mp4", destinationPath: "Downloads/video.mp4", progress: new Progress(p => { Console.WriteLine($"下载进度: {p.Progress}% - {p.FormattedSpeed}"); }), cancellationToken ); if (result.Success) { Console.WriteLine($"下载完成: {result.DownloadedBytes} 字节"); } ``` -------------------------------- ### Custom Retry Policy Configuration Source: https://github.com/dorisoy/shortvideo.autopublisher/blob/main/README.md Define a custom retry policy using RetryPolicyBuilder to specify the number of retries, initial delay, maximum delay, and backoff multiplier. This policy can then be applied to agent operations. ```csharp var customPolicy = new RetryPolicyBuilder() .WithMaxRetries(5) .WithInitialDelay(TimeSpan.FromSeconds(2)) .WithMaxDelay(TimeSpan.FromMinutes(1)) .WithBackoffMultiplier(3.0) .Build(); await agent.ExecuteWithRetryAsync(async () => { // 需要重试的操作 }, customPolicy); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.