Skip to content

Commit 5122525

Browse files
committed
Allow for either of first two lines to be already formatted
1 parent e11fae2 commit 5122525

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

gui/src/main/python/browser_auth_dialog.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ def setup_auth(self):
101101
else:
102102
user_input = self.textarea.toPlainText()
103103
joined_headers = common.HeaderCleanup.cleanup_headers(user_input)
104-
print(joined_headers)
105104
YTMusic(ytmusicapi.setup(filepath=self.browser_file_path, headers_raw=joined_headers))
106105

107106
self.auth_signal.emit("Success")

ytmusic_deleter/common.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ def cleanup_headers(header_lines) -> str:
9999
This is necessary when the headers were copied from Chrome/Edge, which do not format them correctly.
100100
If the headers are already formatted, it returns them unchanged.
101101
"""
102+
logging.debug("Raw headers:\n%s", header_lines)
102103
if HeaderCleanup.is_already_formatted(header_lines):
103-
print("Headers are already formatted, returning as is.")
104+
logging.debug("Headers are already formatted, returning as is.")
104105
return header_lines.strip()
105106
header_lines = HeaderCleanup.remove_client_variations_block(header_lines)
107+
logging.debug("Headers after removing ClientVariations block:\n%s", header_lines)
106108
lines = header_lines.splitlines()
107109

108110
# Remove empty lines
@@ -118,7 +120,9 @@ def cleanup_headers(header_lines) -> str:
118120
# Handle odd number of lines
119121
if i < len(lines):
120122
result.append(lines[i])
121-
return "\n".join(result)
123+
joined_result = "\n".join(result)
124+
logging.debug("Formatted headers:\n%s", joined_result)
125+
return joined_result
122126

123127
@staticmethod
124128
def remove_client_variations_block(text: str) -> str:
@@ -160,16 +164,19 @@ def remove_client_variations_block(text: str) -> str:
160164
@staticmethod
161165
def is_already_formatted(header_text: str) -> bool:
162166
"""
163-
Returns True if the first non-empty line contains a colon followed by at least one
167+
Returns True if either of the first two non-empty lines contains a colon followed by at least one
164168
non-space character, indicating it's already formatted as 'Header: Value'.
165169
"""
170+
checked = 0
166171
for line in header_text.splitlines():
167172
line = line.strip()
168173
if not line:
169174
continue
175+
checked += 1
170176
if ":" in line:
171177
parts = line.split(":", 1)
172-
return bool(parts[1].strip())
173-
else:
174-
return False
178+
if parts[1].strip():
179+
return True
180+
if checked >= 2:
181+
break
175182
return False

0 commit comments

Comments
 (0)