Open In External Editor, Rename, Duplicate for Image, Audio,Video [Official thread]

If you have a problem with the add-on add-on OpenInExternalEditor,Rename,Duplicate for Image,Audio,Video post in this thread. This way I get notified. If you make a new thread I might miss it.

1 Like

Hello, I’m trying to open a card field in VSCode for Mac by setting the option to ā€œcodeā€ or ā€œcode --waitā€ with no luck. The textfield flashes but nothing happens. The only way it works is if I set ā€œopen -tā€ in the options, but then VSCode doesn’t save back to the field.

I’m running Anki 2.1.28 and VSCode 1.47.3 on MacOS 10.14.6.

Thanks for your help!

The add-on ā€œOpenInExternalEditor,Rename,Duplicate for Image,Audio,Videoā€ is meant to edit image, audio, and video files in an image editor like paint or audio editor like audacity. I would never use VSCode for this.

If you want to edit the html source code in VSCode I would use External Editor, if you want to edit some latex maybe text editor for Latex, the selection or html source (FORK).

You write about ā€œthe optionā€ but my add-on has about 20 different config options so I don’t know what you mean. If you really want to use my add-on here I need more info like the whole config and exact steps you take and how this could work with VSCode.

Sorry I’m already using External Editor, I just posted in the wrong thread!

Hello, I want to edit image on Win10 with its built-in software"Photos" ,
but I can’t find its path, so I can’t add it to add-on’s configuration.
Win10ā€˜s built-in software seems can’t to find their path.
Could you give me some help?
Thanks.

@hrdom: If you google for something like ā€œwindows store app cliā€ you should find guides on how to find their path, see e.g. here.

But that’s not enough. The add-on passes the filename as a command line argument to the binary. But as far as I see app store apps often don’t take command line arguments. So even if you have find the path you might fail. I have no solution for this. I just use regular windows apps that I installed myself like paint .net.

Instead of my add-on maybe also have a look at Image Editor. I have never used this add-on but it seems to be independent from your local apps so that you don’t have the problem of calling an external binary.

1 Like

Thank you.
I’ll have a look and decide to use regular windows apps if it has some problem.

Hello,
I’m using anki version 2.1.5 on Windows 10 and when I am trying to install your addon, it’s says that either the code is invalid, or that it’s not available for my version.
Is there a way to make it work ?
Thanks.

@benten: My add-on depends on features that were introduced in Anki 2.1.15. So 2.1.5 is too old. As an add-on uploader I can set compatibility info and I set on Ankiweb that only users with 2.1.15 or newer can install it. So you would need a newer Anki version to use my add-on.

Hi, i want to edit video and there is a video editing software on Windows 10, i don’t know if it’s useful.Can you please recommend the software you use or give me some advice?
Thanks in advance.

[Bug report]

The image rename doesn’t handle Cyrillic characters. (Would submit a PR on Github, but it looks like the repo has been removed…) In any case, here’s the exception:

Traceback (most recent call last):
  File "aqt/webview.py", line 526, in handler
  File "aqt/editor.py", line 534, in <lambda>
  File "/Users/alan/Library/Application Support/Anki2/addons21/1560623518/edit_insert_rename_duplicate.py", line 79, in <lambda>
    editor.saveNow(lambda: func(editor, fname, type, field))
  File "/Users/alan/Library/Application Support/Anki2/addons21/1560623518/rename.py", line 154, in rename
    backup_changed_filenames(fname, newfilename)
  File "/Users/alan/Library/Application Support/Anki2/addons21/1560623518/rename.py", line 123, in backup_changed_filenames
    targetfile.write(f"{old}\t{new}")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 52-56: ordinal not in range(128)

[LATER]

I believe this addresses the exception (basically, just open the logging csv file with UTF-8 encoding.)

def backup_changed_filenames(old, new):
    addon_dir_path = os.path.join(os.path.dirname(__file__))
    renamed_file = os.path.join(addon_dir_path, "user_files", "renamed_files.csv")
    with open(renamed_file, "a", encoding='utf-8') as targetfile:
        targetfile.write(f"{old}\t{new}\n")

