# -*- coding: utf-8 -*- # @Author: wangkun # @Time: 2022/7/12 import os import shutil import ffmpeg from main.feishu_lib import Feishu class Demo: # 获取已下载视频宽高、时长等信息 @classmethod def get_video_info_from_local(cls, video_path): probe = ffmpeg.probe(video_path) # print('video_path: {}'.format(video_path)) # format1 = probe['format'] # bit_rate = int(format1['bit_rate']) / 1000 # duration = format['duration'] # size = int(format1['size']) / 1024 / 1024 video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None) if video_stream is None: print('No video stream found!') return width = int(video_stream['width']) height = int(video_stream['height']) # num_frames = int(video_stream['nb_frames']) # fps = int(video_stream['r_frame_rate'].split('/')[0]) / int(video_stream['r_frame_rate'].split('/')[1]) duration = float(video_stream['duration']) # print('width: {}'.format(width)) # print('height: {}'.format(height)) # print('num_frames: {}'.format(num_frames)) # print('bit_rate: {}k'.format(bit_rate)) # print('fps: {}'.format(fps)) # print('size: {}MB'.format(size)) # print('duration: {}'.format(duration)) return width, height, duration # 判断视频时长是否大于 60s @classmethod def check_duration(cls): # 获取视频时长 video_info = cls.get_video_info_from_local("../videos/11111/video.mp4") video_duration = video_info[2] if int(video_duration) < 60: shutil.rmtree("../videos/11111/") else: print(f"video_duration:{video_duration}") # 判断 title 长度 @classmethod def check_title_len(cls): title = "🌸这首《老公赚钱给老婆花》🌸被唱的太肉麻了🌸好听好看🌸这首《老公赚钱给老婆花》🌸被唱的太肉麻了🌸好听好看"[:30] # print(len(title)) # if len(title) > 30: # title = title[:30] print(title) print(len(title)) # 删除某个文件夹下所有文件 @classmethod def del_files(cls): # 要删除的目标文件夹目录 filepath = "./videos/" # 列出目标文件夹里边的文件列表 del_list = os.listdir(filepath) # 删除前,打印目标文件目录内容 print(f"del_list:{del_list}\n") for f in del_list: # 目标文件夹中,某一个文件/文件夹 file_path = os.path.join(filepath, f) print(f"file_path:{file_path}") # 目标文件目录中的文件夹 if os.path.isdir(file_path): shutil.rmtree(file_path) # 目标文件目录中的文件 elif os.path.isfile(file_path): os.remove(file_path) # 删除后,打印目标文件目录内容 print(f"videos文件夹:{os.listdir(filepath)}\n") # 去重 @classmethod def distent(cls): if "10477" in [n for m in Feishu.get_values_batch("log_type", "music_album", "f5a76e") for n in m]: print("yes") else: print("no") if __name__ == "__main__": demo = Demo() # demo.check_duration() # demo.check_title_len() # demo.del_files() demo.distent()