material.py 6.3 KB

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