material.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. # -*- coding: utf-8 -*-
  2. # @Time: 2023/12/26
  3. import os
  4. import random
  5. import sys
  6. import datetime
  7. sys.path.append(os.getcwd())
  8. from datetime import datetime, timedelta
  9. from common.db import MysqlHelper
  10. from common.feishu import Feishu
  11. class Material():
  12. # 获取抖音视频链接 存入数据库
  13. @classmethod
  14. def insert_user(cls):
  15. # 获取抖音视频链接
  16. douyin = Feishu.get_values_batch("prod", "succinct", "iYbVis")
  17. # 提取账号昵称和账号主页链接
  18. channel = '抖音'
  19. for row in douyin[2:]:
  20. platform = row[0]
  21. if platform == channel:
  22. account_name = row[2]
  23. account_link = row[3]
  24. user_id = account_link.split("user/")[1]
  25. insert_sql = f"""INSERT INTO video_user_id (name, user_id, channel) values ('{account_name}', '{user_id}', '{channel}')"""
  26. MysqlHelper.update_values(
  27. sql=insert_sql,
  28. env="prod",
  29. machine="",
  30. )
  31. # 获取快手视频链接 存入数据库
  32. @classmethod
  33. def insert_kuaishou_user(cls):
  34. # 获取快手视频链接
  35. douyin = Feishu.get_values_batch("prod", "succinct", "MLVd0q")
  36. # 提取账号昵称和账号主页链接
  37. channel = '快手'
  38. for row in douyin[2:]:
  39. platform = row[0]
  40. if platform == channel:
  41. account_name = row[2]
  42. account_link = row[3]
  43. user_id = account_link.split("profile/")[1]
  44. insert_sql = f"""INSERT INTO video_user_id (name, user_id, channel) values ('{account_name}', '{user_id}', '{channel}')"""
  45. MysqlHelper.update_values(
  46. sql=insert_sql,
  47. env="prod",
  48. machine="",
  49. )
  50. # 随机获取标题
  51. @classmethod
  52. def get_title(cls):
  53. title = Feishu.get_values_batch("prod", "succinct", "meGnsz")
  54. random_item = random.choice(title)
  55. cleaned_item = random_item[0].strip("[]'")
  56. return cleaned_item
  57. # 获取所有音频
  58. @classmethod
  59. def get_audio(cls):
  60. audio = Feishu.get_values_batch("prod", "succinct", "zucQUM")
  61. list = []
  62. for row in audio[1:]:
  63. account_name = row[0]
  64. text = row[2]
  65. number = {"audio_id": account_name,"text": text}
  66. list.append(number)
  67. list = random.choice(list)
  68. audio_id = list['audio_id']
  69. srt = list['text']
  70. return audio_id, srt
  71. # 获取抖音 cookie
  72. @classmethod
  73. def get_douyin_cookie(cls):
  74. douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  75. for item in douyin_token:
  76. if item[0] == '抖音':
  77. return item[1]
  78. # 获取快手 cookie
  79. @classmethod
  80. def get_kuaishou_cookie(cls):
  81. kuaishou_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  82. for item in kuaishou_token:
  83. if item[0] == '快手':
  84. return item[1]
  85. @classmethod
  86. def get_houtai_cookie(cls):
  87. douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  88. for item in douyin_token:
  89. if item[0] == '管理后台':
  90. return item[1]
  91. @classmethod
  92. def get_id(cls, audio_id):
  93. current_time = datetime.now()
  94. previous_day = current_time - timedelta(days=1)
  95. formatted_time = previous_day.strftime("%Y-%m-%d")
  96. id_list = f"""select * FROM video_audio where time = '{formatted_time}' AND audio = '{audio_id}'"""
  97. id_list = MysqlHelper.get_values(id_list, "prod")
  98. return id_list
  99. # 获取音频类型
  100. @classmethod
  101. def get_audio_type(cls, video_type, count, channel_type):
  102. list = []
  103. title_list = []
  104. if video_type == "口播--美文类":
  105. if channel_type == "jieri":
  106. audio_type = Feishu.get_values_batch("prod", "succinct", "djrml0")
  107. else:
  108. audio_type = Feishu.get_values_batch("prod", "succinct", "Sed8gy")
  109. for row in audio_type[1:]:
  110. audio_id = row[2]
  111. text = row[3]
  112. title = row[4]
  113. number = {"audio_id": audio_id, "text": text}
  114. if audio_id:
  115. list.append(number)
  116. title_list.append(title)
  117. list = random.choice(list)
  118. audio_id = list['audio_id']
  119. srt = list['text']
  120. return audio_id, srt, title_list
  121. else:
  122. if channel_type == "douyin":
  123. if count == 0 or count == 1:
  124. audio_type = Feishu.get_values_batch("prod", "succinct", "6VXm7q")
  125. for row in audio_type[1:]:
  126. audio_id = row[0]
  127. text = row[1]
  128. title = row[2]
  129. number = {"audio_id": audio_id, "text": text}
  130. list.append(number)
  131. title_list.append(title)
  132. audio_id = list[count]['audio_id']
  133. srt = list[count]['text']
  134. return audio_id, srt, title_list
  135. else:
  136. audio_type = [{"audio": "音画美文--美文类", "type": "6VXm7q"}, {"audio": "音画美文--通用类", "type": "aSNFl8"}]
  137. audio_type = random.choice(audio_type)
  138. type = audio_type['type']
  139. audio_type = Feishu.get_values_batch("prod", "succinct", type)
  140. for row in audio_type[1:]:
  141. audio_id = row[0]
  142. text = row[1]
  143. title = row[2]
  144. number = {"audio_id": audio_id, "text": text}
  145. if audio_id:
  146. list.append(number)
  147. title_list.append(title)
  148. list = random.choice(list)
  149. audio_id = list['audio_id']
  150. srt = list['text']
  151. return audio_id, srt, title_list
  152. else:
  153. audio_type = [{"audio": "音画美文--美文类", "type": "6VXm7q"}, {"audio": "音画美文--通用类", "type": "aSNFl8"}]
  154. audio_type = random.choice(audio_type)
  155. type = audio_type['type']
  156. audio_type = Feishu.get_values_batch("prod", "succinct", type)
  157. for row in audio_type[1:]:
  158. audio_id = row[0]
  159. text = row[1]
  160. title = row[2]
  161. number = {"audio_id": audio_id, "text": text}
  162. if audio_id:
  163. list.append(number)
  164. title_list.append(title)
  165. while True:
  166. list1 = random.choice(list)
  167. audio_id = list1['audio_id']
  168. srt = list1['text']
  169. id_list = cls.get_id(audio_id)
  170. if len(id_list) == 0:
  171. return audio_id, srt, title_list