From 28f964bf2e2a319f9cd1d0d27c5a8c3cf90bb4be Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Tue, 8 May 2018 14:42:32 +0200 Subject: [PATCH 1/6] plan video only if video has been uploaded with success --- lib/pt_upload.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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() From 4ec8960451ed2088a19e6c611cf9767ae7892186 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Tue, 8 May 2018 14:43:23 +0200 Subject: [PATCH 2/6] use refresh_token instead of access_token to plan video in cron, to be able to generate a new token even if token has expired --- lib/utils.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/utils.py b/lib/utils.py index ca8b4d0..1f2ab14 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) @@ -188,13 +188,20 @@ def publishAt(publishAt, oauth, url, idvideo): 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)) From c1e6e032c98f4f67a10696f572e46828b5d6ebaa Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Tue, 8 May 2018 14:54:25 +0200 Subject: [PATCH 3/6] add checks for the jq command and update README --- README.md | 5 +++-- lib/utils.py | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a4aa283..ecfc62d 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. @@ -147,7 +148,7 @@ Languages: - ~~thumbnail/preview~~ Canceled, waiting for Youtube's API support - [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/utils.py b/lib/utils.py index 1f2ab14..bd7b9d8 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -182,6 +182,12 @@ def publishAt(publishAt, oauth, url, idvideo, secret): 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: From 7dd84e1f8d39e513f1c9b5b20ce364d55aa895c8 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Tue, 8 May 2018 15:29:36 +0200 Subject: [PATCH 4/6] add some more features to roadmap \o/ --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ecfc62d..fd7ec79 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,9 @@ 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, [curl](https://linux.die.net/man/1/curl) and [jq](https://stedolan.github.io/jq/)) From 0cd1d750b469361113221a9248b5a6f1b06d4956 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Thu, 10 May 2018 12:12:03 +0200 Subject: [PATCH 5/6] add example of multinies description --- nfo_example.txt | 3 +++ 1 file changed, 3 insertions(+) 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 From 0954c1e074511f9bc88d21ec7785a7e75461e79b Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Sat, 19 May 2018 11:19:48 +0200 Subject: [PATCH 6/6] Add changelog for v0.5 --- CHANGELOG.md | 11 +++++++++++ prismedia_upload.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md 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/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 = (