diff --git a/README.md b/README.md index ca232b9..94fb8e3 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ google_credentials_file: /path/to/google-service-account.json google_sheet_id: "your_google_sheet_id" google_sheet_name: "Sheet1" +id_column: id + environments: production: peertube_instance: https://your-peertube-instance.example.com @@ -55,6 +57,8 @@ environments: Multiple environments can be defined under `environments:`. The `--env` argument selects which one to use at runtime. +id_column sets the name of the column in the Google Sheet used as the unique identifier for each video record. Defaults to id if omitted. Can be overridden at runtime with --id-column. + --- ## Google Sheet Format @@ -62,8 +66,8 @@ Multiple environments can be defined under `environments:`. The `--env` argument The script reads from a Google Sheet with the following columns: | Column | Required | Description | -|--------|----------|-------------| -| `id` | Yes | A local identifier for the video record | +|:----|:----|:----| +| (configurable, default `id`) | Yes | A local identifier for the video record. Column name is set via id_column in the config file or --id-column on the command line. | | `title` | Yes | Title of the video | | `file` | Yes | Path to the local video/media file | | `field_media_oembed_video` | Yes | Full URL to the PeerTube video (used to extract the short UUID) | @@ -98,6 +102,7 @@ python upload-media-transcripts.py \ | `--peertube-username` | No | Override the PeerTube username | | `--peertube-password` | No | Override the PeerTube password | | `--peertube-channel` | No | Override the PeerTube channel number | +| `--id-column` | No | Override the name of the identifier column from config (default: `id`)| ### Dry Run Example diff --git a/upload-media-transcripts b/upload-media-transcripts index fb03921..8a056bc 100755 --- a/upload-media-transcripts +++ b/upload-media-transcripts @@ -370,6 +370,7 @@ def parse_arguments(): parser.add_argument('--peertube-username', dest="peertube_username", help='PeerTube account username.') parser.add_argument('--peertube-password', dest="peertube_password", help='PeerTube account password.') parser.add_argument('--peertube-channel', dest="peertube_channel", help='PeerTube channel number.') + parser.add_argument('--id-column', dest="id_column", help='Name of the column to use as the unique row/media identifier (default: "id").') # Parse the arguments: args = parser.parse_args() @@ -524,7 +525,7 @@ def peertube_add_caption( def process_row(df: pd.DataFrame, row) -> pd.DataFrame: # Required Vars for all media objects. - video_id = row['id'] + video_id = row[id_column] video_title = row['title'] video_file = row['file'] @@ -599,7 +600,7 @@ def process_sheet(sheet_id: str, sheet_name: str, credentials_file): df = read_google_sheet(sheet_id, sheet_name, credentials_file) # Check for Required columns - required_columns = ['id','title','file','field_media_oembed_video'] + required_columns = [id_column,'title','file','field_media_oembed_video'] optional_columns = ['description','language','transcript','transcript_language'] row_count = 1 @@ -609,7 +610,7 @@ def process_sheet(sheet_id: str, sheet_name: str, credentials_file): # Process each row in the sheet for index,row in df.iterrows(): # Get Row information. - video_id = row['id'] + video_id = row[id_column] oembed_url = row['field_media_oembed_video'] transcript = row['transcript'] @@ -678,6 +679,11 @@ def main(): google_sheet_id = None google_sheet_name = None + # Set id_column variable (default to 'id' if not specified anywhere). + id_column = 'id' + if cfg.get('id_column') and cfg['id_column'] is not None: + id_column = cfg['id_column'] + # Override config file variable with command line parameters if they exist. if args.in_gs_creds is not None: google_credentials = args.in_gs_creds @@ -696,7 +702,6 @@ def main(): else: if cfg['google_sheet_name'] and cfg['google_sheet_name'] is not None: google_sheet_name = cfg['google_sheet_name'] - print(f"PeerTube Channel: {peertube_channel}") @@ -715,9 +720,12 @@ def main(): google_sheet_name = args.in_gs_name if args.log_file is not None: log_file = args.log_file + if args.id_column is not None: + id_column = args.id_column globals()['peertube_channel'] = peertube_channel globals()['peertube_instance'] = peertube_instance + globals()['id_column'] = id_column # Create the Log file. print(f"Creating log file: {args.log_file}")