This commit is contained in:
LecygneNoir 2018-03-08 13:53:37 +01:00
parent 67643ead20
commit fbde389349
2 changed files with 26 additions and 13 deletions

View file

@ -40,7 +40,7 @@ Options:
- [x] Youtube upload - [x] Youtube upload
- [x] Peertube upload - [x] Peertube upload
- [ ] Support of all videos arguments (description, tags, category, licence, ...) - [ ] 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 - [ ] 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) - [ ] Usable on Desktop (Linux and/or Windows and/or MacOS)
- [ ] Graphical User Interface - [ ] Graphical User Interface

View file

@ -6,6 +6,7 @@ import mimetypes
import httplib import httplib
import httplib2 import httplib2
import json import json
import array
from ConfigParser import RawConfigParser from ConfigParser import RawConfigParser
from requests_oauthlib import OAuth2Session from requests_oauthlib import OAuth2Session
@ -37,19 +38,31 @@ def upload_video(oauth, config, options):
path = options.get('--file') path = options.get('--file')
url = config.get('peertube', 'peertube_url') url = config.get('peertube', 'peertube_url')
fields = { tags = None
"name": options.get('--name') or os.path.splitext(os.path.basename(path))[0], tags_tuple=[]
"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 # We need to transform fields into tuple to deal with tags as MultipartEncoder does not support list
"description": options.get('--description') or "", # refer https://github.com/requests/toolbelt/issues/190 and https://github.com/requests/toolbelt/issues/205
"privacy": str(options.get('--privacy') or 3), # look at the list numbers at /videos/privacies fields = [
"nsfw": str(options.get('--nsfw') or 0), ("name", options.get('--name') or os.path.splitext(os.path.basename(path))[0]),
"commentsEnabled": "1", ("category", str(options.get('--category') or 1)), # look at the list numbers at /videos/categories
"channelId": get_userinfo(), ("licence", str(options.get('--licence') or 1)), # look at the list numbers at /videos/licences
"videofile": get_videofile(path) # beware, see validateVideo for supported types ("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 = { headers = {
'Content-Type': multipart_data.content_type 'Content-Type': multipart_data.content_type
} }