123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- # -*- coding: utf-8 -*-
- # @Time: 2023/12/26
- import os
- import random
- import sys
- import datetime
- sys.path.append(os.getcwd())
- from datetime import datetime, timedelta
- 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_pinjie_user(cls):
- douyin_pinjie = Feishu.get_values_batch("prod", "succinct", "hHfY4l")
- channel = '抖音-拼接类'
- for row in douyin_pinjie[2:]:
- account_link = row[0]
- user_id = account_link.split("user/")[1]
- insert_sql = f"""INSERT INTO video_user_id (user_id, channel) values ('{user_id}', '{channel}')"""
- MysqlHelper.update_values(
- sql=insert_sql,
- env="prod",
- machine="",
- )
- # 获取快手视频链接 存入数据库
- @classmethod
- def kuaishou_pinjie_user(cls):
- # 获取快手视频链接
- kuaishou_pinjie = Feishu.get_values_batch("prod", "succinct", "hHfY4l")
- # 提取账号昵称和账号主页链接
- channel = '快手-拼接类'
- for row in kuaishou_pinjie[2:]:
- account_link = row[1]
- if account_link == None:
- return
- user_id = account_link.split("profile/")[1]
- insert_sql = f"""INSERT INTO video_user_id (user_id, channel) values ('{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 insert_kuaishou_chunjie_user(cls):
- # 获取快手视频链接
- kuaishou = Feishu.get_values_batch("prod", "succinct", "7EB9WK")
- # 提取账号昵称和账号主页链接
- channel = '快手-春节'
- for row in kuaishou[2:]:
- account_link = row[1]
- user_id = account_link.split("profile/")[1]
- insert_sql = f"""INSERT INTO video_user_id (user_id, channel) values ('{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_inconformity_id(cls):
- inconformity_id = Feishu.get_values_batch("prod", "succinct", "8AxpYW")
- inconformity_id_list = []
- for item in inconformity_id[1:]:
- print(item[0])
- inconformity_id_list.append(item[0])
- return inconformity_id_list
- @classmethod
- def get_id(cls, audio_id):
- current_time = datetime.now()
- formatted_time = current_time.strftime("%Y-%m-%d")
- id_list = f"""select account_id FROM video_audio where time = '{formatted_time}' AND audio = '{audio_id} ' GROUP BY account_id """
- id_list = MysqlHelper.get_values(id_list, "prod")
- return id_list
- # 获取音频类型
- @classmethod
- def get_pinjie_title(cls):
- title_list = []
- # 获取快手视频链接
- pinjie_title = Feishu.get_values_batch("prod", "succinct", "hHfY4l")
- # 提取账号昵称和账号主页链接
- for row in pinjie_title[2:]:
- title = row[2]
- if title == None:
- break
- title_list.append(title)
- return title_list
- # 获取音频类型
- @classmethod
- def get_audio_type(cls, video_type, count, channel_type):
- list = []
- title_list = []
- if video_type == "口播--美文类":
- if channel_type == "jieri":
- audio_type = Feishu.get_values_batch("prod", "succinct", "GXh8FD")
- 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
- elif video_type == "自制--春节":
- zizhi_chunjie = Feishu.get_values_batch("prod", "succinct", "7EB9WK")
- for row in zizhi_chunjie[2:]:
- audio_id = row[2]
- text = row[3]
- title = row[4]
- number = {"audio_id": audio_id, "text": text, "title": title}
- list.append(number)
- # title_list.append(title)
- list = random.choice(list)
- audio_id = list['audio_id']
- srt = list['text']
- title_list = list['title']
- return audio_id, srt, title_list
- else:
- if count == 0:
- audio_type = Feishu.get_values_batch("prod", "succinct", "3cvuGb")
- for row in audio_type[1:]:
- audio_id = row[1]
- text = row[2]
- title = row[3]
- number = {"audio_id": audio_id, "text": text}
- if audio_id:
- list.append(number)
- title_list.append(title)
- while True:
- list1 = random.choice(list)
- audio_id = list1['audio_id']
- srt = list1['text']
- id_list = cls.get_id(audio_id)
- if len(id_list) < 1:
- 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)
- while True:
- list1 = random.choice(list)
- audio_id = list1['audio_id']
- srt = list1['text']
- id_list = cls.get_id(audio_id)
- if len(id_list) < 2:
- return audio_id, srt, title_list
|