Example #1
0
def get_or_create_unconverted_source_url(youtube_id):
    matching_keys = list(unconverted_bucket.list(youtube_id))
    matching_key = None

    if len(matching_keys) > 0:
        if len(matching_keys) > 1:
            logger.warning("More than 1 matching unconverted video URL found for video {0}".format(youtube_id))
        matching_key = matching_keys[0]
    else:
        logger.info("Unconverted video not available on s3 yet, downloading from youtube to create it.")

        video_path = youtube.download(youtube_id)
        logger.info("Downloaded video to {0}".format(video_path))

        assert(video_path)

        video_extension = splitext(video_path)[1]
        assert video_extension[0] == "."
        video_extension = video_extension[1:]
        if video_extension not in ["flv", "mp4"]:
            logger.warning("Unrecognized video extension {0} when downloading video {1} from YouTube".format(video_extension, youtube_id))

        matching_key = Key(unconverted_bucket, "{0}/{0}.{1}".format(youtube_id, video_extension))
        matching_key.set_contents_from_filename(video_path)

        os.remove(video_path)
        logger.info("Deleted {0}".format(video_path))

    return "s3://{0}/{1}".format(unconverted_bucket.name, matching_key.name)
Example #2
0
async def play(client: Client, message_: Message):
    audio = (message_.reply_to_message.audio or message_.reply_to_message.voice
             ) if message_.reply_to_message else None

    res = await message_.reply_text("**MʋsɩcRoɓo𝓽:** 🔄 Pʀocɘssɩŋʛ...")

    if audio:
        if round(audio.duration / 60) > DURATION_LIMIT:
            raise DurationLimitError(
                f"**MʋsɩcRoɓo𝓽:** Vɩɗɘos ɭoŋʛɘʀ tʜʌŋ {DURATION_LIMIT} ɱɩŋʋtɘ(s) ʌʀɘŋ't ʌɭɭowɘɗ, tʜɘ pʀovɩɗɘɗ vɩɗɘo ɩs {audio.duration / 60} ɱɩŋʋtɘ(s)"
            )

        file_name = audio.file_id + audio.file_name.split(".")[-1]
        file_path = await convert(await
                                  message_.reply_to_message.download(file_name)
                                  )
    else:
        messages = [message_]
        text = ""
        offset = None
        length = None

        if message_.reply_to_message:
            messages.append(message_.reply_to_message)

        for message in messages:
            if offset:
                break

            if message.entities:
                for entity in message.entities:
                    if entity.type == "url":
                        text = message.text or message.caption
                        offset, length = entity.offset, entity.length
                        break

        if offset == None:
            await res.edit_text(
                "**MʋsɩcRoɓo𝓽:**❕ Yoʋ ɗɩɗ ŋot ʛɩvɘ ɱɘ ʌŋƴtʜɩŋʛ to pɭʌƴ.")
            return

        url = text[offset:offset + length]

        file_path = await convert(download(url))

    try:
        is_playing = tgcalls.pytgcalls.is_playing(message_.chat.id)

    except:
        is_playing = False

    if is_playing:
        position = await sira.add(message_.chat.id, file_path)
        await res.edit_text(
            f"**MʋsɩcRoɓo𝓽:** #️⃣ Qʋɘʋɘɗ ʌt posɩtɩoŋ {position}.")

    else:
        await res.edit_text("**MʋsɩcRoɓo𝓽:** ▶️ Pɭʌƴɩŋʛ...")
        tgcalls.pytgcalls.join_group_call(message_.chat.id, file_path, 48000)
