1
0

stov_exceptions.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. # This file is part of stov, written by Helmut Pozimski 2012-2021.
  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. """This module contains all custome exceptions used by stov."""
  16. class DBConnectionFailedException(Exception):
  17. """ This exception will be raised when the initial connetion attempt
  18. to the database fails.
  19. """
  20. def __init__(self):
  21. super(DBConnectionFailedException, self).__init__()
  22. self.__message = _("Could not access the database, please check path"
  23. " and permissions and try again!")
  24. def __str__(self):
  25. return self.__message
  26. class DBWriteAccessFailedException(Exception):
  27. """This exception will be raised when a write access to the database fails
  28. (e.g. when the database file permissions are set to read only).
  29. """
  30. def __init__(self):
  31. super(DBWriteAccessFailedException, self).__init__()
  32. self.__message = _("Write access to the database failed, please check "
  33. "file permissions and the file system and try"
  34. " again!")
  35. def __str__(self):
  36. return self.__message
  37. class SubscriptionNotFoundException(Exception):
  38. """This exception will be raised when a requested subscription can't be
  39. found in the database
  40. """
  41. def __init__(self):
  42. super(SubscriptionNotFoundException, self).__init__()
  43. self.__message = _("The subscription you requested could not be "
  44. "found in the database, requested action aborted.")
  45. def __str__(self):
  46. return self.__message
  47. class NoDataFromYoutubeAPIException(Exception):
  48. """This exception will be raised when the Connection to the youtube API
  49. failed or no data was returned
  50. """
  51. def __init__(self):
  52. super(NoDataFromYoutubeAPIException, self).__init__()
  53. self.__message = _("The connection to the youtube API failed or "
  54. "no data was returned.")
  55. def __str__(self):
  56. return self.__message
  57. class YoutubeAPITimeoutException(Exception):
  58. """This exception will be raised when an API request times out"""
  59. def __init__(self, title):
  60. super(YoutubeAPITimeoutException, self).__init__()
  61. self.__message = _("The API Request timed out for subscription %s,"
  62. "please try again later.") % title
  63. def __str__(self):
  64. return self.__message
  65. class ConfigFileWriteErrorException(Exception):
  66. """This exception will be raised when a write access to the configuration
  67. file fails.
  68. """
  69. def __init__(self):
  70. super(ConfigFileWriteErrorException, self).__init__()
  71. self.__message = _("The configuration could not be written, please"
  72. " check that the configuration direcroty exists"
  73. " and is writable.")
  74. def __str__(self):
  75. return self.__message
  76. class DirectoryCreationFailedException(Exception):
  77. """This exception will be raised when the creation of a directory failed.
  78. """
  79. def __init__(self):
  80. super(DirectoryCreationFailedException, self).__init__()
  81. self.__message = _("The directory could not be created, "
  82. "please check that the parent directory "
  83. "exists and is writable")
  84. def __str__(self):
  85. return self.__message
  86. class ConfigFileReadErrorException(Exception):
  87. """This exception will be raised when the configuration file couldn't be
  88. opened for reading
  89. """
  90. def __init__(self):
  91. super(ConfigFileReadErrorException, self).__init__()
  92. self.__message = _("The configuration could not be read, please check "
  93. "that the configuration file exists and is "
  94. "readable.")
  95. def __str__(self):
  96. return self.__message
  97. class InvalidConfigurationVersionException(Exception):
  98. """This exception will be raised when an invalid configuration version
  99. is detected.
  100. """
  101. def __init__(self):
  102. super(InvalidConfigurationVersionException, self).__init__()
  103. self.__message = _("Invalid config version read.")
  104. def __str__(self):
  105. return self.__message
  106. class SubscriptionDisabledException(Exception):
  107. """This exception will be raised when an exception is disabled and
  108. a requested action is not taken because of this fact.
  109. """
  110. def __init__(self, subscription):
  111. super(SubscriptionDisabledException, self).__init__()
  112. self.__message = _("The subscription %s is disabled, videos will"
  113. " not be downloaded.") % subscription
  114. def __str__(self):
  115. return self.__message
  116. class DownloadDirectoryCreationFailedException(Exception):
  117. """This exception will be raised when the creation of a subscription
  118. directory to download a video failed.
  119. """
  120. def __init__(self):
  121. super(DownloadDirectoryCreationFailedException, self).__init__()
  122. self.__message = _("The download directory does not exist and can't "
  123. "be created. Please check your configuration and "
  124. "try again.")
  125. def __str__(self):
  126. return self.__message
  127. class ConfigurationMigrationFailed(Exception):
  128. """This exception will be raised when the migration of the configuration
  129. to the json format fails.
  130. """
  131. def __init__(self):
  132. super(ConfigurationMigrationFailed, self).__init__()
  133. self._message = _("The migration of the configuration to the json "
  134. "format failed.")
  135. def __str__(self):
  136. return self._message
  137. class YoutubeDlCallFailed(Exception):
  138. """This exception will be raised when a call to youtube-dl fails because
  139. of an error returned by youtube-dl.
  140. """
  141. def __init__(self):
  142. super(YoutubeDlCallFailed, self).__init__()
  143. self._message = _("Execution of youtube-dl failed.")
  144. def __str__(self):
  145. return self._message
  146. class ChannelNotFound(Exception):
  147. """ Will be raised when a specific user or channel cannot be found on
  148. the site.
  149. """
  150. def __init__(self):
  151. super(ChannelNotFound, self).__init__()
  152. self._message = _("Channel not found on video site")
  153. def __str__(self):
  154. return self._message
  155. class SiteUnsupported(Exception):
  156. """ Will be raised when stov is called for an unsupported site
  157. """
  158. def __init__(self):
  159. super(SiteUnsupported, self).__init__()
  160. self._message = _("Error: This site is not (yet) supported by stov!")
  161. def __str__(self):
  162. return self._message
  163. class TypeNotSupported(Exception):
  164. """ Will be raised when a video site does not support a specific
  165. subscription type
  166. """
  167. def __init__(self):
  168. super(TypeNotSupported, self).__init__()
  169. self._message = _("Error: This subscription type is not supported by "
  170. "the video site")
  171. def __str__(self):
  172. return self._message