From dffd3ffa842bc318bd3923c61e768f26ac4595eb Mon Sep 17 00:00:00 2001 From: Zykino Date: Sat, 10 Nov 2018 18:56:26 +0100 Subject: [PATCH 1/7] 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'): From dbcd2ff0109680a7ded20d337497cbf67a89679d Mon Sep 17 00:00:00 2001 From: Zykino Date: Sat, 10 Nov 2018 19:13:36 +0100 Subject: [PATCH 2/7] update the README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cd712e9..9bad074 100644 --- a/README.md +++ b/README.md @@ -149,8 +149,8 @@ Languages: - [x] set default language - [x] thumbnail/preview - [x] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4)) - - [x] add videos to playlist for Peertube - - [x] add videos to playlist for Youtube + - [x] add videos to playlist + - [x] create playlist - [x] Use a config file (NFO) file to retrieve videos arguments - [x] Allow to choose peertube or youtube upload (to resume failed upload for example) - [x] Add publishAt option to plan your videos @@ -163,4 +163,4 @@ Languages: If your server uses peertube before 1.0.0-beta4, use the version inside tag 1.0.0-beta3! ## Sources -inspired by [peeror](https://git.rigelk.eu/rigelk/peeror) and [youtube-upload](https://github.com/tokland/youtube-upload) \ No newline at end of file +inspired by [peeror](https://git.rigelk.eu/rigelk/peeror) and [youtube-upload](https://github.com/tokland/youtube-upload) From 617e989154352d685bc54cf37ba45ae0c30f0852 Mon Sep 17 00:00:00 2001 From: Zykino Date: Sun, 11 Nov 2018 13:00:47 +0100 Subject: [PATCH 3/7] fix error message --- prismedia_upload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prismedia_upload.py b/prismedia_upload.py index 6e5ee18..22accf9 100755 --- a/prismedia_upload.py +++ b/prismedia_upload.py @@ -174,7 +174,7 @@ if __name__ == '__main__': Optional('--description'): Or(None, And( str, lambda x: not x.isdigit(), - error="The video name should be a string") + error="The video description should be a string") ), Optional('--tags'): Or(None, And( str, From 6c68c3363bbc36fed94e302a4725f20009c109bc Mon Sep 17 00:00:00 2001 From: Zykino Date: Sun, 11 Nov 2018 14:31:51 +0100 Subject: [PATCH 4/7] prevent decoding unicode strings since python prefer to crash than doing nothing --- lib/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/utils.py b/lib/utils.py index 11e09d5..9ccfdb5 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -206,6 +206,10 @@ def cleanString(toclean): return cleaned def decodeArgumentStrings(options, encoding): + # Python crash when decding from UTF-8 to UTF-8, so we prevent this + if "utf-8" == encoding.lower(): + return; + if options["--name"] is not None: options["--name"] = options["--name"].decode(encoding) From 8d8898aa5578df8ea702e8977886343ed5d12830 Mon Sep 17 00:00:00 2001 From: Zykino Date: Sun, 11 Nov 2018 16:52:48 +0100 Subject: [PATCH 5/7] The strings arguments should be in unicode --- prismedia_upload.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prismedia_upload.py b/prismedia_upload.py index 22accf9..d2bfb8b 100755 --- a/prismedia_upload.py +++ b/prismedia_upload.py @@ -167,17 +167,17 @@ if __name__ == '__main__': schema = Schema({ '--file': And(str, validateVideo, error='file is not supported, please use mp4'), Optional('--name'): Or(None, And( - str, + unicode, lambda x: not x.isdigit(), error="The video name should be a string") ), Optional('--description'): Or(None, And( - str, + unicode, lambda x: not x.isdigit(), error="The video description should be a string") ), Optional('--tags'): Or(None, And( - str, + unicode, lambda x: not x.isdigit(), error="Tags should be a string") ), From f66ba6cc21e1c83fc2b32ec94294d1f7bd079c65 Mon Sep 17 00:00:00 2001 From: Zykino Date: Wed, 28 Nov 2018 00:50:38 +0100 Subject: [PATCH 6/7] string from URF-8 encoded files have not the "unicode" type --- README.md | 3 ++- prismedia_upload.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9bad074..a813848 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,8 @@ Options: --disable-comments Disable comments (Peertube only as YT API does not support) (default: comments are enabled) --nsfw Set the video as No Safe For Work (Peertube only as YT API does not support) (default: video is safe) --nfo=STRING Configure a specific nfo file to set options for the video. - By default Prismedia search a .txt based on video name + By default Prismedia search a .txt based on the video name and will + decode the file as UTF-8 (so make sure your nfo file is UTF-8 encoded) See nfo_example.txt for more details --platform=STRING List of platform(s) to upload to, comma separated. Supported platforms are youtube and peertube (default is both) diff --git a/prismedia_upload.py b/prismedia_upload.py index d2bfb8b..d97ca1b 100755 --- a/prismedia_upload.py +++ b/prismedia_upload.py @@ -167,17 +167,17 @@ if __name__ == '__main__': schema = Schema({ '--file': And(str, validateVideo, error='file is not supported, please use mp4'), Optional('--name'): Or(None, And( - unicode, + basestring, lambda x: not x.isdigit(), error="The video name should be a string") ), Optional('--description'): Or(None, And( - unicode, + basestring, lambda x: not x.isdigit(), error="The video description should be a string") ), Optional('--tags'): Or(None, And( - unicode, + basestring, lambda x: not x.isdigit(), error="Tags should be a string") ), From bddf2ee414e1c4d542bf3608386deda1a9bc24a6 Mon Sep 17 00:00:00 2001 From: Zykino Date: Tue, 11 Dec 2018 01:17:23 +0100 Subject: [PATCH 7/7] fix typo --- lib/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.py b/lib/utils.py index 9ccfdb5..e7e3635 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -206,7 +206,7 @@ def cleanString(toclean): return cleaned def decodeArgumentStrings(options, encoding): - # Python crash when decding from UTF-8 to UTF-8, so we prevent this + # Python crash when decoding from UTF-8 to UTF-8, so we prevent this if "utf-8" == encoding.lower(): return;