From d3a42c4be1bc35218189ed69334748da00296537 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Mon, 15 Oct 2018 12:42:40 +0200 Subject: [PATCH] Patch playlist to be comaptible with beta16 (using name AND display name) --- lib/pt_upload.py | 11 ++++++----- lib/utils.py | 18 +++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/pt_upload.py b/lib/pt_upload.py index 4b57614..6e3a9cf 100644 --- a/lib/pt_upload.py +++ b/lib/pt_upload.py @@ -62,9 +62,10 @@ def get_playlist_by_name(user_info, options): def create_playlist(oauth, url, options): - template = ('Peertube : Playlist %s does not exist, creating it.') + template = ('Peertube: Playlist %s does not exist, creating it.') logging.info(template % (str(options.get('--playlist')))) - data = '{"displayName":"' + str(options.get('--playlist')) +'", \ + data = '{"name":"' + utils.cleanString(str(options.get('--playlist'))) +'", \ + "displayName":"' + str(options.get('--playlist')) +'", \ "description":null}' headers = { @@ -85,7 +86,7 @@ def create_playlist(oauth, url, options): jresponse = jresponse['videoChannel'] return jresponse['id'] else: - logging.error(('Peertube : The upload failed with an unexpected response: ' + logging.error(('Peertube: The upload failed with an unexpected response: ' '%s') % response) exit(1) @@ -101,7 +102,7 @@ def upload_video(oauth, secret, options): mimetypes.types_map[splitext(path)[1]]) path = options.get('--file') - url = secret.get('peertube', 'peertube_url') + url = str(secret.get('peertube', 'peertube_url')).rstrip('/') user_info = get_userinfo() # We need to transform fields into tuple to deal with tags as @@ -128,7 +129,7 @@ def upload_video(oauth, secret, options): exit(1) # If Mastodon compatibility is enabled, clean tags from special characters if options.get('--mt'): - strtag = utils.mastodonTag(strtag) + strtag = utils.cleanString(strtag) fields.append(("tags", strtag)) if options.get('--category'): diff --git a/lib/utils.py b/lib/utils.py index bfabaad..4234116 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -193,15 +193,15 @@ def parseNFO(options): def upcaseFirstLetter(s): return s[0].upper() + s[1:] -def mastodonTag(tag): - tags = tag.split(' ') - mtag = '' - for s in tags: +def cleanString(toclean): + toclean = toclean.split(' ') + cleaned = '' + for s in toclean: 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 + strtoclean = unicodedata.normalize('NFKD', unicode (s, 'utf-8')).encode('ASCII', 'ignore') + strtoclean = ''.join(e for e in strtoclean if e.isalnum()) + strtoclean = upcaseFirstLetter(strtoclean) + cleaned = cleaned + strtoclean - return mtag + return cleaned