Add title and description header/footer in thrimshim instead of cutter

This accomplishes two things:
1. It allows thrimshim to properly validate length restrictions (not implemented yet)
2. It means that the database has a record of the values actually written for each of these rows,
instead of that information depending on how the cutter was configured at the time.
pull/116/head
Mike Lang 5 years ago
parent b0ea790407
commit ba746ff6e6

@ -73,7 +73,7 @@ class Cutter(object):
ERROR_RETRY_INTERVAL = 5 ERROR_RETRY_INTERVAL = 5
RETRYABLE_UPLOAD_ERROR_WAIT_INTERVAL = 5 RETRYABLE_UPLOAD_ERROR_WAIT_INTERVAL = 5
def __init__(self, upload_locations, dbmanager, stop, name, segments_path, tags, title_header, description_footer): def __init__(self, upload_locations, dbmanager, stop, name, segments_path, tags):
"""upload_locations is a map {location name: upload location backend} """upload_locations is a map {location name: upload location backend}
Conn is a database connection. Conn is a database connection.
Stop is an Event triggering graceful shutdown when set. Stop is an Event triggering graceful shutdown when set.
@ -86,8 +86,6 @@ class Cutter(object):
self.stop = stop self.stop = stop
self.segments_path = segments_path self.segments_path = segments_path
self.tags = tags self.tags = tags
self.title_header = title_header
self.description_footer = description_footer
self.logger = logging.getLogger(type(self).__name__) self.logger = logging.getLogger(type(self).__name__)
self.refresh_conn() self.refresh_conn()
@ -338,14 +336,8 @@ class Cutter(object):
# a second try around the whole thing. # a second try around the whole thing.
try: try:
video_id, video_link = upload_backend.upload_video( video_id, video_link = upload_backend.upload_video(
title=( title=job.video_title,
"{} - {}".format(self.title_header, job.video_title) description=job.video_description,
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
),
# Add category and sheet_name as tags # Add category and sheet_name as tags
tags=self.tags + [job.category, job.sheet_name], tags=self.tags + [job.category, job.sheet_name],
data=upload_wrapper(), data=upload_wrapper(),
@ -524,8 +516,6 @@ def main(
name=None, name=None,
base_dir=".", base_dir=".",
tags='', tags='',
title_header="",
description_footer="",
metrics_port=8003, metrics_port=8003,
backdoor_port=0, backdoor_port=0,
): ):
@ -552,17 +542,6 @@ def main(
name defaults to hostname. name defaults to hostname.
tags should be a comma-seperated list of tags to attach to all videos. 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.PromLogCountsHandler.install()
common.install_stacksampler() common.install_stacksampler()
@ -620,7 +599,7 @@ def main(
if backend.needs_transcode and not no_transcode_check: if backend.needs_transcode and not no_transcode_check:
needs_transcode_check.append(backend) needs_transcode_check.append(backend)
cutter = Cutter(upload_locations, dbmanager, stop, name, base_dir, tags, title_header, description_footer) cutter = Cutter(upload_locations, dbmanager, stop, name, base_dir, tags)
transcode_checkers = [ transcode_checkers = [
TranscodeChecker(backend, dbmanager, stop) TranscodeChecker(backend, dbmanager, stop)
for backend in needs_transcode_check for backend in needs_transcode_check

@ -194,8 +194,6 @@
"--base-dir", "/mnt", "--base-dir", "/mnt",
"--backdoor-port", std.toString($.backdoor_port), "--backdoor-port", std.toString($.backdoor_port),
"--tags", std.join(",", $.video_tags), "--tags", std.join(",", $.video_tags),
"--title-header", $.title_header,
"--description-footer", $.description_footer,
$.db_connect, $.db_connect,
std.manifestJson($.cutter_config), std.manifestJson($.cutter_config),
"/etc/wubloader-creds.json", "/etc/wubloader-creds.json",
@ -219,6 +217,8 @@
// Args for the thrimshim: database connection string // Args for the thrimshim: database connection string
command: [ command: [
"--backdoor-port", std.toString($.backdoor_port), "--backdoor-port", std.toString($.backdoor_port),
"--title-header", $.title_header,
"--description-footer", $.description_footer,
$.db_connect, $.db_connect,
$.channel, $.channel,
$.bustime_start, $.bustime_start,

@ -141,6 +141,21 @@ def get_row(ident):
if response["video_channel"] is None: if response["video_channel"] is None:
response["video_channel"] = app.default_channel response["video_channel"] = app.default_channel
response["bustime_start"] = app.bustime_start response["bustime_start"] = app.bustime_start
# remove any added headers or footers so round-tripping is a no-op
if (
app.title_header is not None
and response["video_title"] is not None
and response["video_title"].startswith(app.title_header + ' - ')
):
response["video_title"] = response["video_title"][len(app.title_header + ' - '):]
if (
app.description_footer is not None
and response["video_description"] is not None
and response["video_description"].endswith('\n\n' + app.description_footer)
):
response["video_description"] = response["video_description"][:-len('\n\n' + app.description_footer)]
logging.info('Row {} fetched'.format(ident)) logging.info('Row {} fetched'.format(ident))
return json.dumps(response) return json.dumps(response)
@ -205,6 +220,12 @@ def update_row(ident, editor=None):
new_row['editor'] = editor new_row['editor'] = editor
new_row['edit_time'] = datetime.datetime.utcnow() new_row['edit_time'] = datetime.datetime.utcnow()
# Include headers and footers
if app.title_header is not None and 'video_title' in new_row:
new_row['video_title'] = '{} - {}'.format(app.title_header, new_row['video_title'])
if app.description_footer is not None and 'video_description' in new_row:
new_row['video_description'] = '{}\n\n{}'.format(new_row['video_description'], app.description_footer)
# actually update database # actually update database
build_query = sql.SQL(""" build_query = sql.SQL("""
UPDATE events UPDATE events
@ -275,14 +296,18 @@ def reset_row(ident, editor=None):
@argh.arg('bustime-start', help='The start time in UTC for the event, for UTC-Bustime conversion') @argh.arg('bustime-start', help='The start time in UTC for the event, for UTC-Bustime conversion')
@argh.arg('--backdoor-port', help='Port for gevent.backdoor access. By default disabled.') @argh.arg('--backdoor-port', help='Port for gevent.backdoor access. By default disabled.')
@argh.arg('--no-authentication', help='Do not authenticate') @argh.arg('--no-authentication', help='Do not authenticate')
@argh.arg('--title-header', help='A header to prefix all titles with, seperated from the submitted title by " - "')
@argh.arg('--description-footer', help='A footer to suffix all descriptions with, seperated from the submitted description by a blank line.')
def main(connection_string, default_channel, bustime_start, host='0.0.0.0', port=8004, backdoor_port=0, def main(connection_string, default_channel, bustime_start, host='0.0.0.0', port=8004, backdoor_port=0,
no_authentication=False): no_authentication=False, title_header=None, description_footer=None):
"""Thrimshim service.""" """Thrimshim service."""
server = WSGIServer((host, port), cors(app)) server = WSGIServer((host, port), cors(app))
app.no_authentication = no_authentication app.no_authentication = no_authentication
app.default_channel = default_channel app.default_channel = default_channel
app.bustime_start = bustime_start app.bustime_start = bustime_start
app.title_header = title_header
app.description_footer = description_footer
stopping = gevent.event.Event() stopping = gevent.event.Event()
def stop(): def stop():

Loading…
Cancel
Save