From c2db59738825d2c29c26e19cfb34a02bee9ad2ed Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Wed, 11 Nov 2020 09:52:16 +0100 Subject: [PATCH 1/7] Fix message about thumbnail where it missed a space, close #49 --- prismedia/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prismedia/utils.py b/prismedia/utils.py index c2239c6..d7f85ad 100644 --- a/prismedia/utils.py +++ b/prismedia/utils.py @@ -130,7 +130,7 @@ def searchThumbnail(options): if not options.get('--thumbnail'): logger.debug("No thumbnail has been found, continuing") else: - logger.info("Using " + options.get('--thumbnail') + "as thumbnail") + logger.info("Using " + options.get('--thumbnail') + " as thumbnail") return options From cbb7c745de2d2f746a5974c6615ae8d6bdb96009 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Wed, 11 Nov 2020 10:27:19 +0100 Subject: [PATCH 2/7] Add pagination to find Peertube existing playlists as default pagination shows 14 playlists max. See #41 --- prismedia/pt_upload.py | 74 +++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/prismedia/pt_upload.py b/prismedia/pt_upload.py index b95e550..8a8c381 100644 --- a/prismedia/pt_upload.py +++ b/prismedia/pt_upload.py @@ -108,10 +108,21 @@ def get_default_playlist(user_info): return user_info['videoChannels'][0]['id'] -def get_playlist_by_name(user_playlists, options): - for playlist in user_playlists["data"]: - if playlist['displayName'] == options.get('--playlist'): - return playlist['id'] +def get_playlist_by_name(oauth, url, username, options): + start = 1 + user_playlists = json.loads(oauth.get( + url+"/api/v1/accounts/"+username+"/video-playlists?start="+str(start)+"&count=100").content) + total = user_playlists["total"] + data = user_playlists["data"] + # We need to iterate on pagination as peertube returns max 100 playlists (see #41) + while start < total: + for playlist in data: + if playlist['displayName'] == options.get('--playlist'): + return playlist['id'] + start = start + 100 + user_playlists = json.loads(oauth.get( + url+"/api/v1/accounts/"+username+"/video-playlists?start="+str(start)+"&count=100").content) + data = user_playlists["data"] def create_playlist(oauth, url, options, channel): @@ -179,13 +190,10 @@ def upload_video(oauth, secret, options): return (basename(path), open(abspath(path), 'rb'), mimetypes.types_map[splitext(path)[1]]) - def get_playlist(username): - return json.loads(oauth.get(url+"/api/v1/accounts/"+username+"/video-playlists").content) - path = options.get('--file') url = str(secret.get('peertube', 'peertube_url')).rstrip('/') user_info = get_userinfo() - user_playlists = get_playlist(str(secret.get('peertube', 'username').lower())) + username = str(secret.get('peertube', 'username').lower()) # We need to transform fields into tuple to deal with tags as # MultipartEncoder does not support list refer @@ -267,7 +275,7 @@ def upload_video(oauth, secret, options): fields.append(("channelId", str(channel_id))) if options.get('--playlist'): - playlist_id = get_playlist_by_name(user_playlists, options) + playlist_id = get_playlist_by_name(oauth, url, username, options) if not playlist_id and options.get('--playlistCreate'): playlist_id = create_playlist(oauth, url, options, channel_id) elif not playlist_id: @@ -284,30 +292,30 @@ def upload_video(oauth, secret, options): headers = { 'Content-Type': multipart_data.content_type } - response = oauth.post(url + "/api/v1/videos/upload", - data=multipart_data, - headers=headers) - if response is not None: - if response.status_code == 200: - jresponse = response.json() - jresponse = jresponse['video'] - uuid = jresponse['uuid'] - video_id = str(jresponse['id']) - logger.info('Peertube : Video was successfully uploaded.') - template = 'Peertube: Watch it at %s/videos/watch/%s.' - logger.info(template % (url, uuid)) - template_stdout = '%s/videos/watch/%s' - if options.get('--url-only'): - logger_stdout.info(template_stdout % (url, uuid)) - elif options.get('--batch'): - logger_stdout.info("Peertube: " + template_stdout % (url, uuid)) - # Upload is successful we may set playlist - if options.get('--playlist'): - set_playlist(oauth, url, video_id, playlist_id) - else: - logger.critical(('Peertube: The upload failed with an unexpected response: ' - '%s') % response) - exit(1) + # response = oauth.post(url + "/api/v1/videos/upload", + # data=multipart_data, + # headers=headers) + # if response is not None: + # if response.status_code == 200: + # jresponse = response.json() + # jresponse = jresponse['video'] + # uuid = jresponse['uuid'] + # video_id = str(jresponse['id']) + # logger.info('Peertube: Video was successfully uploaded.') + # template = 'Peertube: Watch it at %s/videos/watch/%s.' + # logger.info(template % (url, uuid)) + # template_stdout = '%s/videos/watch/%s' + # if options.get('--url-only'): + # logger_stdout.info(template_stdout % (url, uuid)) + # elif options.get('--batch'): + # logger_stdout.info("Peertube: " + template_stdout % (url, uuid)) + # # Upload is successful we may set playlist + # if options.get('--playlist'): + # set_playlist(oauth, url, video_id, playlist_id) + # else: + # logger.critical(('Peertube: The upload failed with an unexpected response: ' + # '%s') % response) + # exit(1) def run(options): From 0aae4da68fbff3f836761ab4aafb5be0309ac696 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Wed, 11 Nov 2020 10:29:09 +0100 Subject: [PATCH 3/7] Add changelog for #41 and #47 --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 460be62..d8113b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ # Changelog +## v0.10.2 + +### Fixes + - Fix a typo in log (missing space when displaying thumbnail) (see #47) + - Add pagination when searching playlist in Peertube as default pagination show only 14 playlists (see #41) + ## v0.10.1 ### Fix - - fix a bug introduced with v0.10.0 that broke thumbnail on youtube upload. + - Fix a bug introduced with v0.10.0 that broke thumbnail on youtube upload. ## v0.10.0 From 5160e9e68d873792ff309cfafaa334c186cca254 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Wed, 11 Nov 2020 10:39:11 +0100 Subject: [PATCH 4/7] Add a check to avoid uploading on Peertube with more than 5 tags (see #48) --- CHANGELOG.md | 1 + prismedia/pt_upload.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8113b1..284b16a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixes - Fix a typo in log (missing space when displaying thumbnail) (see #47) - Add pagination when searching playlist in Peertube as default pagination show only 14 playlists (see #41) + - Add a check to avoid uploading video on Peertube with more than 5 tags (see #48) ## v0.10.1 diff --git a/prismedia/pt_upload.py b/prismedia/pt_upload.py index 8a8c381..3bae1b7 100644 --- a/prismedia/pt_upload.py +++ b/prismedia/pt_upload.py @@ -209,14 +209,21 @@ def upload_video(oauth, secret, options): if options.get('--tags'): tags = options.get('--tags').split(',') + tag_number = 0 for strtag in tags: + tag_number = tag_number + 1 # Empty tag crashes Peertube, so skip them if strtag == "": continue - # Tag more than 30 chars crashes Peertube, so exit and check tags + # Tag more than 30 chars crashes Peertube, so skip tags if len(strtag) >= 30: - logger.error("Peertube: Sorry, Peertube does not support tag with more than 30 characters, please reduce tag: " + strtag) - logger.error("Peertube: Meanwhile, this tag will be skipped") + logger.warning("Peertube: Sorry, Peertube does not support tag with more than 30 characters, please reduce tag: " + strtag) + logger.warning("Peertube: Meanwhile, this tag will be skipped") + continue + # Peertube supports only 5 tags at the moment + if tag_number > 5: + logger.warning("Peertube: Sorry, Peertube support 5 tags max, additional tag will be skipped") + logger.warning("Peertube: Skipping tag " + strtag) continue fields.append(("tags[]", strtag)) From 26476347d389040d597df3ded5e947dcf818f95e Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Wed, 11 Nov 2020 10:40:05 +0100 Subject: [PATCH 5/7] =?UTF-8?q?Renable=20Peertube=20upload=20after=20tests?= =?UTF-8?q?=20=F0=9F=98=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prismedia/pt_upload.py | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/prismedia/pt_upload.py b/prismedia/pt_upload.py index 3bae1b7..0268506 100644 --- a/prismedia/pt_upload.py +++ b/prismedia/pt_upload.py @@ -299,30 +299,30 @@ def upload_video(oauth, secret, options): headers = { 'Content-Type': multipart_data.content_type } - # response = oauth.post(url + "/api/v1/videos/upload", - # data=multipart_data, - # headers=headers) - # if response is not None: - # if response.status_code == 200: - # jresponse = response.json() - # jresponse = jresponse['video'] - # uuid = jresponse['uuid'] - # video_id = str(jresponse['id']) - # logger.info('Peertube: Video was successfully uploaded.') - # template = 'Peertube: Watch it at %s/videos/watch/%s.' - # logger.info(template % (url, uuid)) - # template_stdout = '%s/videos/watch/%s' - # if options.get('--url-only'): - # logger_stdout.info(template_stdout % (url, uuid)) - # elif options.get('--batch'): - # logger_stdout.info("Peertube: " + template_stdout % (url, uuid)) - # # Upload is successful we may set playlist - # if options.get('--playlist'): - # set_playlist(oauth, url, video_id, playlist_id) - # else: - # logger.critical(('Peertube: The upload failed with an unexpected response: ' - # '%s') % response) - # exit(1) + response = oauth.post(url + "/api/v1/videos/upload", + data=multipart_data, + headers=headers) + if response is not None: + if response.status_code == 200: + jresponse = response.json() + jresponse = jresponse['video'] + uuid = jresponse['uuid'] + video_id = str(jresponse['id']) + logger.info('Peertube: Video was successfully uploaded.') + template = 'Peertube: Watch it at %s/videos/watch/%s.' + logger.info(template % (url, uuid)) + template_stdout = '%s/videos/watch/%s' + if options.get('--url-only'): + logger_stdout.info(template_stdout % (url, uuid)) + elif options.get('--batch'): + logger_stdout.info("Peertube: " + template_stdout % (url, uuid)) + # Upload is successful we may set playlist + if options.get('--playlist'): + set_playlist(oauth, url, video_id, playlist_id) + else: + logger.critical(('Peertube: The upload failed with an unexpected response: ' + '%s') % response) + exit(1) def run(options): From dab44244f36e8a93e0edb23684d3fb1de8b6aeb0 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Wed, 11 Nov 2020 10:43:36 +0100 Subject: [PATCH 6/7] Revert the workaround for Youtube playlist bug now the bug is fixed by Youtube (see #47) --- CHANGELOG.md | 1 + prismedia/yt_upload.py | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 284b16a..a63f1bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fix a typo in log (missing space when displaying thumbnail) (see #47) - Add pagination when searching playlist in Peertube as default pagination show only 14 playlists (see #41) - Add a check to avoid uploading video on Peertube with more than 5 tags (see #48) + - Revert the workaround for Youtube playlist bug now the bug is fixed by Youtube (see #47) ## v0.10.1 diff --git a/prismedia/yt_upload.py b/prismedia/yt_upload.py index 524ef56..3cfd900 100644 --- a/prismedia/yt_upload.py +++ b/prismedia/yt_upload.py @@ -253,14 +253,12 @@ def set_playlist(youtube, playlist_id, video_id): part='snippet' ).execute() except Exception as e: - # Workaround while youtube API is broken, see issue #47 for details - if e.resp.status != 404 and "Video not found" not in str(e): - if hasattr(e, 'message'): - logger.critical("Youtube: " + str(e.message)) - exit(1) - else: - logger.critical("Youtube: " + str(e)) - exit(1) + if hasattr(e, 'message'): + logger.critical("Youtube: " + str(e.message)) + exit(1) + else: + logger.critical("Youtube: " + str(e)) + exit(1) logger.info('Youtube: Video is correctly added to the playlist.') From 25435453bd11c4f0ccee8a4e668170a94db7f1fe Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Wed, 11 Nov 2020 10:45:02 +0100 Subject: [PATCH 7/7] Bump to version v0.10.2 and fix typo in ticket number inside Changelog for v0.10.2 --- CHANGELOG.md | 2 +- prismedia/upload.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a63f1bb..14e913b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## v0.10.2 ### Fixes - - Fix a typo in log (missing space when displaying thumbnail) (see #47) + - Fix a typo in log (missing space when displaying thumbnail) (see #49) - Add pagination when searching playlist in Peertube as default pagination show only 14 playlists (see #41) - Add a check to avoid uploading video on Peertube with more than 5 tags (see #48) - Revert the workaround for Youtube playlist bug now the bug is fixed by Youtube (see #47) diff --git a/prismedia/upload.py b/prismedia/upload.py index 3d6d6db..0f49cb4 100755 --- a/prismedia/upload.py +++ b/prismedia/upload.py @@ -130,7 +130,7 @@ except ImportError: 'see https://github.com/ahupp/python-magic\n') exit(1) -VERSION = "prismedia v0.10.1" +VERSION = "prismedia v0.10.2" VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted') VALID_CATEGORIES = (