def pv(bot, update, groups, lang): data = voca_db.song(groups[0], lang=lang, fields='MainPicture, Names, Lyrics, Artists, PVs') inline = bool(update.callback_query.inline_message_id) # TODO: Deal with several of the same service. Ex: 17523 has two YT for pv_info in data['pVs']: if pv_info['service'] == groups[1]: text = '' if inline: text = content_parser(data, info=True, inline=True, bot_name=bot.username) text += '\n\n' + '🎥' text += _('<b>{service} PV for {song} by {artist}</b>\n' 'PV Title:\n{name}\n{url}').format( song=data['name'], artist=data['artistString'], service=pv_info['service'], name=pv_info['name'], url=pv_info['url']) edit_message_text(bot, update, send_if_possible=True, text=text, reply_markup=song_keyboard(data, inline=True) if inline else None, parse_mode=ParseMode.HTML) update.callback_query.answer() return
def pv(bot, update, groups, lang): data = voca_db.song(groups[0], lang=lang, fields='MainPicture, Names, Lyrics, Artists, PVs') inline = bool(update.callback_query.inline_message_id) # TODO: Deal with several of the same service. Ex: 17523 has two YT for pv_info in data['pVs']: if pv_info['service'] == groups[1]: text = '' if inline: text = content_parser(data, info=True, inline=True, bot_name=bot.username) text += '\n\n' + '🎥' text += _('<b>{service} PV for {song} by {artist}</b>\n' 'PV Title:\n{name}\n{url}').format(song=data['name'], artist=data['artistString'], service=pv_info['service'], name=pv_info['name'], url=pv_info['url']) edit_message_text(bot, update, send_if_possible=True, text=text, reply_markup=song_keyboard(data, inline=True) if inline else None, parse_mode=ParseMode.HTML) update.callback_query.answer() return
def song(bot, update, groups, lang): data = voca_db.song(groups[0], 'MainPicture, Names, Lyrics, Artists, PVs', lang=lang) update.message.reply_text(content_parser(data, info=True), reply_markup=song_keyboard(data), parse_mode=ParseMode.HTML, disable_web_page_preview=True)
def song_by_pv(bot, update, lang): for entity in update.message.entities: if entity.type == 'url': pv = pv_parser(update.message.text) if pv: data = voca_db.song_by_pv(pv[0], pv[1], 'MainPicture, Names, Lyrics, Artists, PVs', lang=lang) update.message.reply_text(content_parser(data, info=True), reply_markup=song_keyboard(data), parse_mode=ParseMode.HTML, disable_web_page_preview=True)
def album(bot, update, groups, lang): data = voca_db.album(groups[0], 'MainPicture, Names, Discs, Tracks', lang=lang) update.message.reply_text(content_parser(data, info=True), reply_markup=album_keyboard(data), parse_mode=ParseMode.HTML, disable_web_page_preview=True)
def lyrics(bot, update, groups, lang): data = voca_db.song(groups[0], lang=lang, fields='MainPicture, Names, Lyrics, Artists, PVs') reply_keyboard = InlineKeyboardMarkup([[ InlineKeyboardButton(get_lyric_lang(lyric['translationType'], lyric['cultureCode']), callback_data='ly|{}|{}'.format( data['id'], lyric['id'])) for lyric in data['lyrics'] ]]) inline = bool(update.callback_query.inline_message_id) if data['lyrics']: if groups[1] == '': text = _( 'What language would you like the lyrics for <b>{name} by {artist}</b> in?' ).format(name=data['name'], artist=data['artistString']) edit_message_text(bot, update, send_if_possible=True, text=text, reply_markup=reply_keyboard, parse_mode=ParseMode.HTML) update.callback_query.answer() else: for lyric in data['lyrics']: if lyric['id'] == int(groups[1]): text = '' if inline: text = content_parser(data, info=True, inline=True, bot_name=bot.username) text += '\n\n' + '📜' text += _('<b>{lang} lyrics for {song} by {artist}</b>\n' '{lyrics}').format(song=data['name'], artist=data['artistString'], lang=get_lyric_lang( lyric['translationType'], lyric['cultureCode'], long=True), lyrics=lyric['value']) edit_message_text( bot, update, text=text, reply_markup=song_keyboard(data, inline=True) if inline else reply_keyboard, parse_mode=ParseMode.HTML) update.callback_query.answer() else: update.callback_query.answer(_('No lyrics found.'))
def answer(bot, update, entries, offset='', switch_pm=None): if not switch_pm: switch_pm = (_('Click for help.'), 'help_inline') results = [] for entry in entries: try: thumb = entry['mainPicture']['urlThumb'] except KeyError: thumb = '' content = content_parser(entry, info=True, inline=True, bot_name=bot.username) if 'songType' in entry: description = _('{artist}\n{type} song').format(artist=entry['artistString'], type=entry['songType']) if 'favoritedTimes' in entry: description += ' ' + _('with {favorites} favourites').format(favorites=entry['favoritedTimes']) results.append(InlineQueryResultArticle( id=uuid4(), title='🎵' + ' ' + entry['name'], description=description, thumb_url=thumb, input_message_content=InputTextMessageContent(content, parse_mode=ParseMode.HTML, disable_web_page_preview=True), reply_markup=song_keyboard(entry, inline=True) )) elif 'artistType' in entry: results.append(InlineQueryResultArticle( id=uuid4(), title='🎤' + ' ' + entry['name'], description='{type}'.format(type=entry['artistType']), thumb_url=thumb, input_message_content=InputTextMessageContent(content, parse_mode=ParseMode.HTML, disable_web_page_preview=True), reply_markup=artist_keyboard(entry, inline=True) )) elif 'discType' in entry: description = '{artist}\n{type}'.format(artist=entry['artistString'], type=entry['discType']) results.append(InlineQueryResultArticle( id=uuid4(), title='💿' + ' ' + entry['name'], description=description, thumb_url=thumb, input_message_content=InputTextMessageContent(content, parse_mode=ParseMode.HTML, disable_web_page_preview=True), reply_markup=album_keyboard(entry, inline=True) )) update.inline_query.answer(results=results, cache_time=INLINE_CACHE_TIME, is_personal=True, next_offset=offset, switch_pm_text=switch_pm[0], switch_pm_parameter=switch_pm[1])
def send_page_one(bot, update, key, page, state): page_data, counts, context = page(1) update.message = (update.message or update.callback_query.message) if counts[1] == 1 and len(page_data) == 1: entry = page_data[0] if 'songType' in entry or 'artistType' in entry or 'discType' in entry: if update.callback_query: update.callback_query.answer() if 'songType' in entry: info.song(bot, update, [entry['id']]) elif 'artistType' in entry: info.artist(bot, update, [entry['id']]) elif 'discType' in entry: info.album(bot, update, [entry['id']]) return None message_id = update.message.message_id if message_id in replies: sent_message = bot.edit_message_text( chat_id=(update.message or update.callback_query.message).chat.id, message_id=replies[message_id][1], text=content_parser(page_data, context=context, counts=counts), reply_markup=keyboard(key, counts), parse_mode=ParseMode.HTML) else: sent_message = bot.send_message( chat_id=(update.message or update.callback_query.message).chat.id, text=content_parser(page_data, context=context, counts=counts), reply_markup=keyboard(key, counts), parse_mode=ParseMode.HTML) replies[message_id] = (state, sent_message.message_id) if update.callback_query: update.callback_query.answer() return BrowseState.page
def song_by_pv(bot, update, lang): for entity in update.message.entities: if entity.type == 'url': pv = pv_parser(update.message.text) if pv: data = voca_db.song_by_pv( pv[0], pv[1], 'MainPicture, Names, Lyrics, Artists, PVs', lang=lang) update.message.reply_text(content_parser(data, info=True), reply_markup=song_keyboard(data), parse_mode=ParseMode.HTML, disable_web_page_preview=True)
def send_page_one(bot, update, key, page, state): page_data, counts, context = page(1) update.message = (update.message or update.callback_query.message) if counts[1] == 1 and len(page_data) == 1: entry = page_data[0] if 'songType' in entry or 'artistType' in entry or 'discType' in entry: if update.callback_query: update.callback_query.answer() if 'songType' in entry: info.song(bot, update, [entry['id']]) elif 'artistType' in entry: info.artist(bot, update, [entry['id']]) elif 'discType' in entry: info.album(bot, update, [entry['id']]) return None message_id = update.message.message_id if message_id in replies: sent_message = bot.edit_message_text(chat_id=(update.message or update.callback_query.message).chat.id, message_id=replies[message_id][1], text=content_parser(page_data, context=context, counts=counts), reply_markup=keyboard(key, counts), parse_mode=ParseMode.HTML) else: sent_message = bot.send_message(chat_id=(update.message or update.callback_query.message).chat.id, text=content_parser(page_data, context=context, counts=counts), reply_markup=keyboard(key, counts), parse_mode=ParseMode.HTML) replies[message_id] = (state, sent_message.message_id) if update.callback_query: update.callback_query.answer() return BrowseState.page
def album_list(bot, update, groups, lang): data = voca_db.album(groups[0], 'MainPicture, Names, Discs, Tracks', lang=lang) inline = bool(update.callback_query.inline_message_id) text = '' if inline: text = content_parser(data, info=True, inline=True, bot_name=bot.username) text += '\n\n' text += album_tracks(data, inline=inline) edit_message_text(bot, update, send_if_possible=True, text=text, reply_markup=album_keyboard(data, inline=True) if inline else None, parse_mode=ParseMode.HTML) update.callback_query.answer()
def next_page(bot, update, groups): key, cur_page = groups[1], groups[2] cur_page = int(cur_page) try: page_data, counts, context = ongoing[key](cur_page) except KeyError: bot.answer_callback_query(callback_query_id=update.callback_query.id, text='Expired! Please start over.') return ConversationHandler.END bot.edit_message_text(chat_id=update.callback_query.message.chat.id, message_id=update.callback_query.message.message_id, text=content_parser(page_data, context=context, counts=counts), reply_markup=keyboard(key, counts), parse_mode=ParseMode.HTML) update.callback_query.answer() return BrowseState.page
def lyrics(bot, update, groups, lang): data = voca_db.song(groups[0], lang=lang, fields='MainPicture, Names, Lyrics, Artists, PVs') reply_keyboard = InlineKeyboardMarkup([ [InlineKeyboardButton(get_lyric_lang(lyric['translationType'], lyric['cultureCode']), callback_data='ly|{}|{}'.format(data['id'], lyric['id'])) for lyric in data['lyrics']]]) inline = bool(update.callback_query.inline_message_id) if data['lyrics']: if groups[1] == '': text = _('What language would you like the lyrics for <b>{name} by {artist}</b> in?').format( name=data['name'], artist=data['artistString']) edit_message_text(bot, update, send_if_possible=True, text=text, reply_markup=reply_keyboard, parse_mode=ParseMode.HTML) update.callback_query.answer() else: for lyric in data['lyrics']: if lyric['id'] == int(groups[1]): text = '' if inline: text = content_parser(data, info=True, inline=True, bot_name=bot.username) text += '\n\n' + '📜' text += _('<b>{lang} lyrics for {song} by {artist}</b>\n' '{lyrics}').format(song=data['name'], artist=data['artistString'], lang=get_lyric_lang(lyric['translationType'], lyric['cultureCode'], long=True), lyrics=lyric['value']) edit_message_text(bot, update, text=text, reply_markup=song_keyboard(data, inline=True) if inline else reply_keyboard, parse_mode=ParseMode.HTML) update.callback_query.answer() else: update.callback_query.answer(_('No lyrics found.'))
def album_list(bot, update, groups, lang): data = voca_db.album(groups[0], 'MainPicture, Names, Discs, Tracks', lang=lang) inline = bool(update.callback_query.inline_message_id) text = '' if inline: text = content_parser(data, info=True, inline=True, bot_name=bot.username) text += '\n\n' text += album_tracks(data, inline=inline) edit_message_text( bot, update, send_if_possible=True, text=text, reply_markup=album_keyboard(data, inline=True) if inline else None, parse_mode=ParseMode.HTML) update.callback_query.answer()
def answer(bot, update, entries, offset='', switch_pm=None): if not switch_pm: switch_pm = (_('Click for help.'), 'help_inline') results = [] for entry in entries: try: thumb = entry['mainPicture']['urlThumb'] except KeyError: thumb = '' content = content_parser(entry, info=True, inline=True, bot_name=bot.username) if 'songType' in entry: description = _('{artist}\n{type} song').format( artist=entry['artistString'], type=entry['songType']) if 'favoritedTimes' in entry: description += ' ' + _('with {favorites} favourites').format( favorites=entry['favoritedTimes']) results.append( InlineQueryResultArticle( id=uuid4(), title='🎵' + ' ' + entry['name'], description=description, thumb_url=thumb, input_message_content=InputTextMessageContent( content, parse_mode=ParseMode.HTML, disable_web_page_preview=True), reply_markup=song_keyboard(entry, inline=True))) elif 'artistType' in entry: results.append( InlineQueryResultArticle( id=uuid4(), title='🎤' + ' ' + entry['name'], description='{type}'.format(type=entry['artistType']), thumb_url=thumb, input_message_content=InputTextMessageContent( content, parse_mode=ParseMode.HTML, disable_web_page_preview=True), reply_markup=artist_keyboard(entry, inline=True))) elif 'discType' in entry: description = '{artist}\n{type}'.format( artist=entry['artistString'], type=entry['discType']) results.append( InlineQueryResultArticle( id=uuid4(), title='💿' + ' ' + entry['name'], description=description, thumb_url=thumb, input_message_content=InputTextMessageContent( content, parse_mode=ParseMode.HTML, disable_web_page_preview=True), reply_markup=album_keyboard(entry, inline=True))) update.inline_query.answer(results=results, cache_time=INLINE_CACHE_TIME, is_personal=True, next_offset=offset, switch_pm_text=switch_pm[0], switch_pm_parameter=switch_pm[1])
def artist(bot, update, groups, lang): data = voca_db.artist(groups[0], 'MainPicture, Names', lang=lang) update.message.reply_text(content_parser(data, info=True), reply_markup=artist_keyboard(data), parse_mode=ParseMode.HTML, disable_web_page_preview=True)