demo.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/7/12
  4. import os
  5. import shutil
  6. import ffmpeg
  7. from main.feishu_lib import Feishu
  8. class Demo:
  9. # 获取已下载视频宽高、时长等信息
  10. @classmethod
  11. def get_video_info_from_local(cls, video_path):
  12. probe = ffmpeg.probe(video_path)
  13. # print('video_path: {}'.format(video_path))
  14. # format1 = probe['format']
  15. # bit_rate = int(format1['bit_rate']) / 1000
  16. # duration = format['duration']
  17. # size = int(format1['size']) / 1024 / 1024
  18. video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
  19. if video_stream is None:
  20. print('No video stream found!')
  21. return
  22. width = int(video_stream['width'])
  23. height = int(video_stream['height'])
  24. # num_frames = int(video_stream['nb_frames'])
  25. # fps = int(video_stream['r_frame_rate'].split('/')[0]) / int(video_stream['r_frame_rate'].split('/')[1])
  26. duration = float(video_stream['duration'])
  27. # print('width: {}'.format(width))
  28. # print('height: {}'.format(height))
  29. # print('num_frames: {}'.format(num_frames))
  30. # print('bit_rate: {}k'.format(bit_rate))
  31. # print('fps: {}'.format(fps))
  32. # print('size: {}MB'.format(size))
  33. # print('duration: {}'.format(duration))
  34. return width, height, duration
  35. # 判断视频时长是否大于 60s
  36. @classmethod
  37. def check_duration(cls):
  38. # 获取视频时长
  39. video_info = cls.get_video_info_from_local("../videos/11111/video.mp4")
  40. video_duration = video_info[2]
  41. if int(video_duration) < 60:
  42. shutil.rmtree("../videos/11111/")
  43. else:
  44. print(f"video_duration:{video_duration}")
  45. # 判断 title 长度
  46. @classmethod
  47. def check_title_len(cls):
  48. title = "🌸这首《老公赚钱给老婆花》🌸被唱的太肉麻了🌸好听好看🌸这首《老公赚钱给老婆花》🌸被唱的太肉麻了🌸好听好看"[:30]
  49. # print(len(title))
  50. # if len(title) > 30:
  51. # title = title[:30]
  52. print(title)
  53. print(len(title))
  54. # 删除某个文件夹下所有文件
  55. @classmethod
  56. def del_files(cls):
  57. # 要删除的目标文件夹目录
  58. filepath = "./videos/"
  59. # 列出目标文件夹里边的文件列表
  60. del_list = os.listdir(filepath)
  61. # 删除前,打印目标文件目录内容
  62. print(f"del_list:{del_list}\n")
  63. for f in del_list:
  64. # 目标文件夹中,某一个文件/文件夹
  65. file_path = os.path.join(filepath, f)
  66. print(f"file_path:{file_path}")
  67. # 目标文件目录中的文件夹
  68. if os.path.isdir(file_path):
  69. shutil.rmtree(file_path)
  70. # 目标文件目录中的文件
  71. elif os.path.isfile(file_path):
  72. os.remove(file_path)
  73. # 删除后,打印目标文件目录内容
  74. print(f"videos文件夹:{os.listdir(filepath)}\n")
  75. # 去重
  76. @classmethod
  77. def distent(cls):
  78. if "10477" in [n for m in Feishu.get_values_batch("log_type", "music_album", "f5a76e") for n in m]:
  79. print("yes")
  80. else:
  81. print("no")
  82. if __name__ == "__main__":
  83. demo = Demo()
  84. # demo.check_duration()
  85. # demo.check_title_len()
  86. # demo.del_files()
  87. demo.distent()