Scripting way to upload videos to peertube and youtube
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.8 KiB

  1. from configparser import RawConfigParser
  2. from os.path import splitext, basename, dirname, abspath
  3. class Configuration:
  4. """
  5. Configuration manager that read the configuration from multiples nfo files that are commons for all interfaces
  6. The configuration will be read and overridden in the following order:
  7. NFO.txt -> nfo.txt -> directory_name.txt -> video_file.txt -> video_name.txt
  8. (value in the rightmost file override values in preceding files)
  9. Your interface may add to this list from either side. Refer to the plugin's description.
  10. A plugin can also override completely this configuration by using other means. For example the cli plugins takes
  11. command line arguments with more importance than any nfo file.
  12. Attributes:
  13. CONFIG_FILE Filename for the base configuration file that should be used to set global behavior for
  14. prismedia and its plugins
  15. """
  16. CONFIG_FILE = "prismedia.config" # TODO: replace with "config.txt"? something else?
  17. def __init__(self):
  18. self.root_path = dirname(abspath(__file__))
  19. self.config_parser = RawConfigParser()
  20. self.configuration_file_list = []
  21. self.base_configuration_file = self.root_path + "/config/" + self.CONFIG_FILE
  22. self.config_parser.read(self.base_configuration_file)
  23. def read_commons_nfo(self, video_path, video_name):
  24. video_directory = dirname(video_path)
  25. directory_name = basename(video_directory)
  26. video_file = splitext(basename(video_path))[0]
  27. self.configuration_file_list.append(video_directory + "/" + "NFO.txt")
  28. self.configuration_file_list.append(video_directory + "/" + "nfo.txt")
  29. self.configuration_file_list.append(video_directory + "/" + directory_name + ".txt")
  30. self.configuration_file_list.append(video_directory + "/" + video_file + ".txt")
  31. if video_name and video_name != video_file:
  32. self.configuration_file_list.append(video_directory + "/" + video_name + ".txt")
  33. self.config_parser.read(self.configuration_file_list)
  34. # Do not use this in actual production ready code. Prismedia should not write any file
  35. # This can be used in local to see how a plugin's variable needs to be written in the global NFO
  36. # I am afraid that trying to save a plugin info will also save the current config for the video
  37. def _write_config(self):
  38. """
  39. Write the content of the ConfigParser in a file.
  40. """
  41. # Do not use `assert` since we want to do the opposite and optimize the other way around
  42. if not __debug__:
  43. raise AssertionError("The method `Configuration._write_config` should not be called in production")
  44. with open(self.base_configuration_file + "_generated", "w") as configFile:
  45. self.config_parser.write(configFile)
  46. configuration_instance = Configuration()