From b9cd76b1a2d5e005a4d9d04c7c35fc2d9de722ff Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sun, 18 Oct 2020 19:57:05 +1100 Subject: [PATCH] Add non-static implict tags in sheetsync In order for the upcoming playlist manager to be able to use the DB `tags` column to know what tags a video has, all the tags it needs need to be present. Previously, this was a problem because the day and category tags only get added at the cutter and so wouldn't be listed. This moves them so they are added when parsing the row in sheetsync. It also adds the poster moment tag if poster moment is checked. Note that fully static tags that go on all videos are still only added in cutter, but the playlist manager doesn't need to care about those (since by definition they will match every video). --- cutter/cutter/main.py | 4 ++-- sheetsync/sheetsync/main.py | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cutter/cutter/main.py b/cutter/cutter/main.py index 84eb5ce..e47ba2b 100644 --- a/cutter/cutter/main.py +++ b/cutter/cutter/main.py @@ -380,8 +380,8 @@ class Cutter(object): video_id, video_link = upload_backend.upload_video( title=job.video_title, description=job.video_description, - # Add category and sheet_name as tags - tags=self.tags + [job.category, job.sheet_name] + job.video_tags, + # Merge static and video-specific tags + tags=list(set(self.tags + job.video_tags)), data=upload_wrapper(), ) except (JobConsistencyError, JobCancelled, UploadError): diff --git a/sheetsync/sheetsync/main.py b/sheetsync/sheetsync/main.py index bf31a22..004627e 100644 --- a/sheetsync/sheetsync/main.py +++ b/sheetsync/sheetsync/main.py @@ -176,7 +176,7 @@ class SheetSync(object): # because then row_index won't be correct. if row_index == 0: continue - row = self.parse_row(row) + row = self.parse_row(worksheet, row) self.sync_row(worksheet, row_index, row, events.get(row['id'])) except Exception as e: # for HTTPErrors, http response body includes the more detailed error @@ -211,7 +211,7 @@ class SheetSync(object): event_counts.labels(*labels).set(count) return by_id - def parse_row(self, row): + def parse_row(self, worksheet, row): """Take a row as a sequence of columns, and return a dict {column: value}""" row_dict = {'_parse_errors': []} for column, index in self.column_map.items(): @@ -227,6 +227,16 @@ class SheetSync(object): value = None row_dict['_parse_errors'].append("Failed to parse column {}: {}".format(column, e)) row_dict[column] = value + # As a special case, add some implicit tags to the tags column. + # We prepend these to make it slightly more consistent for the editor, + # ie. it's always DAY, CATEGORY, POSTER_MOMENT, CUSTOM + row_dict['tags'] = ( + [ + row_dict['category'], # category name + worksheet, # sheet name + ] + (['Poster Moment'] if row_dict['poster_moment'] else []) + + row_dict['tags'] + ) return row_dict def sync_row(self, worksheet, row_index, row, event): @@ -236,7 +246,9 @@ class SheetSync(object): if event is None: # No event currently in DB, if any field is non-empty, then create it. # Otherwise ignore it. - if not any(row[col] for col in self.input_columns): + # Ignore the tags column for this check since it is never non-empty due to implicit tags + # (and even if there's other tags, we don't care if there's nothing else in the row). + if not any(row[col] for col in self.input_columns if col != 'tags'): return # Only generate row when needed (unless it's already there)