Browse Source

WIP Populate the Video object

plugins
Zykino 3 years ago
parent
commit
bcfc8e723a
3 changed files with 111 additions and 30 deletions
  1. +78
    -0
      prismedia/cli.py
  2. +18
    -28
      prismedia/core.py
  3. +15
    -2
      prismedia/video.py

+ 78
- 0
prismedia/cli.py View File

@ -0,0 +1,78 @@
import pluginInterfaces as pi
import video as vid
from yapsy.PluginManager import PluginManagerSingleton
def helperFunctionnality(options):
optionName = "--list-plugins"
if options.get(optionName):
_listPlugins()
return True
else:
options.pop(optionName)
optionName = "--hearthbeat"
if options.get(optionName):
for plugin in manager.getPluginsOfCategory(pi.PluginTypes.PLATFORM):
plugin.plugin_object.hearthbeat()
return True
else:
options.pop(optionName)
return False
def parseOptions(options):
video = vid.Video()
video.path = _getOption(options, "--file", video.path)
video.thumbnail = _getOption(options, "--thumbnail", video.thumbnail)
video.name = _getOption(options, "--name", video.name)
video.description = _getOption(options, "--description", video.description)
video.playlistName = _getOption(options, "--playlist", video.playlistName)
video.privacy = _getOption(options, "--privacy", video.privacy)
video.category = _getOption(options, "--category", video.category)
video.tags = _getOption(options, "--tag", video.tags)
video.language = _getOption(options, "--language", video.language)
video.originalDate = _getOption(options, "--original-date", video.originalDate)
# 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.
video.publishAt = _getOption(options, "--publish-at", video.publishAt)
# TODO: Add a list of licences
video.licence = _getOption(options, "--licence", video.licence)
video.disableComments = _getOption(options, "--disable-comments", video.disableComments)
video.nsfw = _getOption(options, "--nsfw", video.nsfw)
autoOriginalDate = _getOption(options, "--auto-original-date", False)
if autoOriginalDate:
raise Exception("Unimplemented!")
return video
def _getOption(options, optionName, defaultValue = None):
value = options.get(optionName)
options.pop(optionName)
if value is None:
return defaultValue
return value
def _listPlugins():
manager = PluginManagerSingleton.get()
print("The plugins are stored in the following folders:", manager.getPluginLocator().plugins_places)
print("Category:", pi.PluginTypes.INTERFACE.value)
for plugin in manager.getPluginsOfCategory(pi.PluginTypes.INTERFACE):
print("\t" + plugin.name)
print("Category:", pi.PluginTypes.PLATFORM.value)
for plugin in manager.getPluginsOfCategory(pi.PluginTypes.PLATFORM):
print("\t" + plugin.name)
print("Category:", pi.PluginTypes.CONSUMER.value)
for plugin in manager.getPluginsOfCategory(pi.PluginTypes.CONSUMER):
print("\t" + plugin.name)

+ 18
- 28
prismedia/core.py View File

@ -104,11 +104,12 @@ Languages:
Korean, Mandarin, Portuguese, Punjabi, Russian, Spanish
"""
import video
import cli
import pluginInterfaces as pi
import video as vid
from docopt import docopt
from yapsy.PluginManager import PluginManagerSingleton
import pluginInterfaces as pi
import os
import logging
@ -130,22 +131,6 @@ def loadPlugins(basePluginsPath):
manager.collectPlugins()
def listPlugins():
manager = PluginManagerSingleton.get()
print("The plugins are stored in the following folders:", manager.getPluginLocator().plugins_places)
print("Category:", pi.PluginTypes.INTERFACE.value)
for plugin in manager.getPluginsOfCategory(pi.PluginTypes.INTERFACE):
print(plugin.name)
print("Category:", pi.PluginTypes.PLATFORM.value)
for plugin in manager.getPluginsOfCategory(pi.PluginTypes.PLATFORM):
print(plugin.name)
print("Category:", pi.PluginTypes.CONSUMER.value)
for plugin in manager.getPluginsOfCategory(pi.PluginTypes.CONSUMER):
print(plugin.name)
def main():
basePluginsPath = [os.path.dirname(os.path.abspath(__file__)) + "/plugins"]
@ -154,17 +139,22 @@ def main():
# TODO: add the arguments’s verification (copy/adapt the Schema table)
options = docopt(__doc__, version=VERSION)
print(options)
# Treat options that do not involve
if options.get('--list-plugins'):
listPlugins()
exit(0)
# Helper functionnalities help the user but do not upload anything
if cli.helperFunctionnality(options):
print(options)
exit(0) # TODO: Magic error code
if options.get('--hearthbeat'):
for plugin in manager.getPluginsOfCategory(pi.PluginTypes.PLATFORM):
plugin.plugin_object.hearthbeat()
exit(0)
video = cli.parseOptions(options)
if options["<interface>"]:
pass # TODO: call the interface the user asked for
if video.path is None:
# TODO: log instead to error ? critical ?
print("No valid path to a video file has been provided.")
exit(1) # TODO: Magic error code
print(options)
print()
print("# Plugins")
@ -180,7 +170,7 @@ def main():
print()
print("# Video")
v = video.Video("/path/to/video")
v = vid.Video()
v.name = "vidéo"
print(v.__dict__)
print(v.thumbnail)

+ 15
- 2
prismedia/video.py View File

@ -4,8 +4,8 @@ from os.path import dirname, splitext, basename, isfile
class Video(object):
"""Store data representing a Video."""
def __init__(self, path):
self.path = path
def __init__(self):
self.path = ""
self.thumbnail = None
self.name = None
self.description = "default description"
@ -30,6 +30,19 @@ class Video(object):
# TODO: Create a platform object to have an common object/interface to use for each plugin?
self.platform = {}
@property
def path(self):
return self._path
@path.setter
def path(self, value):
if value == "" or isfile(value):
self._path = value
else:
# TODO: log instead to debug ? info ?
print("The path `" + value + "` does not contain a valid video")
self.path = ""
@property
def thumbnail(self):
if not self._thumbnail is None:

Loading…
Cancel
Save