Browse Source

support tags for peertube, refer https://github.com/requests/toolbelt/issues/190

develop
LecygneNoir 6 years ago
parent
commit
fbde389349
2 changed files with 26 additions and 13 deletions
  1. +1
    -1
      README.md
  2. +25
    -12
      lib/pt_upload.py

+ 1
- 1
README.md View File

@ -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

+ 25
- 12
lib/pt_upload.py View File

@ -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
}

Loading…
Cancel
Save