tidy
This commit is contained in:
parent
fe87afe9d0
commit
94c7f98ce8
|
|
@ -10,21 +10,21 @@ from io import BytesIO
|
|||
class AudioConverterService:
|
||||
|
||||
@sync_to_async
|
||||
def __mp3_to_ogg(self, mp3: BytesIO) -> str:
|
||||
def __audio_to_ogg(self, audio: BytesIO) -> str:
|
||||
filename = f"./audios/{uuid4()}.ogg"
|
||||
|
||||
process = (
|
||||
ffmpeg.input("pipe:")
|
||||
.output(filename, loglevel="quiet")
|
||||
.output(filename, codec="libopus", loglevel="quiet")
|
||||
.overwrite_output()
|
||||
.run_async(pipe_stdin=True)
|
||||
)
|
||||
|
||||
process.communicate(input=mp3.getbuffer())
|
||||
process.communicate(input=audio.getbuffer())
|
||||
return filename
|
||||
|
||||
async def mp3_to_ogg(self, mp3: BytesIO) -> BytesIO:
|
||||
filename = await self.__mp3_to_ogg(mp3)
|
||||
async def audio_to_ogg(self, audio: BytesIO) -> BytesIO:
|
||||
filename = await self.__audio_to_ogg(audio)
|
||||
|
||||
async with aiofiles.open(filename, "rb") as file:
|
||||
content = BytesIO(initial_bytes=await file.read())
|
||||
|
|
|
|||
|
|
@ -41,20 +41,13 @@ class FileUploaderService:
|
|||
if uploaded_file:
|
||||
return
|
||||
|
||||
if file_url.endswith(".mp3") or file_url.endswith(".ogg"):
|
||||
converted_content = await self.audio_converter_service.audio_to_ogg(
|
||||
audio=BytesIO((await self.client.get(file_url)).read())
|
||||
)
|
||||
|
||||
converted_content = await self.audio_converter_service.mp3_to_ogg(
|
||||
mp3=BytesIO((await self.client.get(file_url)).read())
|
||||
)
|
||||
|
||||
uploaded_file_id = await self.planfix_client.upload_file(
|
||||
file_content=converted_content
|
||||
)
|
||||
|
||||
else:
|
||||
uploaded_file_id = await self.planfix_client.upload_file_from_url(
|
||||
file_url
|
||||
)
|
||||
uploaded_file_id = await self.planfix_client.upload_file(
|
||||
file_content=converted_content
|
||||
)
|
||||
|
||||
await self.uploaded_file_repository.upsert(
|
||||
UploadedFile(file_id=uploaded_file_id, file_url=file_url)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user