material.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. if channel_type == "xiaonian":
  96. audio_type = Feishu.get_values_batch("prod", "succinct", "djrml0")
  97. else:
  98. audio_type = Feishu.get_values_batch("prod", "succinct", "Sed8gy")
  99. for row in audio_type[1:]:
  100. audio_id = row[2]
  101. text = row[3]
  102. title = row[4]
  103. number = {"audio_id": audio_id, "text": text}
  104. if audio_id:
  105. list.append(number)
  106. title_list.append(title)
  107. list = random.choice(list)
  108. audio_id = list['audio_id']
  109. srt = list['text']
  110. return audio_id, srt, title_list
  111. else:
  112. if channel_type == "douyin":
  113. if count == 0 or count == 1:
  114. audio_type = Feishu.get_values_batch("prod", "succinct", "6VXm7q")
  115. for row in audio_type[1:]:
  116. audio_id = row[0]
  117. text = row[1]
  118. title = row[2]
  119. number = {"audio_id": audio_id, "text": text}
  120. list.append(number)
  121. title_list.append(title)
  122. audio_id = list[count]['audio_id']
  123. srt = list[count]['text']
  124. return audio_id, srt, title_list
  125. else:
  126. audio_type = [{"audio": "音画美文--美文类", "type": "6VXm7q"}, {"audio": "音画美文--通用类", "type": "aSNFl8"}]
  127. audio_type = random.choice(audio_type)
  128. type = audio_type['type']
  129. audio_type = Feishu.get_values_batch("prod", "succinct", type)
  130. for row in audio_type[1:]:
  131. audio_id = row[0]
  132. text = row[1]
  133. title = row[2]
  134. number = {"audio_id": audio_id, "text": text}
  135. if audio_id:
  136. list.append(number)
  137. title_list.append(title)
  138. list = random.choice(list)
  139. audio_id = list['audio_id']
  140. srt = list['text']
  141. return audio_id, srt, title_list
  142. else:
  143. audio_type = [{"audio": "音画美文--美文类", "type": "6VXm7q"}, {"audio": "音画美文--通用类", "type": "aSNFl8"}]
  144. audio_type = random.choice(audio_type)
  145. type = audio_type['type']
  146. audio_type = Feishu.get_values_batch("prod", "succinct", type)
  147. for row in audio_type[1:]:
  148. audio_id = row[0]
  149. text = row[1]
  150. title = row[2]
  151. number = {"audio_id": audio_id, "text": text}
  152. if audio_id:
  153. list.append(number)
  154. title_list.append(title)
  155. list = random.choice(list)
  156. audio_id = list['audio_id']
  157. srt = list['text']
  158. return audio_id, srt, title_list