diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5586b2e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Prismedia v0.5 + +## Features + - plan your Peertube videos! Stable release + - Support for Peertube beta4 + - More examples in NFO + - Better support for multilines descriptions + +## Fix + - Display datetime for output + - plan video only if upload is successful \ No newline at end of file diff --git a/README.md b/README.md index a4aa283..fd7ec79 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Search in your package manager, otherwise use ``pip install --upgrade`` For Peertube and if you want to use the publishAt option, you also need some utilities on you local system - [atd](https://linux.die.net/man/8/atd) daemon - [curl](https://linux.die.net/man/1/curl) + - [jq](https://stedolan.github.io/jq/) ## Configuration @@ -110,7 +111,7 @@ Options: --publishAt=DATE Publish the video at the given DATE using local server timezone. DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00 DATE should be in the future - For Peertube, requires the "atd" and "curl utilities installed on the system + For Peertube, requires the "atd", "curl" and "jq" utilities installed on the system -h --help Show this help. --version Show version. @@ -144,10 +145,12 @@ Languages: - [x] enabling/disabling comment (Peertube only as Youtube API does not support it) - [x] nsfw (Peertube only as Youtube API does not support it) - [x] set default language - - ~~thumbnail/preview~~ Canceled, waiting for Youtube's API support + - [ ] thumbnail/preview (YT workflow: upload video, upload thumbnail, add thumbnail to video) + - [ ] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4)) + - [ ] add videos to playlist (YT & PT workflow: upload video, find playlist id, add video to playlist) - [x] Use a config file (NFO) file to retrieve videos arguments - [x] Allow to choose peertube or youtube upload (to resume failed upload for example) -- [x] Add publishAt option to plan your videos (need the [atd](https://linux.die.net/man/8/atd) daemon and [curl](https://linux.die.net/man/1/curl)) +- [x] Add publishAt option to plan your videos (need the [atd](https://linux.die.net/man/8/atd) daemon, [curl](https://linux.die.net/man/1/curl) and [jq](https://stedolan.github.io/jq/)) - [ ] 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 ba55821..e30d1f4 100644 --- a/lib/pt_upload.py +++ b/lib/pt_upload.py @@ -123,14 +123,13 @@ def upload_video(oauth, secret, options): template = ('Peertube : Video was successfully uploaded.\n' 'Watch it at %s/videos/watch/%s.') logging.info(template % (url, uuid)) + if options.get('--publishAt'): + utils.publishAt(str(options.get('--publishAt')), oauth, url, idvideo, secret) else: logging.error(('Peertube : The upload failed with an unexpected response: ' '%s') % response) exit(1) - if options.get('--publishAt'): - utils.publishAt(str(options.get('--publishAt')), oauth, url, idvideo) - def run(options): secret = RawConfigParser() diff --git a/lib/utils.py b/lib/utils.py index ca8b4d0..bd7b9d8 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -169,7 +169,7 @@ def upcaseFirstLetter(s): return s[0].upper() + s[1:] -def publishAt(publishAt, oauth, url, idvideo): +def publishAt(publishAt, oauth, url, idvideo, secret): try: FNULL = open(devnull, 'w') check_call(["at", "-V"], stdout=FNULL, stderr=STDOUT) @@ -182,19 +182,32 @@ def publishAt(publishAt, oauth, url, idvideo): except CalledProcessError: logging.error("You need to install the curl command line to use the publishAt option.") exit(1) + try: + FNULL = open(devnull, 'w') + check_call(["jq", "-V"], stdout=FNULL, stderr=STDOUT) + except CalledProcessError: + logging.error("You need to install the jq command line to use the publishAt option.") + exit(1) time = publishAt.split("T") # Remove leading seconds that atd does not manage if time[1].count(":") == 2: time[1] = time[1][:-3] atTime = time[1] + " " + time[0] - token=str(oauth.__dict__['_client'].__dict__['access_token']) + refresh_token=str(oauth.__dict__['_client'].__dict__['refresh_token']) atFile = "/tmp/peertube_" + idvideo + "_" + publishAt + ".at" try: - file = open(atFile,"w") - file.write("curl '" + url + "/api/v1/videos/" + idvideo + "' -X PUT -H 'Authorization: Bearer " + token + "' -H 'Content-Type: multipart/form-data' -F 'privacy=1'") - file.write(" ") # atd needs an empty line at the end of the file to load... - file.close() + openfile = open(atFile,"w") + openfile.write('token=$(curl -X POST -d "client_id=' + str(secret.get('peertube', 'client_id')) + + '&client_secret=' + str(secret.get('peertube', 'client_secret')) + + '&grant_type=refresh_token&refresh_token=' + str(refresh_token) + + '" "' + url + '/api/v1/users/token" | jq -r .access_token)') + openfile.write("\n") + openfile.write('curl "' + url + '/api/v1/videos/' + idvideo + + '" -X PUT -H "Authorization: Bearer ${token}"' + + ' -H "Content-Type: multipart/form-data" -F "privacy=1"') + openfile.write("\n ") # atd needs an empty line at the end of the file to load... + openfile.close() except Exception as e: if hasattr(e, 'message'): logging.error("Error: " + str(e.message)) diff --git a/nfo_example.txt b/nfo_example.txt index 065601d..da06373 100644 --- a/nfo_example.txt +++ b/nfo_example.txt @@ -8,6 +8,9 @@ [video] name = videoname description = Your complete video description + Multilines description + should be wrote with a blank space + at the beginning of the line :) tags = list of tags, comma separated mt = True category = Films diff --git a/prismedia_upload.py b/prismedia_upload.py index 7261cbf..53fa833 100755 --- a/prismedia_upload.py +++ b/prismedia_upload.py @@ -86,7 +86,7 @@ except ImportError: 'see https://github.com/ahupp/python-magic\n') exit(1) -VERSION = "prismedia v0.4" +VERSION = "prismedia v0.5" VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted') VALID_CATEGORIES = (