mport os
import telepot
from telepot.loop import MessageLoop
# Replace with your bot's token and chat_id
BOT_TOKEN = '填写'
CHAT_ID = '填写'
def find_latest_video(directory):
video_files = [f for f in os.listdir(directory) if f.endswith(('.mp4', '.avi', '.mkv', '.mov'))]
if not video_files:
return None
video_files.sort(key=lambda x: os.path.getmtime(os.path.join(directory, x)), reverse=True)
return os.path.join(directory, video_files[0])
def send_video(bot, chat_id, video_path):
with open(video_path, 'rb') as video:
bot.sendVideo(chat_id, video)
def main():
directory = '/path/to/downloads' # 下载路径
latest_video = find_latest_video(directory)
if latest_video:
print(f"Latest video found: {latest_video}")
bot = telepot.Bot(BOT_TOKEN)
send_video(bot, CHAT_ID, latest_video)
print("Video sent successfully")
else:
print("No video files found in the specified directory")
if __name__ == '__main__':
main()