Example #3
0
async def play(client: Client, message_: Message):
    audio = (message_.reply_to_message.audio or message_.reply_to_message.voice
             ) if message_.reply_to_message else None

    res = await message_.reply_text("🔄 Proses...")

    if audio:
        if round(audio.duration / 60) > DURATION_LIMIT:
            raise DurationLimitError(
                f"Musik lebih dari {DURATION_LIMIT} minute(s) tidak dapat dimainkan, Musik ini berdurasi {audio.duration / 60} minute(s)"
            )

        file_name = audio.file_id + audio.file_name.split(".")[-1]
        file_path = await convert(await
                                  message_.reply_to_message.download(file_name)
                                  )
    else:
        messages = [message_]
        text = ""
        offset = None
        length = None

        if message_.reply_to_message:
            messages.append(message_.reply_to_message)

        for message in messages:
            if offset:
                break

            if message.entities:
                for entity in message.entities:
                    if entity.type == "url":
                        text = message.text or message.caption
                        offset, length = entity.offset, entity.length
                        break

        if offset == None:
            await res.edit_text(
                "Lagu apa yang ingin anda mainkan? coba reply /play ke link lagu yang ingin dimainkan."
            )
            return

        url = text[offset:offset + length]

        file_path = await convert(download(url))

    try:
        is_playing = tgcalls.pytgcalls.is_playing(message_.chat.id)
    except:
        is_playing = False

    if is_playing:
        position = await sira.add(message_.chat.id, file_path)
        await res.edit_text(
            f"#️⃣ Lagu dimasukkan kedalam antrian nomor {position}.")
    else:
        await res.edit_text("▶️ Memainkan lagu...")
        tgcalls.pytgcalls.join_group_call(message_.chat.id, file_path, 48000)
Example #4
0
async def play(_, message: Message):
    audio = (message.reply_to_message.audio or message.reply_to_message.voice
             ) if message.reply_to_message else None

    res = await message.reply_text("🔄 İşleme Alındı...")

    if audio:
        if round(audio.duration / 60) > DURATION_LIMIT:
            raise DurationLimitError(
                f"Daha uzun videolar {DURATION_LIMIT} Dakika(s) izin verilmiyor, sağlanan video {audio.duration / 60} Dakika(s)"
            )

        file_name = audio.file_unique_id + "." + (audio.file_name.split(
            ".")[-1] if not isinstance(audio, Voice) else "ogg")
        file_path = await converter.convert((
            await message.reply_to_message.download(file_name)
        ) if not path.isfile(path.join("downloads", file_name)) else file_name)
    else:
        messages = [message]
        text = ""
        offset = None
        length = None

        if message.reply_to_message:
            messages.append(message.reply_to_message)

        for _message in messages:
            if offset:
                break

            if _message.entities:
                for entity in _message.entities:
                    if entity.type == "url":
                        text = _message.text or _message.caption
                        offset, length = entity.offset, entity.length
                        break

        if offset in (None, ):
            await res.edit_text("❕ bana çalmam için hiçbir şey vermedin.")
            return

        url = text[offset:offset + length]

        file_path = await converter.convert(youtube.download(url))

    if message.chat.id in callsmusic.pytgcalls.active_calls:
        position = queues.add(message.chat.id, file_path)
        await res.edit_text(f"#️⃣ Sıraya Alındınız {position}.")
    else:
        await res.edit_text("▶️ Başlatılıyor...")
        callsmusic.pytgcalls.join_group_call(
            message.chat.id, file_path, 48000,
            callsmusic.pytgcalls.get_cache_peer())
Example #5
0
async def play(_, message: Message):
    audio = (message.reply_to_message.audio or message.reply_to_message.voice
             ) if message.reply_to_message else None

    res = await message.reply_text(
        "🔄 Lagu Kamu Sedang Di-Proses, Harap Tunggu Sebentar!...")

    if audio:
        if round(audio.duration / 60) > DURATION_LIMIT:
            raise DurationLimitError(
                f"Videos longer than {DURATION_LIMIT} minute(s) aren't allowed, the provided video is {audio.duration / 60} minute(s)"
            )

        file_name = audio.file_unique_id + "." + (audio.file_name.split(
            ".")[-1] if not isinstance(audio, Voice) else "ogg")
        file = await converter.convert((
            await message.reply_to_message.download(file_name)
        ) if not path.isfile(path.join("downloads", file_name)) else file_name)
    else:
        messages = [message]
        text = ""
        offset = None
        length = None

        if message.reply_to_message:
            messages.append(message.reply_to_message)

        for _message in messages:
            if offset:
                break

            if _message.entities:
                for entity in _message.entities:
                    if entity.type == "url":
                        text = _message.text or _message.caption
                        offset, length = entity.offset, entity.length
                        break

        if offset in (None, ):
            await res.edit_text(
                "❗️ Maaf Kalau Mau Menggunakan Aku, Ketik /play Dan Cari Judul Lagu Habis Itu Reply Pesanmu Dan Aku Akan Melaksanakan Tugas!."
            )
            return

        url = text[offset:offset + length]
        file = await converter.convert(youtube.download(url))

    if message.chat.id in callsmusic.active_chats:
        position = await queues.put(message.chat.id, file=file)
        await res.edit_text(f"*️⃣ Lagumu Akan Diputar Dinomor {position}")
    else:
        await res.edit_text("🎧 Okeyy, Lagumu Sudah Di-Mulai!...")
        await callsmusic.set_stream(message.chat.id, file)
