main.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import os
  2. from pyfzf.pyfzf import FzfPrompt
  3. import requests
  4. from plumbum.commands.processes import ProcessExecutionError
  5. import sys
  6. fzf = FzfPrompt()
  7. def main():
  8. sl = ['Channels', 'Search', 'Add Channel', 'Delete Channel', 'Change Mirror', 'Get Current Mirror', 'Add custom mirror', 'Backup subscribes', 'Restore subscribes', 'Play by link', 'Update script']
  9. sel = fzf.prompt(sl)
  10. ls = ", ".join(sel)
  11. run = 'python3 bin/'
  12. if ls == 'Channels':
  13. os.system(f"{run}channel.py")
  14. elif ls == 'Search':
  15. os.system(f"{run}search.py")
  16. elif ls == 'Add Channel':
  17. os.system(f"{run}search-channel.py")
  18. elif ls == 'Delete Channel':
  19. os.system(f"{run}delchan.py")
  20. elif ls == 'Change Mirror':
  21. os.system(f"{run}chmirror.py")
  22. elif ls == 'Get Current Mirror':
  23. try:
  24. print(f"Current mirror is: {mirror}")
  25. except (FileNotFoundError, NameError):
  26. print("There is no any mirror!")
  27. elif ls == 'Add custom mirror':
  28. print("Write mirror - without https://:")
  29. mirrorin = input()
  30. with open("config/mirrors.txt", 'a') as f:
  31. f.write(mirrorin)
  32. f.close()
  33. elif ls == 'Backup subscribes':
  34. os.system("bash bin/backup.sh")
  35. elif ls == 'Restore subscribes':
  36. os.system("bash bin/restore.sh")
  37. elif ls == 'Play by link':
  38. os.system(f"{run}linkage.py")
  39. elif ls == 'Update script':
  40. os.system("bash bin/backup.sh && mv backup.tar.gz .. && cd .. && rm -rf youtube-cli && git clone https://notabug.org/StalinKali/youtube-cli && cd youtube-cli && bash install.sh && mv ../backup.tar.gz . && echo \"Write backup.tar.gz\" && bash bin/restore.sh")
  41. try:
  42. global mirror
  43. with open('config/.mirror') as ff:
  44. mirror = ff.read()
  45. response = requests.get(f"https://{mirror}")
  46. main()
  47. except (FileNotFoundError, requests.ConnectionError, TimeoutError):
  48. main()
  49. except ProcessExecutionError:
  50. sys.exit()