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 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):