Example #6
0
async def play(client: Client, message_: Message):
    audio = (message_.reply_to_message.audio or message_.reply_to_message.voice) if message_.reply_to_message else None
    chat_id=message_.chat.id
    res = await message_.reply_text("🔄 Please Wait...")

    if audio:
        if round(audio.duration / 60) > DURATION_LIMIT:
            raise DurationLimitError(
                f"Videos longer than {DURATION_LIMIT} minute(s) aren't allowed, the provided video is {audio.duration / 60} minute(s)"
            )

        file_name = audio.file_id + audio.file_name.split(".")[-1]
        file = await convert(await message_.reply_to_message.download(file_name))
    else:
        messages = [message_]
        text = ""
        offset = None
        length = None

        if message_.reply_to_message:
            messages.append(message_.reply_to_message)

        for message in messages:
            if offset:
                break

            if message.entities:
                for entity in message.entities:
                    if entity.type == "url":
                        text = message.text or message.caption
                        offset, length = entity.offset, entity.length
                        break

        if offset == None:
            await res.edit_text("❕ I don't know what you want to play")
            return

        url = text[offset:offset+length]

        file =await convert(download(url))

    if message_.chat.id in tgcalls.GroupsOn:
        position = sira.add(message_.chat.id, file)
        await res.edit_text(f"#️⃣ Queued at position {position}.")
    else:
        await res.edit_text("▶️Now Playing...")
        res.delete
        m = await client.send_photo(
        chat_id=message_.chat.id,
        photo="https://telegra.ph/file/5af2e8a554ace2ca898b0.jpg",
        caption=f"Playing Your song Via RADIO CAT.",
         ) 
        tgcalls.setsong(message_.chat.id, file)
Example #7
0
async def play(_, message: Message):
    audio = (message.reply_to_message.audio or message.reply_to_message.voice) if message.reply_to_message else None

    res = await message.reply_text(f"**{Bn} :** 🔄 Pʀᴏᴄᴇssɪɴɢ...")

    if audio:
        if round(audio.duration / 60) > DURATION_LIMIT:
            raise DurationLimitError(
                f"**{Bn} :** ᴠɪᴅᴇᴏs ʟᴏɴɢᴇʀ ᴛʜᴀɴ {DURATION_LIMIT} ᴍɪɴᴜᴛᴇ(s) ᴀʀᴇɴ'ᴛ ᴀʟʟᴏᴡᴇᴅ, ᴛʜᴇ ᴘʀᴏᴠɪᴅᴇᴅ ᴠɪᴅᴇᴏ ɪs {audio.duration / 60} ᴍɪɴᴜᴛᴇ(s)"
            )

        file_name = audio.file_unique_id + "." + (
            audio.file_name.split(".")[-1] if not isinstance(audio, Voice) else "ogg"
        )
        file_path = await converter.convert(
            (await message.reply_to_message.download(file_name))
            if not path.isfile(path.join("downloads", file_name)) else file_name
        )
    else:
        messages = [message]
        text = ""
        offset = None
        length = None

        if message.reply_to_message:
            messages.append(message.reply_to_message)

        for _message in messages:
            if offset:
                break

            if _message.entities:
                for entity in _message.entities:
                    if entity.type == "url":
                        text = _message.text or _message.caption
                        offset, length = entity.offset, entity.length
                        break

        if offset in (None,):
            await res.edit_text(f"**{Bn} :**❕ Yᴏᴜ ᴅɪᴅ ɴᴏᴛ ɢɪᴠᴇ ᴍᴇ ᴀɴʏᴛʜɪɴɢ ᴛᴏ ᴘʟᴀʏ.")
            return

        url = text[offset:offset + length]

        file_path = await converter.convert(youtube.download(url))

    if message.chat.id in callsmusic.pytgcalls.active_calls:
        position = queues.add(message.chat.id, file_path)
        await res.edit_text(f"**{Bn} :** #️⃣ ǫᴜᴇᴜᴅ ᴀᴛ ᴘᴏsɪᴛɪᴏɴ {position}.")
    else:
        await res.edit_text(f"**{Bn} :** ▶️ Pʟᴀʏɪɴɢ...")
        callsmusic.pytgcalls.join_group_call(message.chat.id, file_path, 48000, callsmusic.pytgcalls.get_cache_peer())
