MCPcopy Create free account
hub / github.com/NanmiCoder/MediaCrawler / parseUrl

Function parseUrl

webui/src/lib/urlParser.ts:64–130  ·  view source on GitHub ↗
(input: string, platform: string)

Source from the content-addressed store, hash-verified

62}
63
64export function parseUrl(input: string, platform: string): ParsedId {
65 const trimmed = input.trim()
66
67 // If it's just an ID (no URL structure), return as unknown type
68 if (!trimmed.includes('/') && !trimmed.includes('.')) {
69 return {
70 id: trimmed,
71 type: 'unknown',
72 original: trimmed,
73 isValid: trimmed.length > 0,
74 }
75 }
76
77 const patterns = platformPatterns[platform]
78 if (!patterns) {
79 return {
80 id: trimmed,
81 type: 'unknown',
82 original: trimmed,
83 isValid: false,
84 }
85 }
86
87 // Try video patterns
88 for (const pattern of patterns.video) {
89 const match = trimmed.match(pattern)
90 if (match && match[1]) {
91 return {
92 id: match[1],
93 type: 'video',
94 original: trimmed,
95 isValid: true,
96 }
97 }
98 }
99
100 // Try creator patterns
101 for (const pattern of patterns.creator) {
102 const match = trimmed.match(pattern)
103 if (match && match[1]) {
104 return {
105 id: match[1],
106 type: 'creator',
107 original: trimmed,
108 isValid: true,
109 }
110 }
111 }
112
113 // Fallback: try to extract any ID-like segment
114 const urlMatch = trimmed.match(/([a-zA-Z0-9_-]{6,})/)
115 if (urlMatch) {
116 return {
117 id: urlMatch[1],
118 type: 'unknown',
119 original: trimmed,
120 isValid: false,
121 }

Callers 1

parseMultipleUrlsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected