material.py 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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_pinjie_user(cls):
  34. douyin_pinjie = Feishu.get_values_batch("prod", "succinct", "hHfY4l")
  35. channel = '抖音-拼接类'
  36. for row in douyin_pinjie[2:]:
  37. account_link = row[0]
  38. user_id = account_link.split("user/")[1]
  39. insert_sql = f"""INSERT INTO video_user_id (user_id, channel) values ('{user_id}', '{channel}')"""
  40. MysqlHelper.update_values(
  41. sql=insert_sql,
  42. env="prod",
  43. machine="",
  44. )
  45. # 获取快手视频链接 存入数据库
  46. @classmethod
  47. def kuaishou_pinjie_user(cls):
  48. # 获取快手视频链接
  49. kuaishou_pinjie = Feishu.get_values_batch("prod", "succinct", "hHfY4l")
  50. # 提取账号昵称和账号主页链接
  51. channel = '快手-拼接类'
  52. for row in kuaishou_pinjie[2:]:
  53. account_link = row[1]
  54. if account_link == None:
  55. return
  56. user_id = account_link.split("profile/")[1]
  57. insert_sql = f"""INSERT INTO video_user_id (user_id, channel) values ('{user_id}', '{channel}')"""
  58. MysqlHelper.update_values(
  59. sql=insert_sql,
  60. env="prod",
  61. machine="",
  62. )
  63. # 获取快手视频链接 存入数据库
  64. @classmethod
  65. def insert_kuaishou_user(cls):
  66. # 获取快手视频链接
  67. douyin = Feishu.get_values_batch("prod", "succinct", "MLVd0q")
  68. # 提取账号昵称和账号主页链接
  69. channel = '快手'
  70. for row in douyin[2:]:
  71. platform = row[0]
  72. if platform == channel:
  73. account_name = row[2]
  74. account_link = row[3]
  75. user_id = account_link.split("profile/")[1]
  76. insert_sql = f"""INSERT INTO video_user_id (name, user_id, channel) values ('{account_name}', '{user_id}', '{channel}')"""
  77. MysqlHelper.update_values(
  78. sql=insert_sql,
  79. env="prod",
  80. machine="",
  81. )
  82. # 获取快手视频链接 存入数据库
  83. @classmethod
  84. def insert_kuaishou_chunjie_user(cls):
  85. # 获取快手视频链接
  86. kuaishou = Feishu.get_values_batch("prod", "succinct", "7EB9WK")
  87. # 提取账号昵称和账号主页链接
  88. channel = '快手-春节'
  89. for row in kuaishou[2:]:
  90. account_link = row[1]
  91. user_id = account_link.split("profile/")[1]
  92. insert_sql = f"""INSERT INTO video_user_id (user_id, channel) values ('{user_id}', '{channel}')"""
  93. MysqlHelper.update_values(
  94. sql=insert_sql,
  95. env="prod",
  96. machine="",
  97. )
  98. # 随机获取标题
  99. @classmethod
  100. def get_title(cls):
  101. title = Feishu.get_values_batch("prod", "succinct", "meGnsz")
  102. random_item = random.choice(title)
  103. cleaned_item = random_item[0].strip("[]'")
  104. return cleaned_item
  105. # 获取所有音频
  106. @classmethod
  107. def get_audio(cls):
  108. audio = Feishu.get_values_batch("prod", "succinct", "zucQUM")
  109. list = []
  110. for row in audio[1:]:
  111. account_name = row[0]
  112. text = row[2]
  113. number = {"audio_id": account_name,"text": text}
  114. list.append(number)
  115. list = random.choice(list)
  116. audio_id = list['audio_id']
  117. srt = list['text']
  118. return audio_id, srt
  119. # 获取抖音 cookie
  120. @classmethod
  121. def get_douyin_cookie(cls):
  122. douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  123. for item in douyin_token:
  124. if item[0] == '抖音':
  125. return item[1]
  126. # 获取快手 cookie
  127. @classmethod
  128. def get_kuaishou_cookie(cls):
  129. kuaishou_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  130. for item in kuaishou_token:
  131. if item[0] == '快手':
  132. return item[1]
  133. @classmethod
  134. def get_houtai_cookie(cls):
  135. douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  136. for item in douyin_token:
  137. if item[0] == '管理后台':
  138. return item[1]
  139. @classmethod
  140. def get_inconformity_id(cls):
  141. inconformity_id = Feishu.get_values_batch("prod", "succinct", "8AxpYW")
  142. inconformity_id_list = []
  143. for item in inconformity_id[1:]:
  144. print(item[0])
  145. inconformity_id_list.append(item[0])
  146. return inconformity_id_list
  147. @classmethod
  148. def get_id(cls, audio_id):
  149. current_time = datetime.now()
  150. formatted_time = current_time.strftime("%Y-%m-%d")
  151. id_list = f"""select account_id FROM video_audio where time = '{formatted_time}' AND audio = '{audio_id} ' GROUP BY account_id """
  152. id_list = MysqlHelper.get_values(id_list, "prod")
  153. return id_list
  154. # 获取音频类型
  155. @classmethod
  156. def get_pinjie_title(cls):
  157. title_list = []
  158. # 获取快手视频链接
  159. pinjie_title = Feishu.get_values_batch("prod", "succinct", "hHfY4l")
  160. # 提取账号昵称和账号主页链接
  161. for row in pinjie_title[2:]:
  162. title = row[2]
  163. if title == None:
  164. break
  165. title_list.append(title)
  166. return title_list
  167. # 获取音频类型
  168. @classmethod
  169. def get_audio_type(cls, video_type, count, channel_type):
  170. list = []
  171. title_list = []
  172. if video_type == "口播--美文类":
  173. if channel_type == "jieri":
  174. audio_type = Feishu.get_values_batch("prod", "succinct", "GXh8FD")
  175. else:
  176. audio_type = Feishu.get_values_batch("prod", "succinct", "Sed8gy")
  177. for row in audio_type[1:]:
  178. audio_id = row[2]
  179. text = row[3]
  180. title = row[4]
  181. number = {"audio_id": audio_id, "text": text}
  182. if audio_id:
  183. list.append(number)
  184. title_list.append(title)
  185. list = random.choice(list)
  186. audio_id = list['audio_id']
  187. srt = list['text']
  188. return audio_id, srt, title_list
  189. elif video_type == "自制--春节":
  190. zizhi_chunjie = Feishu.get_values_batch("prod", "succinct", "7EB9WK")
  191. for row in zizhi_chunjie[2:]:
  192. audio_id = row[2]
  193. text = row[3]
  194. title = row[4]
  195. number = {"audio_id": audio_id, "text": text, "title": title}
  196. list.append(number)
  197. # title_list.append(title)
  198. list = random.choice(list)
  199. audio_id = list['audio_id']
  200. srt = list['text']
  201. title_list = list['title']
  202. return audio_id, srt, title_list
  203. else:
  204. if count == 0:
  205. audio_type = Feishu.get_values_batch("prod", "succinct", "3cvuGb")
  206. for row in audio_type[1:]:
  207. audio_id = row[1]
  208. text = row[2]
  209. title = row[3]
  210. number = {"audio_id": audio_id, "text": text}
  211. if audio_id:
  212. list.append(number)
  213. title_list.append(title)
  214. while True:
  215. list1 = random.choice(list)
  216. audio_id = list1['audio_id']
  217. srt = list1['text']
  218. id_list = cls.get_id(audio_id)
  219. if len(id_list) < 1:
  220. return audio_id, srt, title_list
  221. else:
  222. audio_type = [{"audio": "音画美文--美文类", "type": "6VXm7q"}, {"audio": "音画美文--通用类", "type": "aSNFl8"}]
  223. audio_type = random.choice(audio_type)
  224. type = audio_type['type']
  225. audio_type = Feishu.get_values_batch("prod", "succinct", type)
  226. for row in audio_type[1:]:
  227. audio_id = row[0]
  228. text = row[1]
  229. title = row[2]
  230. number = {"audio_id": audio_id, "text": text}
  231. if audio_id:
  232. list.append(number)
  233. title_list.append(title)
  234. while True:
  235. list1 = random.choice(list)
  236. audio_id = list1['audio_id']
  237. srt = list1['text']
  238. id_list = cls.get_id(audio_id)
  239. if len(id_list) < 2:
  240. return audio_id, srt, title_list