From f8039028c48a5feba23fcd33200b663e6228e5b0 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Wed, 16 Oct 2019 14:46:02 +1100 Subject: [PATCH] local upload backend: Add a testing option to show info upload_video() was called with This is useful because it lets us test uploads and tag logic without involving youtube. --- cutter/cutter/upload_backends.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cutter/cutter/upload_backends.py b/cutter/cutter/upload_backends.py index 4b33a02..0eb834e 100644 --- a/cutter/cutter/upload_backends.py +++ b/cutter/cutter/upload_backends.py @@ -1,5 +1,6 @@ import errno +import json import logging import os import re @@ -121,13 +122,18 @@ class Local(UploadBackend): then a returned video URL might look like: "http://example.com/videos/my-example-video-1ffd816b-6496-45d4-b8f5-5eb06ee532f9.ts" If not given, returns a file:// url with the full path. + write_info: + If true, writes a json file alongside the video file containing + the video title, description and tags. + This is intended primarily for testing purposes. Saves files under their title, plus a random video id to avoid conflicts. Ignores description and tags. """ - def __init__(self, credentials, path, url_prefix=None): + def __init__(self, credentials, path, url_prefix=None, write_info=False): self.path = path self.url_prefix = url_prefix + self.write_info = write_info # make path if it doesn't already exist try: os.makedirs(self.path) @@ -142,6 +148,13 @@ class Local(UploadBackend): title = re.sub('[^A-Za-z0-9_]', '-', title) filename = '{}-{}.ts'.format(title, video_id) # TODO with re-encoding, this ext must change filepath = os.path.join(self.path, filename) + if self.write_info: + with open(os.path.join(self.path, '{}-{}.json'.format(title, video_id))) as f: + f.write(json.dumps({ + 'title': title, + 'description': description, + 'tags': tags, + }) + '\n') with open(filepath, 'w') as f: if isinstance(data, str): # string