From 6a07bbbf4bb93952647b6043f4ba6afde7209155 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Sat, 4 Aug 2018 13:50:39 +0200 Subject: [PATCH 1/3] Update peeror repo with new url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fd7ec79..8d864ba 100644 --- a/README.md +++ b/README.md @@ -160,4 +160,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.drycat.fr/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) \ No newline at end of file From 68959cc1a8887d661618c1e0f78dba55eb438593 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Sat, 4 Aug 2018 14:07:02 +0200 Subject: [PATCH 2/3] Add support for playlist on Peertube --- lib/pt_upload.py | 52 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/lib/pt_upload.py b/lib/pt_upload.py index e30d1f4..8195336 100644 --- a/lib/pt_upload.py +++ b/lib/pt_upload.py @@ -41,11 +41,46 @@ def get_authenticated_service(secret): return oauth +def get_playlist_by_name(user_info, options): + + for playlist in user_info["videoChannels"]: + if playlist['displayName'] == options.get('--playlist'): + return playlist['id'] + + +def create_playlist(oauth, url, options): + template = ('Peertube : Playlist %s does not exist, creating it.') + logging.info(template % (str(options.get('--playlist')))) + data = '{"displayName":"' + str(options.get('--playlist')) +'", \ + "description":null}' + + headers = { + 'Content-Type': "application/json" + } + try: + response = oauth.post(url + "/api/v1/video-channels/", + data=data, + headers=headers) + except Exception as e: + if hasattr(e, 'message'): + logging.error("Error: " + str(e.message)) + else: + logging.error("Error: " + str(e)) + if response is not None: + if response.status_code == 200: + jresponse = response.json() + jresponse = jresponse['videoChannel'] + return jresponse['id'] + else: + logging.error(('Peertube : The upload failed with an unexpected response: ' + '%s') % response) + exit(1) + + def upload_video(oauth, secret, options): def get_userinfo(): - user_info = json.loads(oauth.get(url + "/api/v1/users/me").content) - return str(user_info["id"]) + return json.loads(oauth.get(url+"/api/v1/users/me").content) def get_videofile(path): mimetypes.init() @@ -54,6 +89,7 @@ def upload_video(oauth, secret, options): path = options.get('--file') url = secret.get('peertube', 'peertube_url') + user_info = get_userinfo() # We need to transform fields into tuple to deal with tags as # MultipartEncoder does not support list refer @@ -64,7 +100,6 @@ def upload_video(oauth, secret, options): ("licence", "1"), ("description", options.get('--description') or "default description"), ("nsfw", str(int(options.get('--nsfw')) or "0")), - ("channelId", get_userinfo()), ("videofile", get_videofile(path)) ] @@ -105,12 +140,21 @@ def upload_video(oauth, secret, options): else: fields.append(("commentsEnabled", "1")) + if options.get('--playlist'): + playlist_id = get_playlist_by_name(user_info, options) + if not playlist_id and options.get('--playlistCreate'): + playlist_id = create_playlist(oauth, url, options) + else: + playlist_id = user_info['id'] + else: + playlist_id = user_info['id'] + fields.append(("channelId", str(playlist_id))) + multipart_data = MultipartEncoder(fields) headers = { 'Content-Type': multipart_data.content_type } - response = oauth.post(url + "/api/v1/videos/upload", data=multipart_data, headers=headers) From bd2631699a42fa1300826894430a589a479be86f Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Sat, 4 Aug 2018 14:07:37 +0200 Subject: [PATCH 3/3] Add option to manage playlist for videos --- prismedia_upload.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/prismedia_upload.py b/prismedia_upload.py index 7261cbf..297da76 100755 --- a/prismedia_upload.py +++ b/prismedia_upload.py @@ -34,6 +34,10 @@ Options: DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00 DATE should be in the future For Peertube, requires the "atd" and "curl utilities installed on the system + --playlist=STRING Set the playlist to use for the video. Also known as Channel for Peertube. + If the playlist is not found, spawn an error except if --playlist-create is set. + --playlistCreate Create the playlist if not exists. (default do not create) + Only relevant if --playlist is set. -h --help Show this help. --version Show version. @@ -86,7 +90,7 @@ except ImportError: 'see https://github.com/ahupp/python-magic\n') exit(1) -VERSION = "prismedia v0.4" +VERSION = "prismedia v0.5" VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted') VALID_CATEGORIES = ( @@ -199,6 +203,8 @@ if __name__ == '__main__': Optional('--cca'): bool, Optional('--disable-comments'): bool, Optional('--nsfw'): bool, + Optional('--playlist'): Or(None, str), + Optional('--playlistCreate'): bool, '--help': bool, '--version': bool })