akborana4 commited on
Commit
55684d8
·
verified ·
1 Parent(s): 8c64e05

Update client/src/utils.js

Browse files
Files changed (1) hide show
  1. client/src/utils.js +18 -0
client/src/utils.js CHANGED
@@ -1,10 +1,13 @@
1
  export function detectMediaTypeFromUrl(url) {
2
  try {
3
  const u = new URL(url);
 
4
  const path = u.pathname.toLowerCase();
 
5
  if (/\.(mp4|webm|ogg|mkv|mov|m4v)$/.test(path)) return 'video';
6
  if (/\.(mp3|wav|aac|m4a|flac|ogg|opus)$/.test(path)) return 'audio';
7
  } catch {}
 
8
  return 'unknown';
9
  }
10
 
@@ -19,3 +22,18 @@ export function prettyError(e) {
19
  if (e.message) return e.message;
20
  return JSON.stringify(e);
21
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  export function detectMediaTypeFromUrl(url) {
2
  try {
3
  const u = new URL(url);
4
+ const host = u.hostname.toLowerCase();
5
  const path = u.pathname.toLowerCase();
6
+ if (host.includes('youtube.com') || host.includes('youtu.be')) return 'youtube';
7
  if (/\.(mp4|webm|ogg|mkv|mov|m4v)$/.test(path)) return 'video';
8
  if (/\.(mp3|wav|aac|m4a|flac|ogg|opus)$/.test(path)) return 'audio';
9
  } catch {}
10
+ if (/^[a-zA-Z0-9_-]{11}$/.test(url)) return 'youtube';
11
  return 'unknown';
12
  }
13
 
 
22
  if (e.message) return e.message;
23
  return JSON.stringify(e);
24
  }
25
+
26
+ export function getThumb(meta) {
27
+ if (!meta) return null;
28
+ return (
29
+ meta.thumb ||
30
+ meta.image ||
31
+ meta.thumbnail ||
32
+ meta.song_image ||
33
+ meta.album_image ||
34
+ meta.image_url ||
35
+ meta?.images?.cover ||
36
+ meta?.images?.[0] ||
37
+ null
38
+ );
39
+ }