material.py 10.0 KB

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