Exemplo n.º 1
0
async def yt_x_bleck_megik(link: str) -> Optional[str]:
    if not (yt_id := get_yt_video_id(link)):
        if not (
            (output := await get_song_link(link))
            and (pf_ := output.get("linksByPlatform"))
            and (yt_ := pf_.get("youtube"))
        ):
Exemplo n.º 2
0
    else:
        song_path = safe_filename(await client.download_media(msg.audio))
        thumb = await extract_thumb(song_path, key)
    if song_path and (outf := await convert_raw(song_path, key)):
        return outf, thumb


async def yt_x_bleck_megik(link: str) -> Optional[str]:
    if not (yt_id := get_yt_video_id(link)):
        if not (
            (output := await get_song_link(link))
            and (pf_ := output.get("linksByPlatform"))
            and (yt_ := pf_.get("youtube"))
        ):
            return
        yt_id = get_yt_video_id(yt_.get("url"))
    return yt_id


@pool.run_in_thread
def convert_raw(audio_path: str, key: str = None) -> Optional[str]:
    filename = key or rand_key()
    raw_audio = keypath(filename)
    try:
        ffmpeg.input(audio_path).output(
            raw_audio, format="s16le", acodec="pcm_s16le", ac=2, ar="48k"
        ).overwrite_output().run()
    except ffmpeg._run.Error as ff_e:
        LOG.info(f"ERROR: FFMPEG coudn't transcode rawfile due to :  {ff_e}")
    else:
        os.remove(audio_path)