material.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 get_title(cls):
  32. title = Feishu.get_values_batch("prod", "succinct", "meGnsz")
  33. random_item = random.choice(title)
  34. cleaned_item = random_item[0].strip("[]'")
  35. return cleaned_item
  36. # 获取所有音频
  37. @classmethod
  38. def get_audio(cls):
  39. audio = Feishu.get_values_batch("prod", "succinct", "zucQUM")
  40. list = []
  41. for row in audio[1:]:
  42. account_name = row[0]
  43. list.append(account_name)
  44. srt = row[2]
  45. if srt == None:
  46. continue
  47. file_path = f"./video_stitching/video/{account_name}.srt"
  48. if os.path.isfile(file_path):
  49. continue
  50. else:
  51. with open(file_path, 'w') as file:
  52. # 写入内容到文件中
  53. file.write(srt)
  54. return list
  55. # 获取抖音 cookie
  56. @classmethod
  57. def get_douyin_cookie(cls):
  58. douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  59. for item in douyin_token:
  60. if item[0] == '抖音':
  61. return item[1]
  62. @classmethod
  63. def get_houtai_cookie(cls):
  64. douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  65. for item in douyin_token:
  66. if item[0] == '管理后台':
  67. return item[1]