From dffd3ffa842bc318bd3923c61e768f26ac4595eb Mon Sep 17 00:00:00 2001 From: Zykino Date: Sat, 10 Nov 2018 18:56:26 +0100 Subject: [PATCH] decode stdin strins arguments --- lib/utils.py | 14 ++++++++++---- prismedia_upload.py | 9 ++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/utils.py b/lib/utils.py index 772ff6b..11e09d5 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -123,7 +123,6 @@ 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,7 +167,6 @@ def loadNFO(options): logging.info("No suitable NFO found, skipping.") return False - def parseNFO(options): nfo = loadNFO(options) if nfo: @@ -189,11 +187,9 @@ def parseNFO(options): exit(1) return options - def upcaseFirstLetter(s): return s[0].upper() + s[1:] - def cleanString(toclean): toclean = toclean.split(' ') cleaned = '' @@ -208,3 +204,13 @@ def cleanString(toclean): cleaned = cleaned + strtoclean return cleaned + +def decodeArgumentStrings(options, encoding): + if options["--name"] is not None: + options["--name"] = options["--name"].decode(encoding) + + if options["--description"] is not None: + options["--description"] = options["--description"].decode(encoding) + + if options["--tags"] is not None: + options["--tags"] = options["--tags"].decode(encoding) diff --git a/prismedia_upload.py b/prismedia_upload.py index a300c96..6e5ee18 100755 --- a/prismedia_upload.py +++ b/prismedia_upload.py @@ -64,12 +64,12 @@ Languages: from os.path import dirname, realpath import sys import datetime +import locale import logging logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO) from docopt import docopt - # Allows a relative import from the parent folder sys.path.insert(0, dirname(realpath(__file__)) + "/lib") @@ -110,7 +110,6 @@ VALID_LANGUAGES = ('arabic', 'english', 'french', 'japanese', 'korean', 'mandarin', 'portuguese', 'punjabi', 'russian', 'spanish') - def validateVideo(path): supported_types = ['video/mp4'] if magic.from_file(path, mime=True) in supported_types: @@ -118,21 +117,18 @@ def validateVideo(path): else: return False - def validateCategory(category): if category.lower() in VALID_CATEGORIES: return True else: return False - def validatePrivacy(privacy): if privacy.lower() in VALID_PRIVACY_STATUSES: return True else: return False - def validatePlatform(platform): for plfrm in platform.split(','): if plfrm.lower().replace(" ", "") not in VALID_PLATFORM: @@ -140,14 +136,12 @@ def validatePlatform(platform): return True - def validateLanguage(language): if language.lower() in VALID_LANGUAGES: return True else: return False - def validatePublish(publish): # Check date format and if date is future try: @@ -222,6 +216,7 @@ if __name__ == '__main__': '--version': bool }) + utils.decodeArgumentStrings(options, locale.getpreferredencoding()) options = utils.parseNFO(options) if not options.get('--thumbnail'):