From c5aeacb936e1e7d2113b62c9ccfe40ffc9c34860 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Sat, 4 Aug 2018 13:50:39 +0200 Subject: [PATCH 1/6] 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 2197a95..f612c76 100644 --- a/README.md +++ b/README.md @@ -169,4 +169,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 bd8aa9c4850cbc5597dc397117ce059371ee087e Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Sat, 4 Aug 2018 14:07:02 +0200 Subject: [PATCH 2/6] Add support for playlist on Peertube --- lib/pt_upload.py | 57 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/lib/pt_upload.py b/lib/pt_upload.py index fa3225d..afbb8ff 100644 --- a/lib/pt_upload.py +++ b/lib/pt_upload.py @@ -48,18 +48,55 @@ 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_file(path): mimetypes.init() return (basename(path), open(abspath(path), 'rb'), mimetypes.types_map[splitext(path)[1]]) - url = str(secret.get('peertube', 'peertube_url')).rstrip('/') + 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 @@ -70,8 +107,7 @@ 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_file(options.get('--file'))) + ("videofile", get_videofile(path)) ] if options.get('--tags'): @@ -115,12 +151,21 @@ def upload_video(oauth, secret, options): fields.append(("thumbnailfile", get_file(options.get('--thumbnail')))) fields.append(("previewfile", get_file(options.get('--thumbnail')))) + 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 9118f7b082c6825cca50c974dd7b3cb8d095b9d1 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Sat, 4 Aug 2018 14:07:37 +0200 Subject: [PATCH 3/6] Add option to manage playlist for videos --- prismedia_upload.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/prismedia_upload.py b/prismedia_upload.py index 27d8b8d..04473d8 100755 --- a/prismedia_upload.py +++ b/prismedia_upload.py @@ -37,6 +37,10 @@ Options: --thumbnail=STRING Path to a file to use as a thumbnail for the video. Supported types are jpg and jpeg. By default, prismedia search for an image based on video name followed by .jpg or .jpeg + --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. @@ -211,6 +215,8 @@ if __name__ == '__main__': Optional('--thumbnail'): Or(None, And( str, validateThumbnail, error='thumbnail is not supported, please use jpg/jpeg'), ), + Optional('--playlist'): Or(None, str), + Optional('--playlistCreate'): bool, '--help': bool, '--version': bool }) From 461beaa5cb3516c1d1c0df55a5213f10aedee257 Mon Sep 17 00:00:00 2001 From: Zykino Date: Wed, 12 Sep 2018 00:45:18 +0200 Subject: [PATCH 4/6] peertube: fix default playlist --- lib/pt_upload.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/pt_upload.py b/lib/pt_upload.py index afbb8ff..2cc1083 100644 --- a/lib/pt_upload.py +++ b/lib/pt_upload.py @@ -48,8 +48,11 @@ def get_authenticated_service(secret): return oauth -def get_playlist_by_name(user_info, options): +def get_default_playlist(user_info): + return user_info['videoChannels'][0]['id'] + +def get_playlist_by_name(user_info, options): for playlist in user_info["videoChannels"]: if playlist['displayName'] == options.get('--playlist'): return playlist['id'] @@ -155,10 +158,11 @@ def upload_video(oauth, secret, options): 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'] + elif not playlist_id: + logging.warning("Playlist `" + options.get('--playlist') + "` is unknown, using default playlist.") + playlist_id = get_default_playlist(user_info) else: - playlist_id = user_info['id'] + playlist_id = get_default_playlist(user_info) fields.append(("channelId", str(playlist_id))) multipart_data = MultipartEncoder(fields) From 95f6bc930f3be85ec57741ed30337dc439535a46 Mon Sep 17 00:00:00 2001 From: Zykino Date: Mon, 1 Oct 2018 21:24:34 +0200 Subject: [PATCH 5/6] fix merge: function name changed --- lib/pt_upload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pt_upload.py b/lib/pt_upload.py index 2cc1083..4dd6143 100644 --- a/lib/pt_upload.py +++ b/lib/pt_upload.py @@ -110,7 +110,7 @@ def upload_video(oauth, secret, options): ("licence", "1"), ("description", options.get('--description') or "default description"), ("nsfw", str(int(options.get('--nsfw')) or "0")), - ("videofile", get_videofile(path)) + ("videofile", get_file(path)) ] if options.get('--tags'): From 2d7b8e0b095cf02fb332c79e8b2ec8536f2ec7a4 Mon Sep 17 00:00:00 2001 From: Zykino Date: Tue, 2 Oct 2018 12:11:26 +0200 Subject: [PATCH 6/6] Update README to show the current state of the playlist integration --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f612c76..9e5ee38 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,8 @@ Languages: - [x] thumbnail/preview - [x] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4)) - [ ] add videos to playlist (YT & PT workflow: upload video, find playlist id, add video to playlist) + - [x] Peertube + - [ ] Youtube - [x] Use a config file (NFO) file to retrieve videos arguments - [x] Allow to choose peertube or youtube upload (to resume failed upload for example) - [x] Add publishAt option to plan your videos (need the [atd](https://linux.die.net/man/8/atd) daemon, [curl](https://linux.die.net/man/1/curl) and [jq](https://stedolan.github.io/jq/))