# -*- coding: utf-8 -*- # @Time: 2023/12/26 import os import random import sys sys.path.append(os.getcwd()) from common.db import MysqlHelper from common.feishu import Feishu class Material(): # 获取抖音视频链接 存入数据库 @classmethod def insert_user(cls): # 获取抖音视频链接 douyin = Feishu.get_values_batch("prod", "succinct", "iYbVis") # 提取账号昵称和账号主页链接 channel = '抖音' for row in douyin[2:]: platform = row[0] if platform == channel: account_name = row[2] account_link = row[3] user_id = account_link.split("user/")[1] insert_sql = f"""INSERT INTO video_user_id (name, user_id, channel) values ('{account_name}', '{user_id}', '{channel}')""" MysqlHelper.update_values( sql=insert_sql, env="prod", machine="", ) # 获取快手视频链接 存入数据库 @classmethod def insert_kuaishou_user(cls): # 获取快手视频链接 douyin = Feishu.get_values_batch("prod", "succinct", "MLVd0q") # 提取账号昵称和账号主页链接 channel = '快手' for row in douyin[2:]: platform = row[0] if platform == channel: account_name = row[2] account_link = row[3] user_id = account_link.split("profile/")[1] insert_sql = f"""INSERT INTO video_user_id (name, user_id, channel) values ('{account_name}', '{user_id}', '{channel}')""" MysqlHelper.update_values( sql=insert_sql, env="prod", machine="", ) # 随机获取标题 @classmethod def get_title(cls): title = Feishu.get_values_batch("prod", "succinct", "meGnsz") random_item = random.choice(title) cleaned_item = random_item[0].strip("[]'") return cleaned_item # 获取所有音频 @classmethod def get_audio(cls): audio = Feishu.get_values_batch("prod", "succinct", "zucQUM") list = [] for row in audio[1:]: account_name = row[0] text = row[2] number = {"audio_id": account_name,"text": text} list.append(number) list = random.choice(list) audio_id = list['audio_id'] srt = list['text'] return audio_id, srt # 获取抖音 cookie @classmethod def get_douyin_cookie(cls): douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G") for item in douyin_token: if item[0] == '抖音': return item[1] # 获取快手 cookie @classmethod def get_kuaishou_cookie(cls): kuaishou_token = Feishu.get_values_batch("prod", "succinct", "OpE35G") for item in kuaishou_token: if item[0] == '快手': return item[1] @classmethod def get_houtai_cookie(cls): douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G") for item in douyin_token: if item[0] == '管理后台': return item[1] # 获取音频类型 @classmethod def get_audio_type(cls, video_type, count, channel_type): list = [] title_list = [] if video_type == "口播--美文类": if channel_type == "xiaonian": audio_type = Feishu.get_values_batch("prod", "succinct", "djrml0") else: audio_type = Feishu.get_values_batch("prod", "succinct", "Sed8gy") for row in audio_type[1:]: audio_id = row[2] text = row[3] title = row[4] number = {"audio_id": audio_id, "text": text} if audio_id: list.append(number) title_list.append(title) list = random.choice(list) audio_id = list['audio_id'] srt = list['text'] return audio_id, srt, title_list else: if channel_type == "douyin": if count == 0 or count == 1: audio_type = Feishu.get_values_batch("prod", "succinct", "6VXm7q") for row in audio_type[1:]: audio_id = row[0] text = row[1] title = row[2] number = {"audio_id": audio_id, "text": text} list.append(number) title_list.append(title) audio_id = list[count]['audio_id'] srt = list[count]['text'] return audio_id, srt, title_list else: audio_type = [{"audio": "音画美文--美文类", "type": "6VXm7q"}, {"audio": "音画美文--通用类", "type": "aSNFl8"}] audio_type = random.choice(audio_type) type = audio_type['type'] audio_type = Feishu.get_values_batch("prod", "succinct", type) for row in audio_type[1:]: audio_id = row[0] text = row[1] title = row[2] number = {"audio_id": audio_id, "text": text} if audio_id: list.append(number) title_list.append(title) list = random.choice(list) audio_id = list['audio_id'] srt = list['text'] return audio_id, srt, title_list else: audio_type = [{"audio": "音画美文--美文类", "type": "6VXm7q"}, {"audio": "音画美文--通用类", "type": "aSNFl8"}] audio_type = random.choice(audio_type) type = audio_type['type'] audio_type = Feishu.get_values_batch("prod", "succinct", type) for row in audio_type[1:]: audio_id = row[0] text = row[1] title = row[2] number = {"audio_id": audio_id, "text": text} if audio_id: list.append(number) title_list.append(title) list = random.choice(list) audio_id = list['audio_id'] srt = list['text'] return audio_id, srt, title_list