kelciour / movies2anki

Convert movies with subtitles to watch them with Anki. Inspired by subs2srs
GNU Affero General Public License v3.0
302 stars 28 forks source link

The add-on overrides the aid and alang specified in an MPV conf file. #27

Closed aleksejrs closed 6 months ago

aleksejrs commented 6 months ago

movies2anki's config contains:

"preferred languages": "english",

The .conf file loaded by MPV contains:

sid=3
aid=2
alang=eng

MPV output:

 (+) Audio --aid=1 (*) 'español' (ac3 6ch 48000Hz)
     Audio --aid=2 'english' (ac3 6ch 48000Hz)
     Subs  --sid=1 (*) 'español forzado' (subrip)
     Subs  --sid=2 'español' (subrip)
 (+) Subs  --sid=3 'english' (subrip)
     Subs  --sid=4 --slang=mkv

A random older version from this year's backup plays the English stream.

kelciour commented 6 months ago

If the issue was caused by generating mobile cards, I've updated the add-on and it should be fixed now.

If this mpv output is from the add-on, i.e. while generating mobile cards or reviewing some cards with the add-on, I guess, the first audio stream was selected while generating a new deck of cards. The add-on remembered it ('español') and reused later. Before the update, it could be checked in the Tools > Add-ons > ... > Config and under the ~media key. If this key is deleted, the add-on will use --aid=auto and mpv should behave as it did in the past, i.e. use mpv.conf for automatic audio stream selection.

Now, while making a new deck of cards, the add-on will try to automatically select the preferred audio stream and remember it.

Once the deck is made, the add-on will remember the selected audio stream and will use it for the cards with the same prefix during review or while generating mobile cards. It was stored in the Tools > Add-ons > Config under the ~media key, but it will be moved to 'user_files/media.db' after today's update.

Maybe the add-on was updated too soon, but it seemed to work fine for me after a bit of testing.

aleksejrs commented 6 months ago

I think the cards were added on 2021-07-10. There are no mobile files for them.

kelciour commented 6 months ago

I see. The "preferred languages" wasn't meant to be used with the decks that were already generated. The "preferred languages" was only used in the add-on's main window to automatically select the preferred audio stream (and the subtitle file) before generating a new deck of cards.

I'll update the add-on maybe a few days later and change its behaviour. During review, if the deck was generated some time ago, if no media was generated and the 'audio_id' value couldn't be found in the media database, the "preferred languages" will be passed to mpv as the alang option.


As of now, if the audio id was wrongly selected, it can be fixed either by making a new deck of cards with the correct audio stream using the same video file (and remove the deck later) or manually edit user_files/media.db in the add-on's folder and add a new entry with the "path" and "audio_id", and restarting Anki to reload the media database.

{
    "The.Matrix.1999.HDDVDRip_x264_cw": {
        "path": "C:/Torrent/The Matrix Trilogy/The.Matrix.(1999).HDDVDRip_x264_cw.mkv",
        "audio_id": 2
    },
    "DragsterPS_Pok\u00e9mon_Indigo_League_E01_1080p_Multi-Audio_Multi-Subs_4746B581": {
        "path": "G:/Torrent/[DragsterPS] Pok\u00e9mon Indigo League [1080p] [Multi-Audio] [Multi-Subs] [v2]/[DragsterPS] Pok\u00e9mon Indigo League E01 [1080p] [Multi-Audio] [Multi-Subs] [4746B581].mkv",
        "audio_id": 1
    }
}

If the path can't be found in the media database, specifying the 'aid' or 'alang' in the mpv.conf file should work as it did in the past. Maybe mpv doesn't read the 'mpv.conf' for some reason. It can be tested by modifying player.py and adding the second line with the log-file, opening Anki and reviewing a card, then opening mpv.conf and searching for mpv.conf.

        default_args += ["--sub-visibility=no", "--no-resume-playback", "--save-position-on-quit=no"]
        default_args += ["--log-file=~/Desktop/mpv.anki.log.txt"]

In my case, I installed mpv via scoop and mpv looked at 'C:/Users/N/scoop/apps/mpv-git/current/portable_config/mpv.conf'.

aleksejrs commented 6 months ago

manually edit user_files/media.db in the add-on's folder and add a new entry with the "path" and "audio_id", and restarting Anki to reload the media database.

This worked, thanks. I suppose adding a temporary deck would do the same.

If the path can't be found in the media database, specifying the 'aid' or 'alang' in the mpv.conf file should work as it did in the past. Maybe mpv doesn't read the 'mpv.conf' for some reason.

MPV started by Anki says it's Loading config, the file near the video (I have the dangerous use-filedir-conf=yes option in ~/.config/mpv/config for that user).

It can be tested by modifying player.py and adding the second line with the log-file, opening Anki and reviewing a card, then opening mpv.conf and searching for mpv.conf.

kelciour commented 6 months ago

No idea why the recent update broke it, but the "preferred languages" option will be now passed to mpv as alang option and it should help with old decks that were made before the update. If it doesn't help, Tools > Check Media can be used to update the media database with the correct audio id if it was missing, a new window will appear, and then the encoding of mobile media files can be canceled if it's not needed.