import pluginInterfaces as pi import utils import configuration class Cli(pi.IInterfacePlugin): """ This is the default interface plugin. It is used when no interface plugin is specified. Its core functionality is available as a function call to `prepare_options(video, options)` if you do not need the Cli object. This can be useful to let other plugins to rely on the defaults behaviors proposed by this one and extend it. """ def prepare_options(self, video, options): prepare_options(video, options) def prepare_options(video, options): # TODO: Add the configuration file from the `--nfo` cli argument _store_docopt_to_configuration(video, options) _populate_configuration_into_video(video) def _store_docopt_to_configuration(options): items = {} for key, value in options: if key.startswith("--"): options.pop(key) items[key.strip("- ")] = value configuration.configuration_instance.config_parser.read_dict(items) def _populate_configuration_into_video(self, video): config = configuration.configuration_instance video.path = utils.getOption(config, "file", video.path) video.thumbnail = utils.getOption(config, "thumbnail", video.thumbnail) video.name = utils.getOption(config, "name", video.name) video.description = utils.getOption(config, "description", video.description) video.playlistName = utils.getOption(config, "playlist", video.playlistName) video.privacy = utils.getOption(config, "privacy", video.privacy).lower() video.category = utils.getOption(config, "category", video.category).lower() tags = utils.getOption(config, "tag", video.tags) if isinstance(tags, str): tags = tags.split(",") video.tags = tags video.language = utils.getOption(config, "language", video.language).lower() video.originalDate = utils.getOption(config, "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 = utils.getOption(config, "publish-at", video.publishAt) # TODO: Add a list of licences video.licence = utils.getOption(config, "licence", video.licence) video.disableComments = utils.getOption(config, "disable-comments", video.disableComments) video.nsfw = utils.getOption(config, "nsfw", video.nsfw) autoOriginalDate = utils.getOption(config, "auto-original-date", False) if autoOriginalDate: # TODO: Implement raise NotImplementedError("auto-original-date functionality is not yet implemented.") return video