Skip to content

Commit 85802e5

Browse files
authored
Merge pull request #5 from BOSSincrypto/devin/1780137152-fix-url-overhaul
fix: complete URL conversion overhaul
2 parents d599580 + f3ee43b commit 85802e5

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

app/ui.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22
import platform
33
import queue
4+
import re
45
from pathlib import Path
56
from tkinter import filedialog
7+
from urllib.parse import urlparse
68

79
import customtkinter as ctk
810

@@ -191,6 +193,12 @@ def _add_url(self):
191193
url = dialog.get_input()
192194
if url and url.strip():
193195
url = url.strip()
196+
if not url.startswith(("http://", "https://")):
197+
url = "https://" + url
198+
parsed = urlparse(url)
199+
if not parsed.netloc or "." not in parsed.netloc:
200+
self._status.configure(text="Invalid URL")
201+
return
194202
if url not in self._files:
195203
self._files.append(url)
196204
self._refresh_file_list()
@@ -354,8 +362,7 @@ def _save_output(self):
354362

355363
default_name = "output.md"
356364
if self._selected_file:
357-
base = os.path.basename(self._selected_file)
358-
default_name = Path(base).stem + ".md"
365+
default_name = self._safe_filename(self._selected_file)
359366

360367
path = filedialog.asksaveasfilename(
361368
defaultextension=".md",
@@ -379,7 +386,7 @@ def _save_all(self):
379386
count = 0
380387
seen: dict[str, int] = {}
381388
for result in done:
382-
stem = Path(os.path.basename(result.file_path)).stem
389+
stem = Path(self._safe_filename(result.file_path)).stem
383390
if stem in seen:
384391
seen[stem] += 1
385392
name = f"{stem}_{seen[stem]}.md"
@@ -393,5 +400,18 @@ def _save_all(self):
393400

394401
self._status.configure(text=f"Saved {count} file(s) to {directory}")
395402

403+
@staticmethod
404+
def _safe_filename(source: str) -> str:
405+
if source.startswith(("http://", "https://")):
406+
parsed = urlparse(source)
407+
name = parsed.netloc.replace("www.", "")
408+
path = parsed.path.rstrip("/")
409+
if path and path != "/":
410+
name += "_" + Path(path).stem
411+
name = re.sub(r'[<>:"/\\|?*]', "_", name)
412+
return name + ".md"
413+
base = os.path.basename(source)
414+
return Path(base).stem + ".md"
415+
396416
def _change_theme(self, choice: str):
397417
ctk.set_appearance_mode(choice.lower())

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ authors = [{ name = "BOSSincrypto" }]
1313
dependencies = [
1414
"customtkinter>=5.2.0",
1515
"markitdown[all]>=0.1.6",
16+
"youtube-transcript-api>=1.2.0",
1617
]
1718

1819
[project.scripts]

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
customtkinter>=5.2.0
22
markitdown[all]>=0.1.6
3+
youtube-transcript-api>=1.2.0

0 commit comments

Comments
 (0)