diff --git a/README.md b/README.md index 762bab7..75b72f4 100644 --- a/README.md +++ b/README.md @@ -78,13 +78,19 @@ prismedia_upload - tool to upload videos to Peertube and Youtube Usage: prismedia_upload.py --file= [options] + prismedia_upload.py --file= --tags=STRING [--mt options] prismedia_upload.py -h | --help prismedia_upload.py --version Options: --name=NAME Name of the video to upload. (default to video filename) -d, --description=STRING Description of the video. (default: default description) - -t, --tags=STRING Tags for the video. comma separated + -t, --tags=STRING Tags for the video. comma separated. + WARN: tags with space and special characters (!, ', ", ?, ...) + are not supported by Mastodon to be published from Peertube + use mastodon compatibility below + --mt Force Mastodon compatibility for tags (drop every incompatible characters inside tags) + This option requires --tags -c, --category=STRING Category for the videos, see below. (default: Films) --cca License should be CreativeCommon Attribution (affects Youtube upload only) -p, --privacy=STRING Choose between public, unlisted or private. (default: private) @@ -122,6 +128,7 @@ Languages: - Support of all videos arguments (description, tags, category, licence, ...) - [x] description - [x] tags (no more than 30 characters per tag as Peertube does not support it) + - [x] Option to force tags to be compatible with Mastodon publication - [x] categories - [x] license: cca or not (Youtube only as Peertube uses Attribution by design) - [x] privacy (between public, unlisted or private) diff --git a/lib/pt_upload.py b/lib/pt_upload.py index 9c6c880..5b27fee 100644 --- a/lib/pt_upload.py +++ b/lib/pt_upload.py @@ -68,14 +68,17 @@ def upload_video(oauth, secret, options): if options.get('--tags'): tags = options.get('--tags').split(',') - for strtags in tags: + for strtag in tags: # Empty tag crashes Peertube, so skip them - if strtags == "": + if strtag == "": continue # Tag more than 30 chars crashes Peertube, so exit and check tags - if len(strtags) >= 30: + if len(strtag) >= 30: exit("Sorry, Peertube does not support tag with more than 30 characters, please reduce your tag size") - fields.append(("tags", strtags)) + # If Mastodon compatibility is enabled, clean tags from special characters + if options.get('--mt'): + strtag = utils.mastodonTag(strtag) + fields.append(("tags", strtag)) if options.get('--category'): fields.append(("category", str(utils.getCategory(options.get('--category'), 'peertube')))) diff --git a/lib/utils.py b/lib/utils.py index 63c1f58..9682dc6 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -3,6 +3,7 @@ from ConfigParser import RawConfigParser, NoOptionError, NoSectionError from os.path import dirname, splitext, basename, isfile +import unicodedata ### CATEGORIES ### YOUTUBE_CATEGORY = { @@ -154,3 +155,21 @@ def parseNFO(options): except NoSectionError: exit("Given NFO file miss section [video], please check syntax of your NFO.") return options + + +def upcaseFirstLetter(s): + return s[0].upper() + s[1:] + + +def mastodonTag(tag): + tags = tag.split(' ') + mtag = '' + for s in tags: + if s == '': + continue + strtag = unicodedata.normalize('NFKD', unicode (s, 'utf-8')).encode('ASCII', 'ignore') + strtag = ''.join(e for e in strtag if e.isalnum()) + strtag = upcaseFirstLetter(strtag) + mtag = mtag + strtag + + return mtag diff --git a/nfo_example.txt b/nfo_example.txt index 5ee2f8d..6de918f 100644 --- a/nfo_example.txt +++ b/nfo_example.txt @@ -9,6 +9,7 @@ name = videoname description = Your complete video description tags = list of tags, comma separated +mt = True category = Films cca = True privacy = private diff --git a/prismedia_upload.py b/prismedia_upload.py index e606fb8..deb039a 100755 --- a/prismedia_upload.py +++ b/prismedia_upload.py @@ -6,13 +6,19 @@ prismedia_upload - tool to upload videos to Peertube and Youtube Usage: prismedia_upload.py --file= [options] + prismedia_upload.py --file= --tags=STRING [--mt options] prismedia_upload.py -h | --help prismedia_upload.py --version Options: --name=NAME Name of the video to upload. (default to video filename) -d, --description=STRING Description of the video. (default: default description) - -t, --tags=STRING Tags for the video. comma separated + -t, --tags=STRING Tags for the video. comma separated. + WARN: tags with space and special characters (!, ', ", ?, ...) + are not supported by Mastodon to be published from Peertube + use mastodon compatibility below + --mt Force Mastodon compatibility for tags (drop every incompatible characters inside tags) + This option requires --tags -c, --category=STRING Category for the videos, see below. (default: Films) --cca License should be CreativeCommon Attribution (affects Youtube upload only) -p, --privacy=STRING Choose between public, unlisted or private. (default: private) @@ -146,6 +152,7 @@ if __name__ == '__main__': lambda x: not x.isdigit(), error="Tags should be a string") ), + Optional('--mt'): bool, Optional('--category'): Or(None, And( str, validateCategory,