Exemplo n.º 1
0
async def get_curr_track(lfmbio):
    global ARTIST
    global SONG
    global LASTFMCHECK
    global RUNNING
    global USER_ID
    oldartist = ""
    oldsong = ""
    while LASTFMCHECK:
        try:
            if USER_ID == 0:
                USER_ID = (await lfmbio.client.get_me()).id
            user_info = await bot(GetFullUserRequest(USER_ID))
            RUNNING = True
            playing = User(LASTFM_USERNAME, lastfm).get_now_playing()
            SONG = playing.get_title()
            ARTIST = playing.get_artist()
            oldsong = environ.get("oldsong", None)
            oldartist = environ.get("oldartist", None)
            if playing is not None and SONG != oldsong and ARTIST != oldartist:
                environ["oldsong"] = str(SONG)
                environ["oldartist"] = str(ARTIST)
                if BIOPREFIX:
                    lfmbio = f"{BIOPREFIX} 🎧: {ARTIST} - {SONG}"
                else:
                    lfmbio = f"🎧: {ARTIST} - {SONG}"
                try:
                    if BOTLOG and LastLog:
                        await bot.send_message(
                            BOTLOG_CHATID,
                            f"Attempted to change bio to\n{lfmbio}")
                    await bot(UpdateProfileRequest(about=lfmbio))
                except AboutTooLongError:
                    short_bio = f"🎧: {SONG}"
                    await bot(UpdateProfileRequest(about=short_bio))
            else:
                if playing is None and user_info.about != DEFAULT_BIO:
                    await sleep(6)
                    await bot(UpdateProfileRequest(about=DEFAULT_BIO))
                    if BOTLOG and LastLog:
                        await bot.send_message(
                            BOTLOG_CHATID, f"Reset bio back to\n{DEFAULT_BIO}")
        except AttributeError:
            try:
                if user_info.about != DEFAULT_BIO:
                    await sleep(6)
                    await bot(UpdateProfileRequest(about=DEFAULT_BIO))
                    if BOTLOG and LastLog:
                        await bot.send_message(
                            BOTLOG_CHATID, f"Reset bio back to\n{DEFAULT_BIO}")
            except FloodWaitError as err:
                if BOTLOG and LastLog:
                    await bot.send_message(BOTLOG_CHATID,
                                           f"Error changing bio:\n{err}")
        except FloodWaitError as err:
            if BOTLOG and LastLog:
                await bot.send_message(BOTLOG_CHATID,
                                       f"Error changing bio:\n{err}")
        except WSError as err:
            if BOTLOG and LastLog:
                await bot.send_message(BOTLOG_CHATID,
                                       f"Error changing bio:\n{err}")
        await sleep(2)
    RUNNING = False
Exemplo n.º 2
0
async def get_curr_track(lfmbio):  # sourcery no-metrics
    oldartist = ""
    oldsong = ""
    while LASTFM_.LASTFMCHECK:
        try:
            if LASTFM_.USER_ID == 0:
                LASTFM_.USER_ID = (await lfmbio.client.get_me()).id
            user_info = (await catub(GetFullUserRequest(LASTFM_.USER_ID))).full_user
            LASTFM_.RUNNING = True
            playing = User(LASTFM_USERNAME, lastfm).get_now_playing()
            LASTFM_.SONG = playing.get_title()
            LASTFM_.ARTIST = playing.get_artist()
            oldsong = environ.get("oldsong", None)
            oldartist = environ.get("oldartist", None)
            if (
                playing is not None
                and LASTFM_.SONG != oldsong
                and LASTFM_.ARTIST != oldartist
            ):
                environ["oldsong"] = str(LASTFM_.SONG)
                environ["oldartist"] = str(LASTFM_.ARTIST)
                if BIO_PREFIX:
                    lfmbio = f"{BIO_PREFIX} 🎧: {LASTFM_.ARTIST} - {LASTFM_.SONG}"
                else:
                    lfmbio = f"🎧: {LASTFM_.ARTIST} - {LASTFM_.SONG}"
                try:
                    if BOTLOG and LASTFM_.LastLog:
                        await catub.send_message(
                            BOTLOG_CHATID, f"Attempted to change bio to\n{lfmbio}"
                        )
                    await catub(UpdateProfileRequest(about=lfmbio))
                except AboutTooLongError:
                    short_bio = f"🎧: {LASTFM_.SONG}"
                    await catub(UpdateProfileRequest(about=short_bio))
            if playing is None and user_info.about != DEFAULT_BIO:
                await sleep(6)
                await catub(UpdateProfileRequest(about=DEFAULT_BIO))
                if BOTLOG and LASTFM_.LastLog:
                    await catub.send_message(
                        BOTLOG_CHATID, f"Reset bio back to\n{DEFAULT_BIO}"
                    )
        except AttributeError:
            try:
                if user_info.about != DEFAULT_BIO:
                    await sleep(6)
                    await catub(UpdateProfileRequest(about=DEFAULT_BIO))
                    if BOTLOG and LASTFM_.LastLog:
                        await catub.send_message(
                            BOTLOG_CHATID, f"Reset bio back to\n{DEFAULT_BIO}"
                        )
            except FloodWaitError as err:
                if BOTLOG and LASTFM_.LastLog:
                    await catub.send_message(
                        BOTLOG_CHATID, f"Error changing bio:\n{err}"
                    )
        except (
            FloodWaitError,
            WSError,
            MalformedResponseError,
            AboutTooLongError,
        ) as err:
            if BOTLOG and LASTFM_.LastLog:
                await catub.send_message(BOTLOG_CHATID, f"Error changing bio:\n{err}")
        await sleep(2)
    LASTFM_.RUNNING = False
