antiboredom / videogrep

automatic video supercuts with python
https://antiboredom.github.io/videogrep
Other
3.33k stars 257 forks source link

Subtitle file detection in same directory broken in Windows #109

Closed seanson closed 2 years ago

seanson commented 2 years ago

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: ''
hasanbanna commented 2 years ago

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: ''