Implement copy links button

This commit is contained in:
Jorge Vargas 2025-03-11 19:50:28 -06:00
parent dbf115f254
commit c8cd8c724f
6 changed files with 156 additions and 4 deletions

View file

@ -1,4 +1,5 @@
import * as cheerio from 'cheerio'
import toast from 'react-hot-toast'
import { USER_AGENTS } from './consts'
import type { AlbumRow } from './types'
@ -103,3 +104,12 @@ export async function getDownloadUrl(trackPageUrl: string, lastReqRef: React.Ref
return mp3Links[0]
}
}
export async function copyDownloadUrls(albumUrl: string, lastReqRef: React.RefObject<number>) {
const tracks = await getTracks(albumUrl, lastReqRef)
const urlArray = await Promise.all(tracks.map(async (t) => getDownloadUrl(t.url, lastReqRef)))
const filterUrl = urlArray.filter((u) => !!u && u.length > 1).map((u) => encodeURI(u))
await navigator.clipboard.writeText(filterUrl.join('\n'))
toast.success('Copied links to the clipboard!')
}