Beispiel #1
0
def albumy():
    albums = lib.albums()
    for album in albums:
        album.load()
    local_repo.annex_direct()
    alb_sort_album = beetsCommands.pack_albums_items(sorted(albums, key=lambda x: x.album))
    alb_sort_artist = beetsCommands.pack_albums_items(sorted(albums, key=lambda x: x.albumartist))
    alb_sort_year = beetsCommands.pack_albums_items(sorted(albums, key=lambda x: x.year))
    local_repo.annex_indirect()
    return render_template('albums.html', reload="no", albums=alb_sort_album, artists=alb_sort_artist,
                           years=alb_sort_year)
Beispiel #2
0
def details():
    polish = dictionary.polish()
    dict = dictionary.dictionary(polish)
    albums_id = request.args.getlist('id', type=int)
    action = request.args.getlist('action', type=str)
    expand = request.args.get('expand', type=str)
    saved = request.args.get('remotes', type=str)
    albums = []
    id_arg = ''
    local_repo.get_remotes()
    print("example" + str(local_repo.get_remotes()))
    if saved == 'saved':
        if request.method == 'POST':
            for album_id in albums_id:
                album_dir = beetsCommands.path_to_str(lib.get_album(album_id).item_dir())
                album_dir = album_dir[len(beetsCommands.get_library()) + 1:]
                postvars = variabledecode.variable_decode(request.form, dict_char='_')
                keys = postvars.keys()
                for repo in local_repo.remotes:
                    if repo.name not in keys:
                        local_repo.annex_sync(repo)
                        repo.annex_sync(local_repo)
                        repo.annex_drop(album_dir)
                        repo.annex_sync(local_repo)
                        local_repo.annex_sync(repo)
                    else:
                        local_repo.annex_sync(repo)
                        repo.annex_sync(local_repo)
                        repo.annex_get(local_repo, album_dir)
                        repo.annex_sync(local_repo)
                        local_repo.annex_sync(repo)

                if 'YAMO' not in postvars.keys():
                    local_repo.annex_drop(album_dir)
                else:
                    local_repo.annex_get_from_all(album_dir)

    remote_names = local_repo.remote_names
    remotes_send = []
    for album_id in albums_id:
        if id_arg != '':
            id_arg = id_arg + '&'
        id_arg = id_arg + 'id=' + str(album_id)
        albums.append(lib.get_album(album_id))
        items = albums[-1].items()
        album_dir = beetsCommands.path_to_str(beetsCommands.path_to_str(items[0].path))
        if album_dir:
            album_dir = album_dir[len(beetsCommands.get_library()) + 1:]
            remotes_send.append(local_repo.annex_whereis(album_dir))

    if 'YAMO' not in remote_names:
        remote_names.append('YAMO')

    remote_names_copy = []
    for name in remote_names:
        if name not in remotes_send[0]:
            remote_names_copy.append(name)
    remotes_send.append(remote_names_copy)

    local_repo.annex_direct()
    details = beetsCommands.pack_albums_items(albums)
    local_repo.annex_indirect()

    if expand == 'true':
        if 'edit' in action:
            return edit_data(id_arg, dict, expand, remotes_send)
        else:
            return render_template('expandeddetails.html', details=details, dictionary=dict, id_arg=id_arg,
                                   expanded=expand, remotes=remotes_send)

    polish_short = dictionary.PolishShort()
    dict_short = dictionary.dictionary(polish_short)
    if 'edit' in action:
        return edit_data(id_arg, dict_short, expand, remotes_send)
    print(remotes_send)

    return render_template('expandeddetails.html', details=details, dictionary=dict_short, id_arg=id_arg,
                           expanded=expand, remotes=remotes_send)
Beispiel #3
0
def edit_data(id_arg, dict, expand, remotes_send):
    if request.method == 'POST':

        postvars = variabledecode.variable_decode(request.form, dict_char='_')
        albums_id = []
        items_id = []
        albums_newdata = []
        items_newdata = []
        items_id_grouped = []  # used to help count number of items
        album_keys_number = len(dict.language_album)
        item_keys_number = len(dict.language_item)
        while (len(albums_id) * album_keys_number + len(items_id_grouped) * item_keys_number) != len(postvars):
            albums_number = len(albums_id)
            album_keys_number = len(dict.language_album)
            item_keys_number = len(dict.language_item)
            current_len = albums_number * album_keys_number + len(items_id_grouped) * item_keys_number
            album_newdata = []
            for k in range(0, album_keys_number):
                album_newdata.append(postvars.get(str(current_len + k)))
            albums_newdata.append(album_newdata)
            albums_id.append(int(album_newdata[6]))
            album = lib.get_album(albums_id[-1])

            album_items_id = []
            for item in album.items():
                album_items_id.append(item.id)
                items_id_grouped.append(item.id)
            items_id.append(album_items_id)
            album_items_newdata = []
            for k in range(0, len(album_items_id)):
                item_newdata = []
                for j in range(0, item_keys_number):
                    item_newdata.append(postvars.get(str(albums_number * album_keys_number + (
                            len(items_id_grouped) - len(
                        album_items_id)) * item_keys_number + album_keys_number + k * item_keys_number + j)))

                album_items_newdata.append(item_newdata)
            items_newdata.append(album_items_newdata)
        local_repo.annex_direct()  # git annex direct mode, so beet can modify files

        albums = []
        items = []
        for a, album_id in enumerate(albums_id):
            albums.append(lib.get_album(album_id))  # getting single album
            for k in range(len(dict.language_album)):
                album_key = dict.album_keys[k]
                if albums[a][album_key] == None:
                    pass
                elif album_key == 'id' or album_key == 'artpath':
                    pass
                elif album_key == 'year':
                    if int(albums_newdata[a][k]) < 10000:
                        albums[a][album_key] = int(albums_newdata[a][k])
                    else:
                        pass

                else:
                    albums[a][album_key] = str(albums_newdata[a][k])

            for i, item_id in enumerate(items_id[a]):
                item = lib.get_item(item_id)
                items.append(item)
                for k in range(len(dict.language_item)):
                    item_key = dict.item_keys[k]
                    if item_key == 'id' or item_key == 'path':
                        pass
                    elif item_key == 'album_id':
                        if int(items_newdata[a][i][k]) in albums_id:
                            item[item_key] = int(items_newdata[a][i][k])
                        else:
                            pass
                    elif item_key == 'disc' or item_key == 'track':
                        if int(items_newdata[a][i][k]) < 100:
                            item[item_key] = int(items_newdata[a][i][k])
                        else:
                            pass
                    else:
                        item[item_key] = str(items_newdata[a][i][k])
                        item['comments'] = 'edited'
                item.try_sync(write=1, move=0)
            albums[a].try_sync(write=True, move=False)
        local_repo.annex_indirect()  # commits changes and goes back to indirect mode

        local_repo.annex_direct()
        details = beetsCommands.pack_albums_items(albums)
        local_repo.annex_indirect()

        return render_template('expandeddetails.html', details=details, dictionary=dict, id_arg=id_arg, expanded=expand,
                               remotes=remotes_send)