From 80a7f071948c095f2f8ed473d1f27ce1d691086e Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 19 Feb 2019 11:24:43 +0100 Subject: [PATCH] move sample file into config submodule, genconfig command instead --- README.md | 3 ++- prismedia/__init__.py | 1 + .../config/nfo_example.txt | 0 .../config/peertube_secret.sample | 0 .../config/youtube_secret.json.sample | 0 prismedia/genconfig.py | 15 +++++++++++++++ prismedia/utils.py | 12 ++++++++++-- 7 files changed, 28 insertions(+), 3 deletions(-) rename nfo_example.txt => prismedia/config/nfo_example.txt (100%) rename peertube_secret.sample => prismedia/config/peertube_secret.sample (100%) rename youtube_secret.json.sample => prismedia/config/youtube_secret.json.sample (100%) create mode 100644 prismedia/genconfig.py diff --git a/README.md b/README.md index 5761e06..619bc51 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ poetry install # installs the dependency in a virtualenv specific to the project ## Configuration -Edit `peertube_secret` and `youtube_secret.json` with your credentials. +Generate sample files with `python -m prismedia.genconfig`. Edit +`peertube_secret` and `youtube_secret.json` with your credentials. ### Peertube diff --git a/prismedia/__init__.py b/prismedia/__init__.py index 37de3b8..4c3ebaf 100644 --- a/prismedia/__init__.py +++ b/prismedia/__init__.py @@ -1 +1,2 @@ from . import upload +from . import genconfig diff --git a/nfo_example.txt b/prismedia/config/nfo_example.txt similarity index 100% rename from nfo_example.txt rename to prismedia/config/nfo_example.txt diff --git a/peertube_secret.sample b/prismedia/config/peertube_secret.sample similarity index 100% rename from peertube_secret.sample rename to prismedia/config/peertube_secret.sample diff --git a/youtube_secret.json.sample b/prismedia/config/youtube_secret.json.sample similarity index 100% rename from youtube_secret.json.sample rename to prismedia/config/youtube_secret.json.sample diff --git a/prismedia/genconfig.py b/prismedia/genconfig.py new file mode 100644 index 0000000..f03e423 --- /dev/null +++ b/prismedia/genconfig.py @@ -0,0 +1,15 @@ +from os.path import join, abspath, isfile, dirname +from os import listdir +from shutil import copyfile + + +def genconfig(): + path = join(dirname(__file__), 'config') + files = [f for f in listdir(path) if isfile(join(path, f))] + + for f in files: + copyfile(join(path, f), f) + + +if __name__ == '__main__': + genconfig() diff --git a/prismedia/utils.py b/prismedia/utils.py index 1602ab6..f2984b7 100644 --- a/prismedia/utils.py +++ b/prismedia/utils.py @@ -107,6 +107,7 @@ def remove_empty_kwargs(**kwargs): good_kwargs[key] = value return good_kwargs + def searchThumbnail(options): video_directory = dirname(options.get('--file')) + "/" # First, check for thumbnail based on videoname @@ -124,6 +125,7 @@ def searchThumbnail(options): options['--thumbnail'] = video_directory + video_file + ".jpeg" return options + # return the nfo as a RawConfigParser object def loadNFO(options): video_directory = dirname(options.get('--file')) + "/" @@ -168,10 +170,12 @@ def loadNFO(options): logging.info("No suitable NFO found, skipping.") return False + def parseNFO(options): nfo = loadNFO(options) if nfo: - # We need to check all options and replace it with the nfo value if not defined (None or False) + # We need to check all options and replace it with the nfo value if not + # defined (None or False) for key, value in options.iteritems(): key = key.replace("-", "") try: @@ -188,9 +192,11 @@ def parseNFO(options): exit(1) return options + def upcaseFirstLetter(s): return s[0].upper() + s[1:] + def cleanString(toclean): toclean = toclean.decode('utf-8') toclean = unidecode.unidecode(toclean) @@ -198,10 +204,11 @@ def cleanString(toclean): return cleaned + def decodeArgumentStrings(options, encoding): # Python crash when decoding from UTF-8 to UTF-8, so we prevent this if "utf-8" == encoding.lower(): - return; + return if options["--name"] is not None: options["--name"] = options["--name"].decode(encoding) @@ -211,3 +218,4 @@ def decodeArgumentStrings(options, encoding): if options["--tags"] is not None: options["--tags"] = options["--tags"].decode(encoding) +