Skip to content

feat(ui): extract URLs from pasted text or messages in URL input#95

Closed
miguelAngelo1999 wants to merge 1 commit into
vanloctech:mainfrom
miguelAngelo1999:feat/url-extraction-from-text
Closed

feat(ui): extract URLs from pasted text or messages in URL input#95
miguelAngelo1999 wants to merge 1 commit into
vanloctech:mainfrom
miguelAngelo1999:feat/url-extraction-from-text

Conversation

@miguelAngelo1999

Copy link
Copy Markdown

Problem

The URL input fields only accept one clean URL per line. If a user pastes a message like:

"Hey can you download this https://youtu.be/abc and also this one https://youtu.be/xyz for me?"

...nothing gets added to the queue because none of the lines are a valid URL by themselves.

Solution

Add extractUrls() to src/lib/sources.ts that:

  1. Tries each line as a standalone URL first (existing behavior preserved)
  2. If the line isn't a valid URL on its own, extracts all http:// / https:// URLs from within the text using a regex
  3. Strips trailing punctuation (.,;:!?)) that's commonly attached to URLs in messages
  4. Deduplicates results while preserving order

Update parseUniversalUrls(), DownloadContext.parseUrls(), and MetadataContext.parseUrls() to use this logic.

Files Changed

  • src/lib/sources.ts — new extractUrls() utility
  • src/contexts/DownloadContext.tsx — updated parseUrls()
  • src/contexts/MetadataContext.tsx — updated parseUrls()

@miguelAngelo1999 miguelAngelo1999 force-pushed the feat/url-extraction-from-text branch 3 times, most recently from 692b457 to 136b81e Compare July 2, 2026 21:37
- Add extractUrls() to sources.ts: regex pulls all http/https URLs from
  arbitrary text, deduplicates, strips trailing punctuation
- Update parseUniversalUrls() and parseUrls() in DownloadContext and
  MetadataContext so mixed text like 'download https://... and https://...'
  works on a single line or multiple lines
- Fix countUrls() in UrlInput to count actual URL matches (not lines)
- Auto-switch to multi-line mode when 2+ URLs detected on one line
- Auto-clean pasted input: replace mixed text with extracted URLs on
  separate lines
- Fix preview: appears when single URL detected within surrounding text
@miguelAngelo1999 miguelAngelo1999 force-pushed the feat/url-extraction-from-text branch from 136b81e to 3b362c0 Compare July 2, 2026 21:38
anhtahaylove added a commit to anhtahaylove/youwee that referenced this pull request Jul 3, 2026
Users often paste links inside chat messages or surrounding text, so enqueue flows should extract HTTP URLs once in the shared source helper instead of each input assuming one URL per line. The YouTube page keeps its YouTube-only filter while Universal, Gallery, and Metadata share the broader extraction behavior. The Windows Deno test harness also resolves long native paths so Deno permissions match Bun-created temp paths.

Constraint: Upstream PR vanloctech#95 only touched MetadataContext, but custom has multiple enqueue surfaces that already share source helpers.
Constraint: Bun on Windows can expose TEMP as ADMINI~1 while Deno canonicalizes to Administrator.
Rejected: Port upstream PR vanloctech#95 wholesale | it would disturb custom context memoization and miss Universal/Gallery counters.
Rejected: Add a new parsing dependency | URL extraction is small and covered by tests.
Confidence: high
Scope-risk: moderate
Directive: Keep pasted URL extraction centralized in src/lib/sources.ts so input surfaces do not drift.
Tested: bun run biome check --write .
Tested: bun run tsc -b
Tested: cargo check in src-tauri
Tested: bun test
Not-tested: Manual pasted-text enqueue in the installed Tauri UI before this commit.
@vanloctech

Copy link
Copy Markdown
Owner

Thanks for the UX improvement idea. Extracting URLs from pasted messages is useful, but this PR cannot be merged in its current form.

The PR description says it updates the shared URL parser, DownloadContext, UrlInput counting, paste cleanup, and multiline behavior, but the actual diff only changes MetadataContext.tsx. The main Download input and shared parseUniversalUrls() path are still unchanged.

There are also TypeScript regressions: useDownload is imported from ./DownloadContext, but it is exported from ./download-context; and MetadataContextType is no longer exported even though metadata-context.ts still imports it. The patch also removes cookieSkipPatterns from metadata fetch, which would break the existing skip-cookie setting for metadata jobs.

Could you please rebase on latest main and rework this as a focused shared helper in src/lib/sources.ts, then wire Download, Universal/Gallery/Metadata parsing and URL counting to that helper without changing the context architecture?

@anhtahaylove

Copy link
Copy Markdown
Contributor

I prepared a clean follow-up PR here: #99

It follows the maintainer feedback by adding shared extractUrls() in src/lib/sources.ts, wiring Download, Universal/Gallery, and Metadata parsing/counting through it, and leaving context architecture plus cookieSkipPatterns untouched.

vanloctech pushed a commit that referenced this pull request Jul 5, 2026
Pasted links often arrive inside chat messages or surrounding text, so URL input surfaces should extract HTTP(S) URLs once in src/lib/sources.ts and reuse that behavior across Download, Universal, Gallery, and Metadata without changing context architecture.

Constraint: Maintainer requested a focused shared helper after PR #95 only touched MetadataContext.

Constraint: Metadata fetch must keep existing cookieSkipPatterns behavior.

Rejected: Rework context provider exports | unrelated to URL parsing and caused regressions in PR #95.

Rejected: Add a parsing dependency | a small URL extractor is enough and test-covered.

Confidence: high

Scope-risk: moderate

Directive: Keep URL counting and enqueue parsing routed through extractUrls so pasted-message behavior does not drift between pages.

Tested: bunx biome check --write src/lib/sources.ts src/components/download/UrlInput.tsx src/components/download/UniversalUrlInput.tsx src/components/download/GalleryUrlInput.tsx src/contexts/DownloadContext.tsx src/contexts/MetadataContext.tsx tests/source-url-extraction.test.ts

Tested: bun test tests/source-url-extraction.test.ts

Tested: bun run tsc -b

Not-tested: Full bun run lint on Windows upstream worktree; existing CRLF line endings trigger 356 formatter diagnostics.

Not-tested: cargo check in clean PR worktree; missing bundled yt-dlp binary resource bin\\youwee-yt-dlp-x86_64-pc-windows-msvc.exe.
@vanloctech vanloctech closed this Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants