Implement copy links button
This commit is contained in:
parent
dbf115f254
commit
c8cd8c724f
6 changed files with 156 additions and 4 deletions
|
|
@ -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!')
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue