main.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import time
  2. from yt_download import get_mp3_from_ut, get_info_yt_video
  3. from mp3tag import tag_mp3_file
  4. from config import FEED_UPDATE_INTERVAL, is_suitable_video
  5. from feed import CheckFeed
  6. from database import DbClass
  7. from agent import send_audio
  8. # import subprocess
  9. # subprocess.call(["python3", "bot.py"])
  10. downloaded_videos = DbClass()
  11. yt_feed = CheckFeed()
  12. while True:
  13. videos = yt_feed.read()
  14. video = videos[0]
  15. video_id = video['yt_videoid']
  16. if is_suitable_video(video['title']) and downloaded_videos.is_not_downloaded(video_id):
  17. while get_info_yt_video(video['link'])['is_live']:
  18. print('This stream is on. Waiting for end')
  19. time.sleep(30 * 60)
  20. print("Start Downloading")
  21. mp3 = get_mp3_from_ut(video)
  22. if mp3:
  23. # title = mp3['title']
  24. tag_mp3_file(mp3)
  25. downloaded_videos.add_item(video_id)
  26. file_name = f"{mp3['title']}-{mp3['id']}.mp3"
  27. print(f"----DONE!\n----File name: {file_name}")
  28. send_audio(file_name)
  29. print(f"Next check after {FEED_UPDATE_INTERVAL} minutes")
  30. time.sleep(FEED_UPDATE_INTERVAL * 60)