Example #1
0
def cmd_yt_search(bot, user, text, command, parameter):
    global log, yt_last_result, yt_last_page, song_shortlist
    item_per_page = 5

    if parameter:
        # if next page
        if parameter.startswith("-n"):
            yt_last_page += 1
            if len(yt_last_result) > yt_last_page * item_per_page:
                song_shortlist = [{'type': 'url',
                                   'url': "https://www.youtube.com/watch?v=" + result[0],
                                   'title': result[1]
                                   } for result in yt_last_result[yt_last_page * item_per_page: item_per_page]]
                msg = _yt_format_result(yt_last_result, yt_last_page * item_per_page, item_per_page)
                bot.send_msg(tr('yt_result', result_table=msg), text)
            else:
                bot.send_msg(tr('yt_no_more'), text)

        # if query
        else:
            results = util.youtube_search(parameter)
            if results:
                yt_last_result = results
                yt_last_page = 0
                song_shortlist = [{'type': 'url', 'url': "https://www.youtube.com/watch?v=" + result[0]}
                                  for result in results[0: item_per_page]]
                msg = _yt_format_result(results, 0, item_per_page)
                bot.send_msg(tr('yt_result', result_table=msg), text)
            else:
                bot.send_msg(tr('yt_query_error'), text)
    else:
        bot.send_msg(tr('bad_parameter', command=command), text)
Example #2
0
def cmd_yt_play(bot, user, text, command, parameter):
    global log, yt_last_result, yt_last_page

    if parameter:
        results = util.youtube_search(parameter)
        if results:
            yt_last_result = results
            yt_last_page = 0
            url = "https://www.youtube.com/watch?v=" + yt_last_result[0][0]
            cmd_play_url(bot, user, text, command, url)
        else:
            bot.send_msg(tr('yt_query_error'), text)
    else:
        bot.send_msg(tr('bad_parameter', command=command), text)