Browse Source

Add new feature to force compatibility tag with Mastodon publication (peertube)

develop
LecygneNoir 6 years ago
parent
commit
ac6db56355
5 changed files with 43 additions and 6 deletions
  1. +8
    -1
      README.md
  2. +7
    -4
      lib/pt_upload.py
  3. +19
    -0
      lib/utils.py
  4. +1
    -0
      nfo_example.txt
  5. +8
    -1
      prismedia_upload.py

+ 8
- 1
README.md View File

@ -78,13 +78,19 @@ prismedia_upload - tool to upload videos to Peertube and Youtube
Usage:
prismedia_upload.py --file=<FILE> [options]
prismedia_upload.py --file=<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)

+ 7
- 4
lib/pt_upload.py View File

@ -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'))))

+ 19
- 0
lib/utils.py View File

@ -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

+ 1
- 0
nfo_example.txt View File

@ -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

+ 8
- 1
prismedia_upload.py View File

@ -6,13 +6,19 @@ prismedia_upload - tool to upload videos to Peertube and Youtube
Usage:
prismedia_upload.py --file=<FILE> [options]
prismedia_upload.py --file=<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,

Loading…
Cancel
Save