diff --git a/README.md b/README.md index 536e511..1bebfc0 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Options: - [x] Youtube upload - [x] Peertube upload - [ ] Support of all videos arguments (description, tags, category, licence, ...) -- [ ] Use file to retrieve videos arguments +- [ ] Use a config file (NFO) file to retrieve videos arguments - [ ] Record and forget: put the video in a directory, and the script uploads it for you - [ ] Usable on Desktop (Linux and/or Windows and/or MacOS) - [ ] Graphical User Interface diff --git a/lib/pt_upload.py b/lib/pt_upload.py index d262a08..d22afed 100644 --- a/lib/pt_upload.py +++ b/lib/pt_upload.py @@ -6,6 +6,7 @@ import mimetypes import httplib import httplib2 import json +import array from ConfigParser import RawConfigParser from requests_oauthlib import OAuth2Session @@ -37,19 +38,31 @@ def upload_video(oauth, config, options): path = options.get('--file') url = config.get('peertube', 'peertube_url') - fields = { - "name": options.get('--name') or os.path.splitext(os.path.basename(path))[0], - "category": str(options.get('--category') or 1), # look at the list numbers at /videos/categories - "licence": str(options.get('--licence') or 1), # look at the list numbers at /videos/licences - "description": options.get('--description') or "", - "privacy": str(options.get('--privacy') or 3), # look at the list numbers at /videos/privacies - "nsfw": str(options.get('--nsfw') or 0), - "commentsEnabled": "1", - "channelId": get_userinfo(), - "videofile": get_videofile(path) # beware, see validateVideo for supported types - } + tags = None + tags_tuple=[] + + # We need to transform fields into tuple to deal with tags as MultipartEncoder does not support list + # refer https://github.com/requests/toolbelt/issues/190 and https://github.com/requests/toolbelt/issues/205 + fields = [ + ("name", options.get('--name') or os.path.splitext(os.path.basename(path))[0]), + ("category", str(options.get('--category') or 1)), # look at the list numbers at /videos/categories + ("licence", str(options.get('--licence') or 1)), # look at the list numbers at /videos/licences + ("description", options.get('--description') or "default description"), + ("privacy", str(options.get('--privacy') or 3)), # look at the list numbers at /videos/privacies + ("nsfw", str(options.get('--nsfw') or 0)), + ("commentsEnabled", "1"), + ("channelId", get_userinfo()), + ("videofile", get_videofile(path)) # beware, see validateVideo for supported types + ] + + if options.get('--tags'): + tags = options.get('--tags').split(',') + for strtags in tags: + fields.append(("tags", strtags)) + + # multipart_data = MultipartEncoder(fields=fields) + multipart_data = MultipartEncoder(fields) - multipart_data = MultipartEncoder(fields=fields) headers = { 'Content-Type': multipart_data.content_type }