material.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 insert_kuaishou_chunjie_user(cls):
  53. # 获取快手视频链接
  54. kuaishou = Feishu.get_values_batch("prod", "succinct", "7EB9WK")
  55. # 提取账号昵称和账号主页链接
  56. channel = '快手-春节'
  57. for row in kuaishou[2:]:
  58. account_link = row[1]
  59. user_id = account_link.split("profile/")[1]
  60. insert_sql = f"""INSERT INTO video_user_id (user_id, channel) values ('{user_id}', '{channel}')"""
  61. MysqlHelper.update_values(
  62. sql=insert_sql,
  63. env="prod",
  64. machine="",
  65. )
  66. # 随机获取标题
  67. @classmethod
  68. def get_title(cls):
  69. title = Feishu.get_values_batch("prod", "succinct", "meGnsz")
  70. random_item = random.choice(title)
  71. cleaned_item = random_item[0].strip("[]'")
  72. return cleaned_item
  73. # 获取所有音频
  74. @classmethod
  75. def get_audio(cls):
  76. audio = Feishu.get_values_batch("prod", "succinct", "zucQUM")
  77. list = []
  78. for row in audio[1:]:
  79. account_name = row[0]
  80. text = row[2]
  81. number = {"audio_id": account_name,"text": text}
  82. list.append(number)
  83. list = random.choice(list)
  84. audio_id = list['audio_id']
  85. srt = list['text']
  86. return audio_id, srt
  87. # 获取抖音 cookie
  88. @classmethod
  89. def get_douyin_cookie(cls):
  90. douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  91. for item in douyin_token:
  92. if item[0] == '抖音':
  93. return item[1]
  94. # 获取快手 cookie
  95. @classmethod
  96. def get_kuaishou_cookie(cls):
  97. kuaishou_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  98. for item in kuaishou_token:
  99. if item[0] == '快手':
  100. return item[1]
  101. @classmethod
  102. def get_houtai_cookie(cls):
  103. douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  104. for item in douyin_token:
  105. if item[0] == '管理后台':
  106. return item[1]
  107. @classmethod
  108. def get_id(cls, audio_id):
  109. current_time = datetime.now()
  110. previous_day = current_time - timedelta(days=1)
  111. formatted_time = previous_day.strftime("%Y-%m-%d")
  112. id_list = f"""select * FROM video_audio where time = '{formatted_time}' AND audio = '{audio_id}'"""
  113. id_list = MysqlHelper.get_values(id_list, "prod")
  114. return id_list
  115. # 获取音频类型
  116. @classmethod
  117. def get_audio_type(cls, video_type, count, channel_type):
  118. list = []
  119. title_list = []
  120. if video_type == "口播--美文类":
  121. if channel_type == "jieri":
  122. audio_type = Feishu.get_values_batch("prod", "succinct", "GXh8FD")
  123. else:
  124. audio_type = Feishu.get_values_batch("prod", "succinct", "Sed8gy")
  125. for row in audio_type[1:]:
  126. audio_id = row[2]
  127. text = row[3]
  128. title = row[4]
  129. number = {"audio_id": audio_id, "text": text}
  130. if audio_id:
  131. list.append(number)
  132. title_list.append(title)
  133. list = random.choice(list)
  134. audio_id = list['audio_id']
  135. srt = list['text']
  136. return audio_id, srt, title_list
  137. elif video_type == "自制--春节":
  138. zizhi_chunjie = Feishu.get_values_batch("prod", "succinct", "7EB9WK")
  139. for row in zizhi_chunjie[2:]:
  140. audio_id = row[2]
  141. text = row[3]
  142. title = row[4]
  143. number = {"audio_id": audio_id, "text": text, "title": title}
  144. list.append(number)
  145. # title_list.append(title)
  146. list = random.choice(list)
  147. audio_id = list['audio_id']
  148. srt = list['text']
  149. title_list = list['title']
  150. return audio_id, srt, title_list
  151. else:
  152. if channel_type == "douyin":
  153. if count == 0 or count == 1:
  154. audio_type = Feishu.get_values_batch("prod", "succinct", "6VXm7q")
  155. for row in audio_type[1:]:
  156. audio_id = row[0]
  157. text = row[1]
  158. title = row[2]
  159. number = {"audio_id": audio_id, "text": text}
  160. list.append(number)
  161. title_list.append(title)
  162. audio_id = list[count]['audio_id']
  163. srt = list[count]['text']
  164. return audio_id, srt, title_list
  165. else:
  166. audio_type = [{"audio": "音画美文--美文类", "type": "6VXm7q"}, {"audio": "音画美文--通用类", "type": "aSNFl8"}]
  167. audio_type = random.choice(audio_type)
  168. type = audio_type['type']
  169. audio_type = Feishu.get_values_batch("prod", "succinct", type)
  170. for row in audio_type[1:]:
  171. audio_id = row[0]
  172. text = row[1]
  173. title = row[2]
  174. number = {"audio_id": audio_id, "text": text}
  175. if audio_id:
  176. list.append(number)
  177. title_list.append(title)
  178. list = random.choice(list)
  179. audio_id = list['audio_id']
  180. srt = list['text']
  181. return audio_id, srt, title_list
  182. else:
  183. audio_type = [{"audio": "音画美文--美文类", "type": "6VXm7q"}, {"audio": "音画美文--通用类", "type": "aSNFl8"}]
  184. audio_type = random.choice(audio_type)
  185. type = audio_type['type']
  186. audio_type = Feishu.get_values_batch("prod", "succinct", type)
  187. for row in audio_type[1:]:
  188. audio_id = row[0]
  189. text = row[1]
  190. title = row[2]
  191. number = {"audio_id": audio_id, "text": text}
  192. if audio_id:
  193. list.append(number)
  194. title_list.append(title)
  195. while True:
  196. list1 = random.choice(list)
  197. audio_id = list1['audio_id']
  198. srt = list1['text']
  199. id_list = cls.get_id(audio_id)
  200. if len(id_list) == 0:
  201. return audio_id, srt, title_list