Exemplo n.º 3
0
async def _(event):
    """DeezLoader by @An0nimia. Ported for UniBorg by @SpEcHlDe"""
    if event.fwd_from:
        return

    strings = {
        "name": "DeezLoad",
        "arl_token_cfg_doc": "ARL Token for Deezer",
        "invalid_arl_token":
        "please set the required variables for this module",
        "wrong_cmd_syntax":
        "bruh, now i think how far should we go. please terminate my Session.",
        "server_error": "We're experiencing technical difficulties.",
        "processing": "`Downloading...`",
        "uploading": "`Uploading...`",
    }

    ARL_TOKEN = DEEZER_ARL_TOKEN

    if ARL_TOKEN is None:
        await event.edit(strings["invalid_arl_token"])
        return

    try:
        loader = deezloader.Login(ARL_TOKEN)
    except Exception as er:
        await event.edit(str(er))
        return

    temp_dl_path = os.path.join(TEMP_DOWNLOAD_DIRECTORY, str(time.time()))
    if not os.path.exists(temp_dl_path):
        os.makedirs(temp_dl_path)

    required_link = event.pattern_match.group(1)
    required_qty = event.pattern_match.group(2)
    required_qty = required_qty.strip() if required_qty else "MP3_320"

    await event.edit(strings["processing"])

    if "spotify" in required_link:
        if "track" in required_link:
            required_track = loader.download_trackspo(
                required_link,
                output=temp_dl_path,
                quality=required_qty,
                recursive_quality=True,
                recursive_download=True,
                not_interface=True,
            )
            await event.edit(strings["uploading"])
            await upload_track(required_track, event)
            shutil.rmtree(temp_dl_path)
            await event.delete()

        elif "album" in required_link:
            reqd_albums = loader.download_albumspo(
                required_link,
                output=temp_dl_path,
                quality=required_qty,
                recursive_quality=True,
                recursive_download=True,
                not_interface=True,
                zips=False,
            )
            await event.edit(strings["uploading"])
            for required_track in reqd_albums:
                await upload_track(required_track, event)
            shutil.rmtree(temp_dl_path)
            await event.delete()

    elif "deezer" in required_link:
        if "track" in required_link:
            required_track = loader.download_trackdee(
                required_link,
                output=temp_dl_path,
                quality=required_qty,
                recursive_quality=True,
                recursive_download=True,
                not_interface=True,
            )
            await event.edit(strings["uploading"])
            await upload_track(required_track, event)
            shutil.rmtree(temp_dl_path)
            await event.delete()

        elif "album" in required_link:
            reqd_albums = loader.download_albumdee(
                required_link,
                output=temp_dl_path,
                quality=required_qty,
                recursive_quality=True,
                recursive_download=True,
                not_interface=True,
                zips=False,
            )
            await event.edit(strings["uploading"])
            for required_track in reqd_albums:
                await upload_track(required_track, event)
            shutil.rmtree(temp_dl_path)
            await event.delete()

    elif "now" in required_link:
        playing = User(LASTFM_USERNAME, lastfm).get_now_playing()
        artist = str(playing.get_artist())
        song = str(playing.get_title())
        try:
            required_track = loader.download_name(
                artist=artist,
                song=song,
                output=temp_dl_path,
                quality=required_qty,
                recursive_quality=True,
                recursive_download=True,
                not_interface=True,
            )
        except BaseException as err:
            await event.edit(f"**ERROR :** {err}")
            await asyncio.sleep(5)
            return
        await event.edit(strings["uploading"])
        await upload_track(required_track, event)
        shutil.rmtree(temp_dl_path)
        await event.delete()

    else:
        await event.edit(strings["wrong_cmd_syntax"])
Exemplo n.º 4
0
 def is_valid_user(self, last_username):
     last_user = User(last_username, self.network)
     try:
         return bool(last_user.get_playcount() > 0)
     except:
         return False