Beispiel #1
0
def input_media_audio(class_thumb_file):
    return InputMediaAudio(
        media=TestInputMediaAudio.media,
        caption=TestInputMediaAudio.caption,
        duration=TestInputMediaAudio.duration,
        performer=TestInputMediaAudio.performer,
        title=TestInputMediaAudio.title,
        thumb=class_thumb_file,
        parse_mode=TestInputMediaAudio.parse_mode,
        caption_entities=TestInputMediaAudio.caption_entities,
    )
Beispiel #2
0
def favorite(update, context):
    user = User.validate_user(update.effective_user)
    fav_episodes = Episode.objects(starrers=user)
    if len(fav_episodes) == 1:
        update.message.reply_audio(
            audio=fav_episodes.first().file_id
        )
    elif len(fav_episodes) >= 2 and len(fav_episodes) <= 5:
        update.message.reply_media_group(
            media=list(map(lambda episode: InputMediaAudio(
                media=episode.file_id
            ), fav_episodes))
        )
    elif len(fav_episodes) > 5:
        #!!!
        update.message.reply_media_group(
            media=list(map(lambda x: InputMediaAudio(x.file_id), fav_episodes))
        )
    else:
        update.message.reply_text(
            text='还没有收藏的单集~',
            reply_markup=InlineKeyboardMarkup.from_button(
                InlineKeyboardButton('订阅列表', switch_inline_query_current_chat=''))
        )
Beispiel #3
0
def get_preview(bot, update):
    query = update.callback_query
    data = str(query.data).split("=")[1]
    data = literal_eval(data)
    id = data['id']
    song_data = get_song_data(id)
    query_str, result, type = db.get_by_id(data['sId'])

    keys = [[],
            [
                InlineKeyboardButton("Reset",
                                     callback_data="/reset={}".format(data)),
                InlineKeyboardButton("Download",
                                     callback_data="/download={}".format(data))
            ]]
    size = len(result)
    setup_keyboard(data, keys, size)
    try:
        open("cache/preview/{}.mp3".format(id), 'rb')
    except Exception as e:
        print(e)
        url = "http://track.anghami.com/rest/v1/GETtrack.view?songid={}".format(
            id)
        r = requests.get(url)

        with open("cache/preview/{}".format(id), "wb") as f:
            f.write(r.content)
            f.flush()
            f.close()
        r.close()
        preview = AudioSegment.from_file("cache/preview/{}".format(id), "m4a")
        preview.export("cache/preview/{}.mp3".format(id), format="mp3")
        os.remove("cache/preview/{}".format(id))
    bot.answer_callback_query(callback_query_id=update.callback_query.id)
    bot.edit_message_media(
        timeout=999,
        reply_markup=InlineKeyboardMarkup(keys),
        chat_id=query.message.chat_id,
        message_id=query.message.message_id,
        media=InputMediaAudio(
            media=open("cache/preview/{}.mp3".format(id), 'rb'),
            title=song_data['title'],
            performer=song_data['artist'],
            thumb="https://anghamicoverart.akamaized.net/?id={}".format(
                song_data["coverArt"])))
Beispiel #4
0
        def build_media(parse_mode, med_type):
            kwargs = {}
            if parse_mode != ParseMode.HTML:
                kwargs["parse_mode"] = parse_mode
                kwargs["caption"] = markdown_caption
            else:
                kwargs["caption"] = html_caption

            if med_type == "animation":
                return InputMediaAnimation(animation, **kwargs)
            if med_type == "document":
                return InputMediaDocument(document, **kwargs)
            if med_type == "audio":
                return InputMediaAudio(audio, **kwargs)
            if med_type == "photo":
                return InputMediaPhoto(photo, **kwargs)
            if med_type == "video":
                return InputMediaVideo(video, **kwargs)
Beispiel #5
0
        def build_media(parse_mode, med_type):
            kwargs = {}
            if parse_mode != ParseMode.HTML:
                kwargs['parse_mode'] = parse_mode
                kwargs['caption'] = markdown_caption
            else:
                kwargs['caption'] = html_caption

            if med_type == 'animation':
                return InputMediaAnimation(animation, **kwargs)
            if med_type == 'document':
                return InputMediaDocument(document, **kwargs)
            if med_type == 'audio':
                return InputMediaAudio(audio, **kwargs)
            if med_type == 'photo':
                return InputMediaPhoto(photo, **kwargs)
            if med_type == 'video':
                return InputMediaVideo(video, **kwargs)
Beispiel #6
0
def youtubemusic(update, context):
    if len(context.args) == 1:
        url = context.args[0]
        video = pafy.new(url)
        bestaudio = video.getbestaudio(preftype="m4a")
        filepath = f"/tmp/{validateTitle(bestaudio.title)}.{bestaudio.extension}"
        music_size = bestaudio.get_filesize()
        if music_size > 1000 * 1000 * 10:
            update.message.reply_text(
                "对不起,这个音乐超过了10MB!Sorry, this music is more than 10MB.")
            return
        img = f"{config.run_path}/imgs/downloading.jpg"
        msg = update.message.reply_photo(
            open(img, 'rb'),
            caption=f"正在下载你的音乐/Downloading your music of {music_size/1000}KB..."
        )
        bestaudio.download(filepath=filepath, quiet=True)
        msg.edit_media(InputMediaAudio(open(filepath, 'rb')), timeout=60)
        os.remove(filepath)
    else:
        update.message.reply_text(
            "对不起,需要给我一个像样儿的网址/Sorry, but I need a URL after that.比如:\n/ytm ")
Beispiel #7
0
 def test_with_audio_file(self, audio_file):  # noqa: F811
     # fixture found in test_audio
     input_media_audio = InputMediaAudio(audio_file, caption="test 3")
     assert input_media_audio.type == self.type
     assert isinstance(input_media_audio.media, InputFile)
     assert input_media_audio.caption == "test 3"
Beispiel #8
0
 def test_with_local_files(self):
     input_media_audio = InputMediaAudio(data_file("telegram.mp4"),
                                         thumb=data_file("telegram.jpg"))
     assert input_media_audio.media == data_file("telegram.mp4").as_uri()
     assert input_media_audio.thumb == data_file("telegram.jpg").as_uri()
Beispiel #9
0
 def test_with_local_files(self):
     input_media_audio = InputMediaAudio(
         'tests/data/telegram.mp4', thumb='tests/data/telegram.jpg'
     )
     assert input_media_audio.media == (Path.cwd() / 'tests/data/telegram.mp4/').as_uri()
     assert input_media_audio.thumb == (Path.cwd() / 'tests/data/telegram.jpg/').as_uri()
Beispiel #10
0
 def test_with_local_files(self):
     input_media_audio = InputMediaAudio('tests/data/telegram.mp4',
                                         thumb='tests/data/telegram.jpg')
     assert input_media_audio.media == f"file://{Path.cwd() / 'tests/data/telegram.mp4'}"
     assert input_media_audio.thumb == f"file://{Path.cwd() / 'tests/data/telegram.jpg'}"