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.

123 lines
4.1 KiB

  1. from os.path import dirname, splitext, basename, isfile, normpath, expanduser
  2. class Platform(object):
  3. """
  4. Store data representing a Platform.
  5. """
  6. def __init__(self):
  7. self.error = None
  8. self.publishAt = None
  9. self.url = None
  10. def __repr__(self):
  11. return str(self.__dict__)
  12. # TODO: Add container for `with-*` and a `isValid` method to check that all `with-*` options are present
  13. # TODO: We need some list (using enum?) for the commons licences, language, privacy, categories options
  14. class Video(object):
  15. """
  16. Store data representing a Video.
  17. """
  18. def __init__(self):
  19. self.path = ""
  20. self.thumbnail = None
  21. self.name = None
  22. self.description = "Video uploaded with Prismedia"
  23. self.playlistName = None
  24. self.playlistCreate = False
  25. self.privacy = "private"
  26. self.category = "films"
  27. self.tags = []
  28. self.language = "english"
  29. self.originalDate = None # TODO: add a method "extract original date"? -> I feal that needs to be done outside of this class
  30. # TODO: set as an object: { "all": date1, "platformX": date2, …}?
  31. # Maybe the publishAt by platform is better placed in `self.platform`
  32. # And so publishAt would only contains the global date.
  33. self.publishAt = None
  34. # TODO: Add a list of licences
  35. self.licence = "proprietary"
  36. self.disableComments = False
  37. self.nsfw = False
  38. # Each platform should insert here the upload state
  39. self.platform = {}
  40. @property
  41. def path(self):
  42. return self._path
  43. @path.setter
  44. def path(self, value):
  45. path = normpath(expanduser(value))
  46. if value == "":
  47. self._path = ""
  48. elif isfile(path):
  49. self._path = path
  50. else:
  51. # TODO: log instead to debug? info?
  52. print("The path `" + value + "` does not point to a video")
  53. self._path = ""
  54. @property
  55. def thumbnail(self):
  56. if self._thumbnail is not None:
  57. return self._thumbnail
  58. else:
  59. result = None
  60. video_directory = dirname(self.path) + "/"
  61. # First, check for thumbnail based on videoname
  62. if isfile(video_directory + self.name + ".jpg"):
  63. result = video_directory + self.name + ".jpg"
  64. elif isfile(video_directory + self.name + ".jpeg"):
  65. result = video_directory + self.name + ".jpeg"
  66. # Then, if we still not have thumbnail, check for thumbnail based on videofile name
  67. # NOTE: This may be a the exact same check from the previous conditions if self._name = None.
  68. # Bus as far as I know it is not recommended to use privates properties even in the same class
  69. # Maybe check if self.name == splitext(basename(self.path))[0]
  70. # Not done since it is early dev for the plugins rewrite
  71. if not result:
  72. video_file = splitext(basename(self.path))[0]
  73. if isfile(video_directory + video_file + ".jpg"):
  74. result = video_directory + video_file + ".jpg"
  75. elif isfile(video_directory + video_file + ".jpeg"):
  76. result = video_directory + video_file + ".jpeg"
  77. # TODO: move to caller. Logging the output is its responsibility
  78. # Display some info after research
  79. # if not result:
  80. # logger.debug("No thumbnail has been found, continuing")
  81. # else:
  82. # logger.info("Using " + result + " as thumbnail")
  83. return result
  84. @thumbnail.setter
  85. def thumbnail(self, value):
  86. self._thumbnail = value
  87. @property
  88. def name(self):
  89. if self._name is not None:
  90. return self._name
  91. else:
  92. return splitext(basename(self.path))[0]
  93. @name.setter
  94. def name(self, value):
  95. self._name = value
  96. def __repr__(self):
  97. result = "{\n"
  98. for key in self.__dict__:
  99. result += "\t'" + key + "': " + str(self.__dict__[key]) + ",\n"
  100. result += "}\n"
  101. return result