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

Subtitle file detection in same directory broken in Windows #109

Closed
seanson opened this issue Jul 12, 2022 · 1 comment · Fixed by #110
Closed

Subtitle file detection in same directory broken in Windows #109

seanson opened this issue Jul 12, 2022 · 1 comment · Fixed by #110

Comments

@seanson
Copy link
Contributor

seanson commented Jul 12, 2022

When running on a file in the same directory in Windows, the os.path.dirname returns '', which fails with os.scandir raising the error FileNotFoundError: [WinError 3] The system cannot find the path specified: ''

videogrep --version
2.1.1

Working in subdirectory:

videogrep --input tests\test_inputs\manifesto.mp4 --ngrams 1
the 20
of 12
in 7

Failing in same directory:

videogrep --input manifesto.mp4 --ngrams 1
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\Scripts\videogrep.exe\__main__.py", line 7, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\videogrep\cli.py", line 119, in main
    grams = get_ngrams(args.inputfile, args.ngrams)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\videogrep\videogrep.py", line 98, in get_ngrams
    transcript = parse_transcript(file)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\videogrep\videogrep.py", line 61, in parse_transcript
    subfile = find_transcript(videoname, prefer)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\videogrep\videogrep.py", line 32, in find_transcript
    all_files = [f.path for f in os.scandir(os.path.dirname(videoname)) if f.is_file()]
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''
seanson added a commit to seanson/videogrep that referenced this issue Jul 12, 2022
Fixes antiboredom#109

This swaps out the os.path methods for using pathlib instead in the subtitle
detection function and test path generation. This helps mitigate Windows'
weird behaviour with dirname returns on files in the same directory.
@hasanbanna
Copy link

I get the same issue on macos.

videogrep --input meta.mp4 --search 'experience'                                                                                                                                  
Traceback (most recent call last):
  File "/opt/homebrew/bin/videogrep", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.9/site-packages/videogrep/cli.py", line 146, in main
    videogrep(
  File "/opt/homebrew/lib/python3.9/site-packages/videogrep/videogrep.py", line 472, in videogrep
    segments = search(files, query, search_type)
  File "/opt/homebrew/lib/python3.9/site-packages/videogrep/videogrep.py", line 207, in search
    transcript = parse_transcript(file, prefer=prefer)
  File "/opt/homebrew/lib/python3.9/site-packages/videogrep/videogrep.py", line 61, in parse_transcript
    subfile = find_transcript(videoname, prefer)
  File "/opt/homebrew/lib/python3.9/site-packages/videogrep/videogrep.py", line 32, in find_transcript
    all_files = [f.path for f in os.scandir(os.path.dirname(videoname)) if f.is_file()]
FileNotFoundError: [Errno 2] No such file or directory: ''

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 a pull request may close this issue.

2 participants