diff --git a/CHANGELOG.md b/CHANGELOG.md index 460be62..14e913b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,17 @@ # Changelog +## v0.10.2 + +### Fixes + - 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) + ## 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 diff --git a/prismedia/pt_upload.py b/prismedia/pt_upload.py index b95e550..0268506 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 @@ -201,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)) @@ -267,7 +282,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: @@ -293,7 +308,7 @@ def upload_video(oauth, secret, options): jresponse = jresponse['video'] uuid = jresponse['uuid'] video_id = str(jresponse['id']) - logger.info('Peertube : Video was successfully uploaded.') + 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' 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 = ( 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 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.')