Skip to content

Update currently selected cards in Anki#134

Merged
tatsumoto-ren merged 13 commits intoAjatt-Tools:masterfrom
fntenjr:master
Mar 29, 2025
Merged

Update currently selected cards in Anki#134
tatsumoto-ren merged 13 commits intoAjatt-Tools:masterfrom
fntenjr:master

Conversation

@fntenjr
Copy link
Copy Markdown
Contributor

@fntenjr fntenjr commented Mar 12, 2025

for #133

@tatsumoto-ren
Copy link
Copy Markdown
Member

This repo doesn't use tabs to indent code.

@fntenjr
Copy link
Copy Markdown
Contributor Author

fntenjr commented Mar 13, 2025

My bad, should be good now.

@tatsumoto-ren
Copy link
Copy Markdown
Member

rebased against master.

@emiham
Copy link
Copy Markdown
Contributor

emiham commented Mar 17, 2025

If you update multiple notes you will only see the output from the last one added on the OSD. This is especially bad if there's an error adding a note that's not the last one.

Also all modified notes should be opened in Anki, not just the last one.

@tatsumoto-ren
Copy link
Copy Markdown
Member

Yeah, I think only one card should be updated at a time. If you have multiple cards with the same sentence (and the same audio recording), that's typically a bad practice.

@fntenjr
Copy link
Copy Markdown
Contributor Author

fntenjr commented Mar 17, 2025

If you update multiple notes you will only see the output from the last one added on the OSD. This is especially bad if there's an error adding a note that's not the last one.

Also all modified notes should be opened in Anki, not just the last one.

It was really due to how ankiconnect.append_media works, but I have a solution. Displaying all noteids is confusing in my opinion, so I made it that just the number of cards that were updated is displayed, errors still work.

Yeah, I think only one card should be updated at a time. If you have multiple cards with the same sentence (and the same audio recording), that's typically a bad practice.

Yes, I considered that first but I wanted the functionality to match the "update last notes" functionality, which allows it. I'll set config.card_overwrite_safeguard to 1 by default. Users still can change it, but can be discouraged with documentation.

@emiham
Copy link
Copy Markdown
Contributor

emiham commented Mar 17, 2025

If you have multiple cards with the same sentence (and the same audio recording), that's typically a bad practice.

This is generally fine for vocab cards. I realize you don't like them, but people are going to want to make them anyway. Discouraging is fine, removing the option seems like a bit much.

I'll set config.card_overwrite_safeguard to 1 by default. Users still can change it, but can be discouraged with documentation.

I think this strikes the right balance.

Displaying all noteids is confusing in my opinion, so I made it that just the number of cards that were updated is displayed, errors still work.

Agreed, there's no value in seeing the IDs, so this is perfect.

ankiconnect.lua Outdated
end

self.append_media = function(note_id, fields, create_media_fn, tag)
self.append_media = function(note_id, fields, create_media_fn, tag, quiet_on_success)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be cleaner to have this function return an error if encountered, and have the caller handle printing. You could then print things like "updated 3 cards, 1 error.: ...".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this function runs curl request asynchronously, so we either gotta wait or do this. I chose not to fiddle and change too much

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, that's probably too big of a rewrite for a small feature like this.

ankiconnect.lua Outdated
self.gui_browse(string.format("nid:%s", note_id)) -- select the updated note in the card browser
h.notify(string.format("Note #%s updated.", note_id))
if not quiet_on_success then
self.gui_browse(string.format("nid:%s", note_id)) -- select the updated note in the card browser
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the caller handles printing it could also handle this. It already does for multiple cards right now, so this could be consolidated to one block of code in one file.

@fntenjr
Copy link
Copy Markdown
Contributor Author

fntenjr commented Mar 17, 2025

I cooked this special branch https://github.com/fulltimebaka/mpvacious/tree/synchronous-updating try and see if you like it

@emiham
Copy link
Copy Markdown
Contributor

emiham commented Mar 19, 2025

I think it looks sensible, but it might be out of scope for this PR after all. There's probably a bigger refactor it could be part of, so for now it maybe makes sense to just go with the workaround. But let's see what @tatsumoto-ren thinks.

@emiham
Copy link
Copy Markdown
Contributor

emiham commented Mar 24, 2025

I just realized that we should probably not overwrite the sentence/sentence translation fields when updating a note. They could be from something completely unrelated, so they should be merged unless explicitly overwritten.

don't run the same code multiple times
@tatsumoto-ren
Copy link
Copy Markdown
Member

I just realized that we should probably not overwrite the sentence/sentence translation fields when updating a note. They could be from something completely unrelated, so they should be merged unless explicitly overwritten.

Could you link the code block that needs to be changed?

forvo.set_output_dir(anki_media_dir)
new_data = forvo.append(new_data, stored_data)
new_data = update_sentence(new_data, stored_data)
if not overwrite then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join_media_fields should also join sentences if you're not overwriting.

This would also require a separator between merged fields (e.g. a newline).

We could also check if the fields are equal (or equal to the data between separators), in which case they can be skipped. I think this is only marginally useful, but I don't think it would hurt either.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, add sentence_field and secondary_field to the list?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and also change this to something like (I haven't actually run this so please test it):

if not h.is_empty(field) and not string.match(h.table_get(stored_data, field, ""), h.table_get(new_data, field, "")) then
    new_data[field] = h.table_get(stored_data, field, "") .. "\n" .. h.table_get(new_data, field, "")
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this can be proposed in a different PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants