menu.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from pyfzf.pyfzf import FzfPrompt
  2. import sys
  3. import os
  4. from config import player
  5. fzf = FzfPrompt()
  6. addition_menu_items = {
  7. "exit": "Exit",
  8. "level_up": "Level Up"
  9. }
  10. def terminate():
  11. print("EXIT")
  12. sys.exit()
  13. def item_do(item):
  14. os.system(f"{player} {item}")
  15. def show_menu(channels, video_titles, links):
  16. """Just 2 levels menu. Displays channels list and video titles in channels"""
  17. # appending additional menu items like Exit and level up
  18. channels.append(addition_menu_items["exit"])
  19. for item in video_titles:
  20. item.append(addition_menu_items["level_up"])
  21. def main_menu():
  22. main_choice = fzf.prompt(channels, '--cycle')
  23. try:
  24. if main_choice[0] == addition_menu_items["exit"]:
  25. return terminate()
  26. else:
  27. return channels.index(main_choice[0])
  28. except IndexError:
  29. return None
  30. main_index = main_menu()
  31. while True:
  32. if main_index is None:
  33. main_index = main_menu()
  34. item_choice = fzf.prompt(video_titles[main_index], '--cycle')
  35. try:
  36. if item_choice[0] != addition_menu_items["level_up"]:
  37. item_index = video_titles[main_index].index(item_choice[0])
  38. link = links[main_index][item_index]
  39. item_do(link)
  40. else:
  41. main_index = None
  42. except IndexError:
  43. pass