Example #8
0
async def play(client: Client, message_: Message):
    messages = [message_]
    text = ""
    offset = None
    length = None

    if message_.reply_to_message:
        messages.append(message_.reply_to_message)

    for message in messages:
        if offset:
            break

        if message.entities:
            for entity in message.entities:
                if entity.type == "url":
                    text = message.text or message.caption
                    offset, length = entity.offset, entity.length
                    break

    if offset == None:
        await message_.reply_text("You did not provide a video URL.")
        return

    url = text[offset:offset+length]

    await message_.reply_text("Downloading and converting...")

    file_path = await convert(download(url))

    if message_.chat.id in pytgcalls.get_active_voice_chats():
        await message_.reply_text(
            "There is a song being played at the moment, what do you want to do?",
            reply_markup=InlineKeyboardMarkup(
                [
                    [
                        InlineKeyboardButton(
                            "Play now", callback_data=file_path
                        )
                    ],
                    [
                        InlineKeyboardButton(
                            "Don't play, close this.", callback_data="close"
                        )
                    ]
                ]
            )
        )
    else:
        await message_.reply_text("Playing...")
        pytgcalls.join_group_call(message_.chat.id, file_path, 48000)
Example #9
0
    def download_video(self, youtube_id, permalink):
        """Download the video with the specified YouTube ID.
        If it has already been downloaded, the actual download is skipped.
        Returns a Video instance.
        """
        try:
            v = self.db.query(Video).filter_by(youtubeId=youtube_id).one()
        except NoResultFound:
            v = Video(youtube_id, permalink)
            self.db.add(v)

        v.localPath = locate_video(self.cfg.dest_dir, v.youtubeId)

        if v.localPath is None:
            youtube.download(self.cfg.dest_dir, v.youtubeId)
            v.localPath = locate_video(self.cfg.dest_dir, v.youtubeId)

        if v.localPath is None:
            v.state = Video.ERROR
        else:
            v.state = Video.DOWNLOADED
            v.downloaded = dt.datetime.now()
            v.localModified = dt.datetime.now()
        return v
Example #10
0
def add():
    link = None
    result = None
    if flask_login.current_user.is_anonymous:
        title = 'Главная страница'
    else:
        title = flask_login.current_user.id
    if request.method == 'POST' and 'link' in request.form:
        link = request.form['link']
        result = youtube.download(link)
        if result:
            return redirect("/")
        else:
            result = 'Ошибка загрузки. Проверьте ссылку'
    return render_template('add.html', username=title, error=result)
Example #11
0
def get_or_create_unconverted_source_url(youtube_id):
    matching_keys = list(unconverted_bucket.list_blobs(prefix=youtube_id))

    # TODO(alpert): How do these .part files get created? They're not real
    # video files and should be ignored.
    matching_keys = [key for key in matching_keys
                     if not key.name.endswith('.part')]

    matching_key = None

    if matching_keys:
        if len(matching_keys) > 1:
            util.logger.warning("More than 1 matching unconverted video "
                                "URL found for video {0}".format(youtube_id))
        matching_key = matching_keys[0]
    else:
        util.logger.info("Unconverted video not available on GCS yet, "
                         "downloading from youtube to create it.")

        video_path = youtube.download(youtube_id)
        if not video_path:
            message = "Error downloading video {0}".format(youtube_id)
            util.logger.warning(message)
            return
        util.logger.info("Downloaded video to {0}".format(video_path))

        video_extension = os.path.splitext(video_path)[1]
        assert video_extension[0] == "."
        video_extension = video_extension[1:]
        if video_extension not in ["flv", "mp4"]:
            message = ("Unrecognized video extension {0} when downloading "
                       "video {1} from YouTube".format(video_extension,
                                                       youtube_id))
            util.logger.warning(message)
        # Upload video file into gcs unconverted bucket.
        matching_key = unconverted_bucket.blob(
            "{0}/{0}.{1}".format(youtube_id,
                                 video_extension))
        matching_key.upload_from_filename(video_path)

        os.remove(video_path)
        util.logger.info("Deleted {0}".format(video_path))

    return "gcs://{0}/{1}".format(unconverted_bucket.name, matching_key.name)