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: Usage:
prismedia_upload.py --file=<FILE> [options] prismedia_upload.py --file=<FILE> [options]
prismedia_upload.py --file=<FILE> --tags=STRING [--mt options]
prismedia_upload.py -h | --help prismedia_upload.py -h | --help
prismedia_upload.py --version prismedia_upload.py --version
Options: Options:
--name=NAME Name of the video to upload. (default to video filename) --name=NAME Name of the video to upload. (default to video filename)
-d, --description=STRING Description of the video. (default: default description) -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) -c, --category=STRING Category for the videos, see below. (default: Films)
--cca License should be CreativeCommon Attribution (affects Youtube upload only) --cca License should be CreativeCommon Attribution (affects Youtube upload only)
-p, --privacy=STRING Choose between public, unlisted or private. (default: private) -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, ...) - Support of all videos arguments (description, tags, category, licence, ...)
- [x] description - [x] description
- [x] tags (no more than 30 characters per tag as Peertube does not support it) - [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] categories
- [x] license: cca or not (Youtube only as Peertube uses Attribution by design) - [x] license: cca or not (Youtube only as Peertube uses Attribution by design)
- [x] privacy (between public, unlisted or private) - [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'): if options.get('--tags'):
tags = options.get('--tags').split(',') tags = options.get('--tags').split(',')
for strtags in tags:
for strtag in tags:
# Empty tag crashes Peertube, so skip them # Empty tag crashes Peertube, so skip them
if strtags == "":
if strtag == "":
continue continue
# Tag more than 30 chars crashes Peertube, so exit and check tags # 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") 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'): if options.get('--category'):
fields.append(("category", str(utils.getCategory(options.get('--category'), 'peertube')))) 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 ConfigParser import RawConfigParser, NoOptionError, NoSectionError
from os.path import dirname, splitext, basename, isfile from os.path import dirname, splitext, basename, isfile
import unicodedata
### CATEGORIES ### ### CATEGORIES ###
YOUTUBE_CATEGORY = { YOUTUBE_CATEGORY = {
@ -154,3 +155,21 @@ def parseNFO(options):
except NoSectionError: except NoSectionError:
exit("Given NFO file miss section [video], please check syntax of your NFO.") exit("Given NFO file miss section [video], please check syntax of your NFO.")
return options 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 name = videoname
description = Your complete video description description = Your complete video description
tags = list of tags, comma separated tags = list of tags, comma separated
mt = True
category = Films category = Films
cca = True cca = True
privacy = private privacy = private

+ 8
- 1
prismedia_upload.py View File

@ -6,13 +6,19 @@ prismedia_upload - tool to upload videos to Peertube and Youtube
Usage: Usage:
prismedia_upload.py --file=<FILE> [options] prismedia_upload.py --file=<FILE> [options]
prismedia_upload.py --file=<FILE> --tags=STRING [--mt options]
prismedia_upload.py -h | --help prismedia_upload.py -h | --help
prismedia_upload.py --version prismedia_upload.py --version
Options: Options:
--name=NAME Name of the video to upload. (default to video filename) --name=NAME Name of the video to upload. (default to video filename)
-d, --description=STRING Description of the video. (default: default description) -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) -c, --category=STRING Category for the videos, see below. (default: Films)
--cca License should be CreativeCommon Attribution (affects Youtube upload only) --cca License should be CreativeCommon Attribution (affects Youtube upload only)
-p, --privacy=STRING Choose between public, unlisted or private. (default: private) -p, --privacy=STRING Choose between public, unlisted or private. (default: private)
@ -146,6 +152,7 @@ if __name__ == '__main__':
lambda x: not x.isdigit(), lambda x: not x.isdigit(),
error="Tags should be a string") error="Tags should be a string")
), ),
Optional('--mt'): bool,
Optional('--category'): Or(None, And( Optional('--category'): Or(None, And(
str, str,
validateCategory, validateCategory,

Loading…
Cancel
Save