main.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # This file is part of stov, written by Helmut Pozimski 2012-2017.
  2. #
  3. # stov 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, version 2 of the License.
  6. #
  7. # stov 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. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with stov. If not, see <http://www.gnu.org/licenses/>.
  14. # -*- coding: utf8 -*-
  15. """ Contains the main function of stov to start the application.
  16. """
  17. import logging
  18. from lib_stov import helpers
  19. from lib_stov import program
  20. def main():
  21. """
  22. Main function
  23. """
  24. helpers.initialize_gettext()
  25. helpers.setup_sighandler()
  26. parser = helpers.parse_arguments()
  27. arguments = parser.parse_args()
  28. helpers.create_lock()
  29. helpers.setup_configuration(arguments)
  30. logger = logging.getLogger("stov")
  31. helpers.setup_database()
  32. helpers.find_youtubedl()
  33. program.initialize_sites()
  34. if arguments.add:
  35. if arguments.site:
  36. program.add_subscription(arguments.channel,
  37. arguments.searchparameter,
  38. arguments.playlist, arguments.site)
  39. else:
  40. program.add_subscription(arguments.channel,
  41. arguments.searchparameter,
  42. arguments.playlist)
  43. elif arguments.lssites:
  44. program.list_sites()
  45. elif arguments.list:
  46. program.list_subscriptions()
  47. elif arguments.deleteid:
  48. program.delete_subscription(arguments.deleteid)
  49. elif arguments.update is not None:
  50. program.update_subscriptions(arguments.update)
  51. elif arguments.download is not None:
  52. program.download_notify(arguments.download)
  53. elif arguments.subscriptionid:
  54. program.list_videos(arguments.subscriptionid)
  55. elif arguments.catchup:
  56. program.catchup(arguments.catchup)
  57. elif arguments.cleanup:
  58. program.clean_database()
  59. elif arguments.enableid:
  60. program.change_subscription_state(arguments.enableid, True)
  61. elif arguments.disableid:
  62. program.change_subscription_state(arguments.disableid, False)
  63. elif arguments.license:
  64. program.print_license()
  65. elif arguments.version:
  66. logger.info("1.2.1")
  67. else:
  68. parser.print_help()
  69. helpers.remove_lock()