main.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. conf = helpers.setup_configuration(arguments)
  30. logger = logging.getLogger("stov")
  31. database = helpers.setup_database(conf)
  32. helpers.find_youtubedl(conf)
  33. program.initialize_sites(database)
  34. if arguments.add:
  35. if arguments.site:
  36. program.add_subscription(conf, database,
  37. arguments.channel,
  38. arguments.searchparameter,
  39. arguments.playlist,
  40. arguments.site)
  41. else:
  42. program.add_subscription(conf, database, arguments.channel,
  43. arguments.searchparameter,
  44. arguments.playlist)
  45. elif arguments.lssites:
  46. program.list_sites(database)
  47. elif arguments.list:
  48. program.list_subscriptions(conf, database)
  49. elif arguments.deleteid:
  50. program.delete_subscription(database, arguments.deleteid)
  51. elif arguments.update is not None:
  52. program.update_subscriptions(database, conf, arguments.update)
  53. elif arguments.download is not None:
  54. program.download_notify(database, conf, arguments.download)
  55. elif arguments.subscriptionid:
  56. program.list_videos(database, conf, arguments.subscriptionid)
  57. elif arguments.catchup:
  58. program.catchup(database, arguments.catchup)
  59. elif arguments.cleanup:
  60. program.clean_database(database, conf)
  61. elif arguments.enableid:
  62. program.change_subscription_state(database, arguments.enableid, True)
  63. elif arguments.disableid:
  64. program.change_subscription_state(database, arguments.disableid, False)
  65. elif arguments.license:
  66. program.print_license()
  67. elif arguments.version:
  68. logger.info("1.2")
  69. else:
  70. parser.print_help()
  71. helpers.remove_lock()