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

from os.path import dirname, splitext, basename, isfile, normpath, expanduser
class Platform(object):
"""
Store data representing a Platform.
"""
def __init__(self):
self.error = None
self.publishAt = None
self.url = None
def __repr__(self):
return str(self.__dict__)
# TODO: Add container for `with-*` and a `isValid` method to check that all `with-*` options are present
# TODO: We need some list (using enum?) for the commons licences, language, privacy, categories options
class Video(object):
"""
Store data representing a Video.
"""
def __init__(self):
self.path = ""
self.thumbnail = None
self.name = None
self.description = "Video uploaded with Prismedia"
self.playlistName = None
self.playlistCreate = False
self.privacy = "private"
self.category = "films"
self.tags = []
self.language = "english"
self.originalDate = None # TODO: add a method "extract original date"? -> I feal that needs to be done outside of this class
# TODO: set as an object: { "all": date1, "platformX": date2, …}?
# Maybe the publishAt by platform is better placed in `self.platform`
# And so publishAt would only contains the global date.
self.publishAt = None
# TODO: Add a list of licences
self.licence = "proprietary"
self.disableComments = False
self.nsfw = False
# Each platform should insert here the upload state
self.platform = {}
@property
def path(self):
return self._path
@path.setter
def path(self, value):
path = normpath(expanduser(value))
if value == "":
self._path = ""
elif isfile(path):
self._path = path
else:
# TODO: log instead to debug? info?
print("The path `" + value + "` does not point to a video")
self._path = ""
@property
def thumbnail(self):
if self._thumbnail is not None:
return self._thumbnail
else:
result = None
video_directory = dirname(self.path) + "/"
# First, check for thumbnail based on videoname
if isfile(video_directory + self.name + ".jpg"):
result = video_directory + self.name + ".jpg"
elif isfile(video_directory + self.name + ".jpeg"):
result = video_directory + self.name + ".jpeg"
# Then, if we still not have thumbnail, check for thumbnail based on videofile name
# NOTE: This may be a the exact same check from the previous conditions if self._name = None.
# Bus as far as I know it is not recommended to use privates properties even in the same class
# Maybe check if self.name == splitext(basename(self.path))[0]
# Not done since it is early dev for the plugins rewrite
if not result:
video_file = splitext(basename(self.path))[0]
if isfile(video_directory + video_file + ".jpg"):
result = video_directory + video_file + ".jpg"
elif isfile(video_directory + video_file + ".jpeg"):
result = video_directory + video_file + ".jpeg"
# TODO: move to caller. Logging the output is its responsibility
# Display some info after research
# if not result:
# logger.debug("No thumbnail has been found, continuing")
# else:
# logger.info("Using " + result + " as thumbnail")
return result
@thumbnail.setter
def thumbnail(self, value):
self._thumbnail = value
@property
def name(self):
if self._name is not None:
return self._name
else:
return splitext(basename(self.path))[0]
@name.setter
def name(self, value):
self._name = value
def __repr__(self):
result = "{\n"
for key in self.__dict__:
result += "\t'" + key + "': " + str(self.__dict__[key]) + ",\n"
result += "}\n"
return result