|
@ -108,10 +108,21 @@ def get_default_playlist(user_info): |
|
|
return user_info['videoChannels'][0]['id'] |
|
|
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): |
|
|
def create_playlist(oauth, url, options, channel): |
|
@ -179,13 +190,10 @@ def upload_video(oauth, secret, options): |
|
|
return (basename(path), open(abspath(path), 'rb'), |
|
|
return (basename(path), open(abspath(path), 'rb'), |
|
|
mimetypes.types_map[splitext(path)[1]]) |
|
|
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') |
|
|
path = options.get('--file') |
|
|
url = str(secret.get('peertube', 'peertube_url')).rstrip('/') |
|
|
url = str(secret.get('peertube', 'peertube_url')).rstrip('/') |
|
|
user_info = get_userinfo() |
|
|
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 |
|
|
# We need to transform fields into tuple to deal with tags as |
|
|
# MultipartEncoder does not support list refer |
|
|
# MultipartEncoder does not support list refer |
|
@ -201,14 +209,21 @@ def upload_video(oauth, secret, options): |
|
|
|
|
|
|
|
|
if options.get('--tags'): |
|
|
if options.get('--tags'): |
|
|
tags = options.get('--tags').split(',') |
|
|
tags = options.get('--tags').split(',') |
|
|
|
|
|
tag_number = 0 |
|
|
for strtag in tags: |
|
|
for strtag in tags: |
|
|
|
|
|
tag_number = tag_number + 1 |
|
|
# Empty tag crashes Peertube, so skip them |
|
|
# Empty tag crashes Peertube, so skip them |
|
|
if strtag == "": |
|
|
if strtag == "": |
|
|
continue |
|
|
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: |
|
|
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 |
|
|
continue |
|
|
fields.append(("tags[]", strtag)) |
|
|
fields.append(("tags[]", strtag)) |
|
|
|
|
|
|
|
@ -267,7 +282,7 @@ def upload_video(oauth, secret, options): |
|
|
fields.append(("channelId", str(channel_id))) |
|
|
fields.append(("channelId", str(channel_id))) |
|
|
|
|
|
|
|
|
if options.get('--playlist'): |
|
|
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'): |
|
|
if not playlist_id and options.get('--playlistCreate'): |
|
|
playlist_id = create_playlist(oauth, url, options, channel_id) |
|
|
playlist_id = create_playlist(oauth, url, options, channel_id) |
|
|
elif not playlist_id: |
|
|
elif not playlist_id: |
|
@ -293,7 +308,7 @@ def upload_video(oauth, secret, options): |
|
|
jresponse = jresponse['video'] |
|
|
jresponse = jresponse['video'] |
|
|
uuid = jresponse['uuid'] |
|
|
uuid = jresponse['uuid'] |
|
|
video_id = str(jresponse['id']) |
|
|
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.' |
|
|
template = 'Peertube: Watch it at %s/videos/watch/%s.' |
|
|
logger.info(template % (url, uuid)) |
|
|
logger.info(template % (url, uuid)) |
|
|
template_stdout = '%s/videos/watch/%s' |
|
|
template_stdout = '%s/videos/watch/%s' |
|
|