generated from richard-unterberg/ts-react-vike-start
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ user defined output bitrates, own context for lame converter
- Loading branch information
1 parent
396627b
commit 4bdc903
Showing
26 changed files
with
323 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import LinkElement from '#components/LinkElement' | ||
|
||
const Footer = () => ( | ||
<div className="mb-20 mt-20 text-small text-center"> | ||
<footer className="pb-20 mt-20 text-small text-center"> | ||
<div className="w-1/2 mb-10 border-grayDark h-1 border-dotted border-b-2 mx-auto" /> | ||
<LinkElement href="https://github.com/richard-unterberg/squeez"> | ||
⭐️ https://github.com/richard-unterberg/squeez | ||
<LinkElement href="https://github.com/richard-unterberg/squeezer"> | ||
⭐️ richard-unterberg/squeezer | ||
</LinkElement> | ||
</div> | ||
</footer> | ||
) | ||
|
||
export default Footer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export const AppConfig = { | ||
viteBaseUrl: '/squeez', | ||
viteBaseUrl: '/squeezer', | ||
defaultOutputBitrate: 320, | ||
} | ||
|
||
export const SomeIteration = [2, 4, 8, 16] | ||
export const OutputBitrates = [32, 40, 48, 56, 64, 80, 96, 112, 128, 192, 224, 256, 320] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useCallback, useContext, useMemo } from 'react' | ||
|
||
import useUploadContext from '#hooks/useUploadContext' | ||
import convertTo from '#lamejs/convert' | ||
import { LameContext } from '#lamejs/LameContextProvider' | ||
|
||
const useLameContext = () => { | ||
const context = useContext(LameContext) | ||
const lamejs = useMemo(() => context?.lamejs, [context?.lamejs]) | ||
const setLamejs = useMemo(() => context?.setLamejs, [context?.setLamejs]) | ||
const outputBits = useMemo(() => context?.outputBits, [context?.outputBits]) | ||
const setOutputBits = useMemo(() => context?.setOutputBits, [context?.setOutputBits]) | ||
const { attachments } = useUploadContext() | ||
|
||
const handleConvert = useCallback(() => { | ||
const conversionSequence = attachments.reduce( | ||
(chain, file) => | ||
chain.then(() => | ||
convertTo({ file, lameLib: lamejs, outputBits }) | ||
.then(mp3File => { | ||
const downloadLink = document.createElement('a') | ||
downloadLink.href = URL.createObjectURL(mp3File) | ||
downloadLink.download = mp3File.name | ||
downloadLink.click() | ||
}) | ||
.catch(error => { | ||
throw new Error(error) | ||
}), | ||
), | ||
Promise.resolve(), | ||
) | ||
|
||
return conversionSequence | ||
}, [attachments, lamejs, outputBits]) | ||
|
||
return { lamejs, outputBits, setLamejs, handleConvert, setOutputBits } | ||
} | ||
|
||
export default useLameContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { useCallback, useContext, useMemo } from 'react' | ||
|
||
import { UploadContext } from '#lamejs/UploadContextProvider' | ||
|
||
const isValidWav = (file: File) => file.type === 'audio/wav' | ||
|
||
const useUploadContext = () => { | ||
const context = useContext(UploadContext) | ||
|
||
const attachments = useMemo(() => context?.attachments || [], [context?.attachments]) | ||
const handleSetAttachments = useMemo( | ||
() => context?.setAttachments || (() => []), | ||
[context?.setAttachments], | ||
) | ||
|
||
const formatError = useMemo(() => context?.formatError || false, [context?.formatError]) | ||
const setFormatError = useMemo( | ||
() => context?.setFormatError || (() => false), | ||
[context?.setFormatError], | ||
) | ||
|
||
const isDropping = useMemo(() => context?.isDropping || false, [context?.isDropping]) | ||
const setIsDropping = useMemo( | ||
() => context?.setIsDropping || (() => false), | ||
[context?.setIsDropping], | ||
) | ||
|
||
const setAttachments = useCallback( | ||
(files: File[]) => { | ||
files.forEach(file => { | ||
if (!isValidWav(file)) { | ||
setFormatError('File must be a .wav file - Files ignored') | ||
return | ||
} | ||
const isDuplicate = attachments.some(prevFile => prevFile.name === file.name) | ||
|
||
if (isDuplicate) { | ||
setFormatError('File with the same name already exists - Files ignored') | ||
} else { | ||
// Add the file to the array if it's not a duplicate | ||
handleSetAttachments(previousFiles => [...previousFiles, file]) | ||
setFormatError(false) | ||
} | ||
}) | ||
}, | ||
[attachments, handleSetAttachments, setFormatError], | ||
) | ||
|
||
const removeAttachment = useCallback( | ||
(fileName: string) => { | ||
handleSetAttachments(previousFiles => previousFiles.filter(file => file.name !== fileName)) | ||
}, | ||
[handleSetAttachments], | ||
) | ||
|
||
const clearAttachments = useCallback(() => { | ||
handleSetAttachments([]) | ||
}, [handleSetAttachments]) | ||
|
||
if (!context) { | ||
throw new Error('useUploadContext must be used within a Dialog') | ||
} | ||
|
||
return { | ||
attachments, | ||
formatError, | ||
isDropping, | ||
setAttachments, | ||
setIsDropping, | ||
setFormatError, | ||
removeAttachment, | ||
clearAttachments, | ||
} as const | ||
} | ||
|
||
export default useUploadContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ export enum ICON_ID { | |
AudioLines, | ||
Drum, | ||
FileVolume, | ||
Trash, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.