force_song.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 (
  20. make_sure_file_exists,
  21. )
  22. from song_switcher import switch_to_song
  23. from input import validate_obs_song_scene_switcher_config, InfoMsgBox
  24. import config as const
  25. # pylint: disable=inconsistent-return-statements
  26. def get_force_int() -> int:
  27. try:
  28. return int(sys.argv[1])
  29. except IndexError:
  30. app = QApplication
  31. InfoMsgBox(
  32. QMessageBox.Critical,
  33. "Error",
  34. "couldn't parse force song integer",
  35. )
  36. del app
  37. sys.exit(1)
  38. def exit_if_force_int_is_illegal():
  39. force_int = get_force_int()
  40. msg = ""
  41. if force_int > const.OBS_MIN_SUBDIRS:
  42. msg = f"force integer {force_int} too big"
  43. if force_int < 1:
  44. msg = f"force integer {force_int} cannot be smaller than 1"
  45. if msg != "":
  46. app = QApplication
  47. InfoMsgBox(QMessageBox.Critical, "Error", msg)
  48. del app
  49. sys.exit(1)
  50. if __name__ == "__main__":
  51. colorama.init()
  52. validate_obs_song_scene_switcher_config()
  53. make_sure_file_exists(const.NEXTSONG_CACHE_FILE, gui_error_out=True)
  54. exit_if_force_int_is_illegal()
  55. switch_to_song(get_force_int())