Beispiel #1
0
 def fetch(self, id):
     music_dict = self.db.query_music_by_id(id)
     if music_dict:
         self[id] = dict_to_item(music_dict)
         return self[id]
     else:
         return None
Beispiel #2
0
def cmd_find_tagged(bot, user, text, command, parameter):
    global song_shortlist

    if not parameter:
        bot.send_msg(tr('bad_parameter', command=command), text)
        return

    msgs = [tr('multiple_file_found') + "<ul>"]
    count = 0

    tags = parameter.split(",")
    tags = list(map(lambda t: t.strip(), tags))

    music_dicts = var.music_db.query_music_by_tags(tags)
    song_shortlist = music_dicts

    for i, music_dict in enumerate(music_dicts):
        item = dict_to_item(music_dict)
        count += 1
        if count > ITEMS_PER_PAGE:
            break
        msgs.append("<li><b>{:d}</b> - <b>{}</b> (<i>{}</i>)</li>".format(
            i + 1, item.title, ", ".join(item.tags)))

    if count != 0:
        msgs.append("</ul>")
        if count > ITEMS_PER_PAGE:
            msgs.append(tr("records_omitted"))
        msgs.append(tr("shortlist_instruction"))
        send_multi_lines(bot, msgs, text, "")
    else:
        bot.send_msg(tr("no_file"), text)
Beispiel #3
0
    def get_items_by_tags(self, tags):
        music_dicts = self.db.query_music_by_tags(tags)
        items = []
        if music_dicts:
            for music_dict in music_dicts:
                id = music_dict['id']
                self[id] = dict_to_item(music_dict)
                items.append(self[id])

        return items
Beispiel #4
0
def cmd_play_file_match(bot,
                        user,
                        text,
                        command,
                        parameter,
                        do_not_refresh_cache=False):
    global log

    if parameter:
        file_dicts = var.music_db.query_music(Condition().and_equal(
            'type', 'file'))
        msgs = [tr('multiple_file_added') + "<ul>"]
        try:
            count = 0
            music_wrappers = []
            for file_dict in file_dicts:
                file = file_dict['title']
                match = re.search(parameter, file)
                if match and match[0]:
                    count += 1
                    music_wrapper = get_cached_wrapper(dict_to_item(file_dict),
                                                       user)
                    music_wrappers.append(music_wrapper)
                    log.info("cmd: add to playlist: " +
                             music_wrapper.format_debug_string())
                    msgs.append("<li><b>{}</b> ({})</li>".format(
                        music_wrapper.item().title,
                        file[:match.span()[0]] + "<b style='color:pink'>" +
                        file[match.span()[0]:match.span()[1]] + "</b>" +
                        file[match.span()[1]:]))

            if count != 0:
                msgs.append("</ul>")
                var.playlist.extend(music_wrappers)
                send_multi_lines_in_channel(bot, msgs, "")
            else:
                if do_not_refresh_cache:
                    bot.send_msg(tr("no_file"), text)
                else:
                    var.cache.build_dir_cache()
                    cmd_play_file_match(bot,
                                        user,
                                        text,
                                        command,
                                        parameter,
                                        do_not_refresh_cache=True)

        except re.error as e:
            msg = tr('wrong_pattern', error=str(e))
            bot.send_msg(msg, text)
    else:
        bot.send_msg(tr('bad_parameter', command=command), text)
Beispiel #5
0
def get_cached_wrapper_from_dict(dict_from_db, user):
    if dict_from_db:
        item = dict_to_item(dict_from_db)
        return get_cached_wrapper(item, user)
    return None