force_song.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python3
  2. # Copyright © 2024 Noah Vogt <noah@noahvogt.com>
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. import sys
  14. import colorama
  15. from PyQt5.QtWidgets import ( # pylint: disable=no-name-in-module
  16. QApplication,
  17. QMessageBox,
  18. )
  19. from utils import make_sure_file_exists, InfoMsgBox
  20. from song_switcher import switch_to_song
  21. from input import validate_obs_song_scene_switcher_config
  22. import config as const
  23. # pylint: disable=inconsistent-return-statements
  24. def get_force_int() -> int:
  25. try:
  26. return int(sys.argv[1])
  27. except IndexError:
  28. app = QApplication
  29. InfoMsgBox(
  30. QMessageBox.Critical,
  31. "Error",
  32. "couldn't parse force song integer",
  33. )
  34. del app
  35. sys.exit(1)
  36. def exit_if_force_int_is_illegal():
  37. force_int = get_force_int()
  38. msg = ""
  39. if force_int > const.OBS_MIN_SUBDIRS:
  40. msg = f"force integer {force_int} too big"
  41. if force_int < 1:
  42. msg = f"force integer {force_int} cannot be smaller than 1"
  43. if msg != "":
  44. app = QApplication
  45. InfoMsgBox(QMessageBox.Critical, "Error", msg)
  46. del app
  47. sys.exit(1)
  48. if __name__ == "__main__":
  49. colorama.init()
  50. validate_obs_song_scene_switcher_config()
  51. make_sure_file_exists(const.NEXTSONG_CACHE_FILE, gui_error_out=True)
  52. exit_if_force_int_is_illegal()
  53. switch_to_song(get_force_int())