import openpyxl import sys # Ensure correct number of arguments if len(sys.argv) != 5: print("Usage: update_excel.py ") sys.exit(1) # Read command-line arguments filename = sys.argv[1].strip() audio_languages = sys.argv[2].strip() if sys.argv[2].strip() else "NONE" subtitle_languages = sys.argv[3].strip() if sys.argv[3].strip() else "NONE" codec = sys.argv[4].strip().lower() # Excel file path excel_file = "/home/honney/mount/Storage/Nextcloud/DVDs_Blueray.xlsx" # Load the workbook and select the first sheet workbook = openpyxl.load_workbook(excel_file) sheet = workbook.active temp = 0 # Find the row containing the filename for row in sheet.iter_rows(min_row=2, max_row=sheet.max_row, min_col=1, max_col=1): file_cell = row[0] if file_cell.value and isinstance(file_cell.value, str) and file_cell.value.strip() == filename: temp += 1 row_index = file_cell.row # Get row number # Ensure filename stays unchanged sheet.cell(row=row_index, column=1).value = filename # Column A (Filename) # Update Audio and Subtitle languages (if empty, set to "NONE") if sheet.cell(row=row_index, column=7).value == audio_languages: temp += 1 else: sheet.cell(row=row_index, column=7).value = audio_languages # Column G (Audio) if sheet.cell(row=row_index, column=8).value == subtitle_languages: temp += 1 else: sheet.cell(row=row_index, column=8).value = subtitle_languages # Column H (Subtitles) # If codec is h265, set columns D, E, F to 1 if codec == "h265": if sheet.cell(row=row_index, column=4).value == 1: temp += 1 else: sheet.cell(row=row_index, column=4).value = 1 if sheet.cell(row=row_index, column=5).value == 1: temp += 1 else: sheet.cell(row=row_index, column=5).value = 1 if sheet.cell(row=row_index, column=6).value == 1: temp += 1 else: sheet.cell(row=row_index, column=6).value = 1 if sheet.cell(row=row_index, column=3).value: dvd = sheet.cell(row=row_index, column=3).value else: sheet.cell(row=row_index, column=3).value = "DVD" dvd = "DVD" if sheet.cell(row=row_index, column=2).value == "NOT CHECKED": sheet.cell(row=row_index, column=2).value = "" # Debugging: Confirm columns updated else: print(f"❌ Codec Wrong {filename}") # Debugging: Confirm updates # print(f"✅ Updated row {row_index} -> Audio: {audio_languages}, Subtitles: {subtitle_languages}, Codec: {codec}") break # Stop loop once match is found if temp == 0: print(f"❌ No matching row found for {filename}") elif temp < 0 and temp != 6: print(f"🟨 Updated Info for {filename}") elif temp == 6: print(f"🔵 Allready has info for {filename}") else: print(f"✅ {row_index}: {filename} | | {dvd} | 1 | 1 | 1 | {audio_languages} | {subtitle_languages}") # Save the updated workbook workbook.save(excel_file) # print(f"✅ Successfully updated Excel for {filename}")