diff --git a/cutter/cutter/main.py b/cutter/cutter/main.py index 36c12bf..9096812 100644 --- a/cutter/cutter/main.py +++ b/cutter/cutter/main.py @@ -72,7 +72,7 @@ class Cutter(object): ERROR_RETRY_INTERVAL = 5 RETRYABLE_UPLOAD_ERROR_WAIT_INTERVAL = 5 - def __init__(self, upload_locations, dbmanager, stop, name, segments_path): + def __init__(self, upload_locations, dbmanager, stop, name, segments_path, tags, title_header, description_footer): """upload_locations is a map {location name: upload location backend} Conn is a database connection. Stop is an Event triggering graceful shutdown when set. @@ -84,6 +84,9 @@ class Cutter(object): self.dbmanager = dbmanager self.stop = stop self.segments_path = segments_path + self.tags = tags + self.title_header = title_header + self.description_footer = description_footer self.logger = logging.getLogger(type(self).__name__) self.refresh_conn() @@ -341,11 +344,16 @@ class Cutter(object): try: video_id = upload_backend.upload_video( - title=job.video_title, - description=job.video_description, - tags=[], # TODO + title=( + "{} - {}".format(self.title_header, job.video_title) + if self.title_header else job.video_title + ), + description=( + "{}\n\n{}".format(job.video_description, self.description_footer) + if self.description_footer else job.video_description + ), + tags=self.tags, data=upload_wrapper(), - hidden=True, # TODO remove when not testing ) except JobConsistencyError: raise # this ensures it's not caught in the next except block @@ -515,7 +523,18 @@ class TranscodeChecker(object): return result.rowcount -def main(dbconnect, config, creds_file, name=None, base_dir=".", metrics_port=8003, backdoor_port=0): +def main( + dbconnect, + config, + creds_file, + name=None, + base_dir=".", + tags='', + title_header="", + description_footer="", + metrics_port=8003, + backdoor_port=0, +): """dbconnect should be a postgres connection string, which is either a space-separated list of key=value pairs, or a URI like: postgresql://USER:PASSWORD@HOST/DBNAME?KEY=VALUE @@ -534,6 +553,19 @@ def main(dbconnect, config, creds_file, name=None, base_dir=".", metrics_port=80 creds_file should contain any required credentials for the upload backends, as JSON. name defaults to hostname. + + tags should be a comma-seperated list of tags to attach to all videos. + + title_header will be prepended to all video titles, seperated by a " - ". + description_footer will be added as a seperate paragraph at the end of all video descriptions. + For example, with --title-header foo --description-footer 'A video of foo.', + then a video with title 'bar' and a description 'Bar with baz' would actually have: + title: foo - bar + description: + Bar with baz + + A video of foo. + """ common.PromLogCountsHandler.install() common.install_stacksampler() @@ -545,6 +577,8 @@ def main(dbconnect, config, creds_file, name=None, base_dir=".", metrics_port=80 if name is None: name = socket.gethostname() + tags = tags.split(',') if tags else [] + stop = gevent.event.Event() gevent.signal(signal.SIGTERM, stop.set) # shut down on sigterm @@ -583,7 +617,7 @@ def main(dbconnect, config, creds_file, name=None, base_dir=".", metrics_port=80 if backend.needs_transcode and not no_transcode_check: needs_transcode_check.append(backend) - cutter = Cutter(upload_locations, dbmanager, stop, name, base_dir) + cutter = Cutter(upload_locations, dbmanager, stop, name, base_dir, tags, title_header, description_footer) transcode_checkers = [ TranscodeChecker(backend, dbmanager, stop) for backend in needs_transcode_check diff --git a/docker-compose.jsonnet b/docker-compose.jsonnet index c5a96b7..0d7fc06 100644 --- a/docker-compose.jsonnet +++ b/docker-compose.jsonnet @@ -95,6 +95,16 @@ unlisted: {type: "youtube", hidden: true, no_transcode_check: true}, }, + // Fixed tags to add to all videos + video_tags:: ["DB13", "DB2019", "2019", "Desert Bus", "Desert Bus for Hope", "Child's Play Charity", "Child's Play", "Charity Fundraiser"], + + // The header to put at the front of video titles, eg. a video with a title + // of "hello world" with title header "foo" becomes: "foo - hello world". + title_header:: "DB2019", + + // The footer to put at the bottom of descriptions, in its own paragraph. + description_footer:: "Uploaded by the Desert Bus Video Strike Team", + // Path to a JSON file containing google credentials for sheetsync as keys // 'client_id', 'client_secret' and 'refresh_token'. // May be the same as cutter_creds_file. @@ -183,6 +193,9 @@ command: [ "--base-dir", "/mnt", "--backdoor-port", std.toString($.backdoor_port), + "--tags", std.join(",", $.video_tags), + "--title-header", $.title_header, + "--description-footer", $.description_footer, $.db_connect, std.manifestJson($.cutter_config), "/etc/wubloader-creds.json",