Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mp3 file not found when generating deck #54

Open
anawfulfeeling opened this issue Dec 28, 2023 · 2 comments
Open

mp3 file not found when generating deck #54

anawfulfeeling opened this issue Dec 28, 2023 · 2 comments

Comments

@anawfulfeeling
Copy link

After having some initial problems with ffmpeg not being found on Mac (the addon doesn't check /opt/homebrew/bin/ffmpeg where ffmpeg will be installed using Brew), I was unable to run the addon using the following video: https://www.youtube.com/watch?v=mapbKTJ9aBs

Error log below:

Error 
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed. 
If the issue only occurs when add-ons are enabled, please use the Tools>Add-ons menu item to disable some add-ons and restart Anki, repeat until you discover the add-on that is causing the problem. 
When you've discovered the add-on that is causing the problem, please report the issue on the add-ons section of our support site. 
Debug info:
Anki 2.1.65 (aa9a734f) Python 3.9.15 Qt 6.5.0 PyQt 6.5.0
Platform: macOS-14.0-arm64-arm-64bit
Flags: frz=True ao=True sv=3
Add-ons, last update check: 2023-12-28 12:00:30
Add-ons possibly involved: ⁨Youtube to Anki⁩

Caught exception:
Traceback (most recent call last):
  File "/Users/anawfulfeeling/Library/Application Support/Anki2/addons21/964531817/worker.py", line 166, in add_card
    audiofname = mw.col.media.addFile(subtitle_range.audio_path)
  File "anki.media", line 94, in add_file
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/5z/kwxwbktd1w9_jn75jrs99fvm0000gp/T/How to Use じゃない - ja-orig_                  1900-01-01 00_00_00_240000_                  3_429.mp3'

Caught exception:
Traceback (most recent call last):
  File "/Users/anawfulfeeling/Library/Application Support/Anki2/addons21/964531817/worker.py", line 166, in add_card
    audiofname = mw.col.media.addFile(subtitle_range.audio_path)
  File "anki.media", line 94, in add_file
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/5z/kwxwbktd1w9_jn75jrs99fvm0000gp/T/How to Use じゃない - ja-orig_                  1900-01-01 00_00_03_679000_                  3_311.mp3'

Caught exception:
Traceback (most recent call last):
  File "/Users/anawfulfeeling/Library/Application Support/Anki2/addons21/964531817/worker.py", line 166, in add_card
    audiofname = mw.col.media.addFile(subtitle_range.audio_path)
  File "anki.media", line 94, in add_file
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/5z/kwxwbktd1w9_jn75jrs99fvm0000gp/T/How to Use じゃない - ja-orig_                  1900-01-01 00_00_06_990000_                  0_01.mp3'

@anawfulfeeling anawfulfeeling changed the title Directories not found during deck creation mp3 file not found when generating deck Dec 28, 2023
@anawfulfeeling
Copy link
Author

I tried another video and hit the same error: https://www.youtube.com/watch?v=r0io_xgmcSs

@cnra
Copy link

cnra commented Jul 3, 2024

Probably caused by invalid characters like ":" in title.

Sanitazing filename in ffmpeg.py could solve the issue:

import re

class Ffmpeg:
    def __init__(self, subtitle, video_path, video_title):
        self.time_diff = (subtitle.time_end - subtitle.time_start).total_seconds()
        sanitized_title = re.sub(r'[^\w_ -]', '_', video_title)
        media_path_prefix = Path(tempfile.gettempdir()).joinpath(
            f"{sanitized_title}_\
                  {str(subtitle.time_start).replace('.','_').replace(':','_')}_\
                  {str(self.time_diff).replace('.','_').replace(':','_')}",
        )

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

No branches or pull requests

2 participants