diff --git a/prismedia/core.py b/prismedia/core.py index 0604666..f5c89a1 100644 --- a/prismedia/core.py +++ b/prismedia/core.py @@ -1,11 +1,15 @@ +#!/usr/bin/python +# coding: utf-8 + +import video + from yapsy.PluginManager import PluginManager import pluginInterfaces as pi import logging + # logging.basicConfig(level=logging.DEBUG) -def loadPlugins(type): - # Load the plugins from the plugin directory. - # TODO: subdirectories too? +def loadPlugins(): manager = PluginManager() manager.setPluginPlaces(["plugins"]) # TODO: Generate the absolute path @@ -14,49 +18,55 @@ def loadPlugins(type): manager.setCategoriesFilter({ "Interface" : pi.IInterfacePlugin, "Platform" : pi.IPlatformPlugin, + "Consumer" : pi.IConsumerPlugin, }) manager.collectPlugins() + return manager # TODO: Use the singleton PluginManager? - # Loop round the plugins and print their names. - print("debug") - print(manager.getAllPlugins()) - print("all plugins") - for plugin in manager.getAllPlugins(): - plugin.plugin_object.print_name() +print("# Plugins") +#def test_loadPlugins(arg): +manager = loadPlugins() +# Loop round the plugins and print their names. +print("debug") +print(manager.getAllPlugins()) - print("Category: Interface") - for plugin in manager.getPluginsOfCategory("Interface"): - plugin.plugin_object.print_name() +print("all plugins") +for plugin in manager.getAllPlugins(): + print(plugin.name) + # plugin.plugin_object.print_name() - print("Category: Platform") - for plugin in manager.getPluginsOfCategory("Platform"): - plugin.plugin_object.print_name() +print("Category: Interface") +for plugin in manager.getPluginsOfCategory("Interface"): + print(plugin.name) + # plugin.plugin_object.print_name() - # discovered_plugins = { - # name: importlib.import_module(name) - # for finder, name, ispkg - # in pkgutil.iter_modules(["/home/zykino/Documents/0DocPerso/Code/prismedia/plugins"]) - # if name.startswith("prismedia_" + type + "_") - # } +print("Category: Platform") +for plugin in manager.getPluginsOfCategory("Platform"): + print(plugin.name) + # plugin.plugin_object.print_name() -#def test_loadPlugins(arg): -platforms = loadPlugins("platform") -print (platforms) - -def startInterface(): - interface = loadPlugins("interface") - - options = interface["default"].run() - if options.get('--interface'): - if interface[options.get('--interface')]: - options = interface[options.get('--interface')].run(options) - else: - options = interface["cli"].run(options) - options = interface["nfo"].run(options) - -def uploadToPlatforms(options): - platforms = loadPlugins("platform") - for platform in options.get('--platform'): - platforms[platform].run(options) + +print() +print("# Video") +v = video.Video("/path/to/video") +v.name = "vidéo" +print(v.__dict__) +print(v.thumbnail) + +# def startInterface(): +# interface = loadPlugins() +# +# options = interface["default"].run() # Do I need this to extract basic cli? like an option "--interface=xxx" +# if options.get('--interface'): +# if interface[options.get('--interface')]: +# options = interface[options.get('--interface')].run(options) +# else: +# options = interface["cli"].run(options) +# options = interface["nfo"].run(options) +# +# def uploadToPlatforms(options): +# platforms = loadPlugins("platform") +# for platform in options.get('--platform'): +# platforms[platform].run(options) diff --git a/prismedia/plugins/platforms/peertube.py b/prismedia/plugins/platforms/peertube.py index 78780a2..d040f9a 100644 --- a/prismedia/plugins/platforms/peertube.py +++ b/prismedia/plugins/platforms/peertube.py @@ -66,8 +66,6 @@ LANGUAGE = { class Peertube(pi.IPlatformPlugin): """docstring for Peertube.""" - def print_name(self): - print("This is plugin peertube") def get_authenticated_service(secret): peertube_url = str(secret.get('peertube', 'peertube_url')).rstrip("/") @@ -249,7 +247,7 @@ class Peertube(pi.IPlatformPlugin): # https://github.com/requests/toolbelt/issues/190 and # https://github.com/requests/toolbelt/issues/205 fields = [ - ("name", options.get('--name') or splitext(basename(options.get('--file')))[0]), + ("name", options.get('--name')), ("licence", "1"), ("description", options.get('--description') or "default description"), ("nsfw", str(int(options.get('--nsfw')) or "0")), diff --git a/prismedia/plugins/platforms/youtube.py b/prismedia/plugins/platforms/youtube.py index 0faeb95..5b084d0 100644 --- a/prismedia/plugins/platforms/youtube.py +++ b/prismedia/plugins/platforms/youtube.py @@ -156,7 +156,7 @@ def initialize_upload(youtube, options): # and if empty, it does not cause problem during upload body = { "snippet": { - "title": options.get('--name') or splitext(basename(path))[0], + "title": options.get('--name'), "description": options.get('--description') or "default description", "tags": tags, # if no category, set default to 1 (Films) diff --git a/prismedia/utils.py b/prismedia/utils.py index 345e2ef..d8f66ee 100644 --- a/prismedia/utils.py +++ b/prismedia/utils.py @@ -136,31 +136,6 @@ def remove_empty_kwargs(**kwargs): return good_kwargs -def searchThumbnail(options): - video_directory = dirname(options.get('--file')) + "/" - # First, check for thumbnail based on videoname - if options.get('--name'): - if isfile(video_directory + options.get('--name') + ".jpg"): - options['--thumbnail'] = video_directory + options.get('--name') + ".jpg" - elif isfile(video_directory + options.get('--name') + ".jpeg"): - options['--thumbnail'] = video_directory + options.get('--name') + ".jpeg" - # Then, if we still not have thumbnail, check for thumbnail based on videofile name - if not options.get('--thumbnail'): - video_file = splitext(basename(options.get('--file')))[0] - if isfile(video_directory + video_file + ".jpg"): - options['--thumbnail'] = video_directory + video_file + ".jpg" - elif isfile(video_directory + video_file + ".jpeg"): - options['--thumbnail'] = video_directory + video_file + ".jpeg" - - # Display some info after research - if not options.get('--thumbnail'): - logger.debug("No thumbnail has been found, continuing") - else: - logger.info("Using " + options.get('--thumbnail') + " as thumbnail") - - return options - - def searchOriginalDate(options): fileModificationDate = str(getmtime(options.get('--file'))).split('.') return datetime.datetime.fromtimestamp(int(fileModificationDate[0])).isoformat() diff --git a/prismedia/video.py b/prismedia/video.py new file mode 100644 index 0000000..67d28b0 --- /dev/null +++ b/prismedia/video.py @@ -0,0 +1,81 @@ +from os.path import dirname, splitext, basename, isfile + +# 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, path): + self.path = path + self.thumbnail = None + self.name = None + self.description = "default description" + self.playlistName = None + 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 + # TODO: Create a platform object to have an common object/interface to use for each plugin? + self.platform = {} + + @property + def thumbnail(self): + if not self._thumbnail is 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 resporsability + # 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 not self._name is None: + return self._name + else: + return splitext(basename(self.path))[0] + + @name.setter + def name(self, value): + self._name = value