Also added a newline after each log entry…

@OjisanSeiuchi : Thanks for fixing this bug. I just uploaded a new version to ankiweb. If you find other problems or have other fixes please let me know. I removed the github repo because I often forgot to push changes I made and I figured no repo is better than a dated one (at least as long as you can get my most current version from ankiweb).

@ijgnd No worries - sometimes public repos can be a headache - different coding styles, trust factor, etc. Anyway, thanks for your contributions to the Anki community - really appreciate it. Happy holidays.

There is a bug in rename.py line 106 - I’m sorry I didn’t capture the stack trace; but the fix looks straightforward. The return type of mw.col.backend.find_and_replace() is an OpChangesWithCount and to increment that change count, must access its count property, otherwise the increment assign operator fails. Here’s the entire method for _replace_all_sound_src(): Functioning correctly on macOS/Anki 2.1.48. [LATER] - I guess there’s a similar issue with the corresponding img method, too.

def _replace_all_sound_src(orig_name: str, new_name: str):
    "new_name doesn't have whitespace, dollar sign, nor double quote"
    
    old = f"[sound:{orig_name}"
    new = f"[sound:{new_name}"

    # Compatibility: 2.1.0+
    n = mw.col.findNotes("[sound")

    replaced_cnt = 0
    if anki_point_version >= 28:
        op_chg_cnt = mw.col.backend.find_and_replace(
            nids=n,
            search=old,
            replacement=new,
            regex=False,
            match_case=False,
            field_name=None,
        )
        replaced_cnt += op_chg_cnt.count
    else:
        replaced_cnt += findReplace(col=mw.col, nids=n, src=old, dst=new, regex=False, fold=False)
    return replaced_cnt

@OjisanSeiuchi : Thanks for another fix. I just uploaded a new version. I made a small change so that old anki versions still work and tried to adjust it to the rename image function as you suggested.

I re-added the most recent code of this add-on to github at GitHub - ijgnd/anki21__OpenInExternalEditor_Rename_Duplicate_for_Image_Audio_Video . This should make it easier for you if you have any more improvements.

there’s maybe a problem with renaming in 2.1.55

reported in another thread by @ferophila : Is there an addon to reveal files in a file manger fom editor window? - #12 by ferophila

To narrow it down I posted two questions:

Maybe it’s better to continue in this thread.

Is there a way to mass rename media files using as Input an Anki-field (e.g. sort field)?

1 Like

not with my add-on. You could rename the files with a different tool e.g. using some regular expression and then update your notes in anki with the build-in search&replace feature that also supports regex. I’d certainly make a backup of all my files (and check that it’s complete) before trying this …

Is it possible to have a custom development?
How to contact you on this?
I need to mass re-name audio files.
The add-on should walk through an Anki-Card-Deck (Alternative: selected Anki-Notes in browser) and rename all sound-tags and it’s corresponding files of a selectable anki-destination-field (selection by configuration file)
The new filename should be generated by a special Anki field calld ā€œnewfilenameā€.

Example: if the name of the sound tag and the corresponding filname is:
[sound:hypertts-d9d4315dcdea8dda366681a0e62a7dae5aaa2a7d6752a4f1044493e0.mp3]
and the content of the anki-field ā€œnewfilenameā€ is
ā€œmynewfilenameā€, then it will be processed as follows:

  1. new filename: mynewfilename.mp3
  2. the sound tag of the anki-destination-field will be renamed to:
    [sound:mynewfilename.mp3]

P.S. Best would be a general solution that also works with pictures.

@PulaArenaFighter : Your suggestion sounds useful. But at the moment I don’t have time. There are some coders that offer to write custom add-ons. E.g. in the forum there’s @abdo who can be hired via https://www.fiverr.com/abd_nh . I don’t know him though I already merged some of his code into another add-on of mine that he was paid to make by a third party.

I guess the source code of your proposed add-on will have very little overlap with the source code of my add-on so that maybe it’s more future proof to make it into a standalone add-on.

1 Like