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.

94 lines
3.5 KiB

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