diff --git a/README.md b/README.md index cd712e9..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) @@ -149,8 +150,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 +164,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) diff --git a/lib/utils.py b/lib/utils.py index 772ff6b..e7e3635 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,17 @@ def cleanString(toclean): cleaned = cleaned + strtoclean 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; + + 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..d97ca1b 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: @@ -173,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, + basestring, lambda x: not x.isdigit(), error="The video name should be a string") ), Optional('--description'): Or(None, And( - str, + basestring, 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, + basestring, lambda x: not x.isdigit(), error="Tags should be a string") ), @@ -222,6 +216,7 @@ if __name__ == '__main__': '--version': bool }) + utils.decodeArgumentStrings(options, locale.getpreferredencoding()) options = utils.parseNFO(options) if not options.get('--thumbnail'):