Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new douyin support #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ playwright install chromium firefox
非程序员,[新手级教程](https://juejin.cn/post/7372114027840208911)

# 🐇 About
The project for my own project extracted, my release strategy is timed release (released a day in advance), so the release part of the event are used for the next day time!
The project for my own project extracted, my release strategy is timed release (released a day in advance), so the release part of the time are used for the next day time!

If you need to release it immediately, you can study the source code or ask me questions.

该项目为我自用项目抽离出来,我的发布策略是定时发布(提前一天发布),故发布部分采用的事件均为第二天的时间
该项目为我自用项目抽离出来,我的发布策略是定时发布(提前一天发布),故发布部分采用的时间均为第二天的时间

如果你有需求立即发布,可自行研究源码或者向我提问

Expand Down Expand Up @@ -109,6 +109,9 @@ douyin平台, 账号名为test, 动作为upload, 视频文件(需对应的meta

python cli_main.py douyin test upload "C:\Users\superdog\Videos\2023-11-07_05-27-44 - 这位少女如梦中仙... .mp4" -pt 1 -t "2024-6-14 12:00"
douyin平台, 账号名为test, 动作为upload, 视频文件, 发布方式(pt):1 定时发布, 发布时间(t): 2024-6-14 12:00

python cli_main.py douyin test upload "C:\Users\superdog\Videos\2023-11-07_05-27-44 - 这位少女如梦中仙... .mp4" -pt 1 -t "2024-6-14 12:00" -dt 1
douyin平台, 账号名为test, 动作为upload, 视频文件, 发布方式(pt):1 定时发布, 发布时间(t): 2024-6-14 12:00, 是否允许别人保存视频(dt):1 不允许
```

---
Expand Down
5 changes: 4 additions & 1 deletion cli_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ async def main():
action_parser.add_argument("-pt", "--publish_type", type=int, choices=[0, 1],
help="0 for immediate, 1 for scheduled", default=0)
action_parser.add_argument('-t', '--schedule', help='Schedule UTC time in %Y-%m-%d %H:%M format')
action_parser.add_argument("-dt", "--download_type", type=int, choices=[0, 1],
help="0 for allowed, 1 for not allowed (only for douyin)", default=0)

# 解析命令行参数
args = parser.parse_args()
Expand Down Expand Up @@ -78,8 +80,9 @@ async def main():
publish_date = parse_schedule(args.schedule)

if args.platform == SOCIAL_MEDIA_DOUYIN:
download_type = args.download_type
await douyin_setup(account_file, handle=False)
app = DouYinVideo(title, video_file, tags, publish_date, account_file)
app = DouYinVideo(title, video_file, tags, publish_date, account_file, download_type)
elif args.platform == SOCIAL_MEDIA_TIKTOK:
await tiktok_setup(account_file, handle=True)
app = TiktokVideo(title, video_file, tags, publish_date, account_file)
Expand Down
10 changes: 9 additions & 1 deletion uploader/douyin_uploader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ async def douyin_cookie_gen(account_file):


class DouYinVideo(object):
def __init__(self, title, file_path, tags, publish_date: datetime, account_file, thumbnail_path=None):
def __init__(self, title, file_path, tags, publish_date: datetime, account_file, download_type, thumbnail_path=None):
self.title = title # 视频标题
self.file_path = file_path
self.tags = tags
self.publish_date = publish_date
self.account_file = account_file
self.download_type = download_type
self.date_format = '%Y年%m月%d日 %H:%M'
self.local_executable_path = LOCAL_CHROME_PATH
self.thumbnail_path = thumbnail_path
Expand Down Expand Up @@ -184,6 +185,9 @@ async def upload(self, playwright: Playwright) -> None:
if self.publish_date != 0:
await self.set_schedule_time_douyin(page, self.publish_date)

if self.download_type != 0:
await self.set_download_type(page)

# 判断视频是否发布成功
while True:
# 判断视频是否发布成功
Expand Down Expand Up @@ -228,6 +232,10 @@ async def set_location(self, page: Page, location: str = "杭州市"):
await page.wait_for_selector('div[role="listbox"] [role="option"]', timeout=5000)
await page.locator('div[role="listbox"] [role="option"]').first.click()

async def set_download_type(self, page: Page):
# 选择下载类型
await page.locator("[class^='radio']:has-text('不允许')").click()

async def main(self):
async with async_playwright() as playwright:
await self.upload(playwright)
Expand Down