antiboredom / videogrep

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

Search issue with spaces #97

Closed albertious closed 2 years ago

albertious commented 2 years ago

Hi I have come across an issue when using regular expression with the --search arg. (at least in OSX)

to explain....

--search "hello" will find all instances of hello

--search "hello|dog|cat|burger" using the '|' vertical bar, it will find all separate instances of hello, dog, cat and burger

--search "hello man" This will find instances of hello man. It can deal with the spaces fine when there is just one phrase.

However the search string does not deal well with spaces when using the '|' in the same search, so --search "hello man|dog|cat|burger" will only return instances of hello man, ignoring the dog, cat, burger.

--search "dog|cat|burger|hello man" will only return instances of ignoring the dog, cat, and burger, this time ignoring hello man

I have tried substituting the space in hello man with various grep and regex tricks { },[ ],[\s],\s,[[:space:]],[:space:], etc. but I haven't found any that work.

Does anyone know a way to use | and spaces in a search?

A.

antiboredom commented 2 years ago

Hi! This is definitely an issue. I'm actually not sure what the best way to resolve it is, and if you have any suggestions I'm very open! In the meantime, the only workaround is to make two supercuts, one with each search query.

https://github.com/antiboredom/videogrep/blob/80fee3b40150814a4159fabc715046777f382584/videogrep/videogrep.py#L143

albertious commented 2 years ago

Hi! This is definitely an issue. I'm actually not sure what the best way to resolve it is, and if you have any suggestions I'm very open! In the meantime, the only workaround is to make two supercuts, one with each search query.

https://github.com/antiboredom/videogrep/blob/80fee3b40150814a4159fabc715046777f382584/videogrep/videogrep.py#L143

ah no worries. the two supercut solution doesn't suit in this instance because I am passing -r. I'll keep trying some stuff and if I have any luck, I'll post the solution here. thanks for getting back to me sam!

albertious commented 2 years ago

do you think there might be a way to pass multiple --search commands which are then appended together? so that the first could be a single phrase with spaces "hello man", and the second with the vertical bars "dog|cat|burger".

currently separating these two types of search with " " doesn't pass, as it thinks dog|cat|burger is a new arg. but maybe there is a way for the .py code to expect multiple " "?

hmmmmm...

antiboredom commented 2 years ago

funny you should ask! I have just been working on implementing that exact idea, and have pushed it to this branch: https://github.com/antiboredom/videogrep/tree/multisearch

It allows you to run videogrep like so:

videogrep --input video.mp4 --search "first search" --search "second search"

(you can add as many --search options as you want)

I want to do a bit more testing before I publish it to pypi, but if you'd like to give it a go you should be able to install it with:

pip install git+https://github.com/antiboredom/videogrep@multisearch
albertious commented 2 years ago

wow. this works perfectly. thanks so much!

I have tested it as follows: videogrep --input video.mp4 --search "multi word string" --search "separate|single|word|searches|using|vertical|bar|characters" and it seems to be working perfectly. fun! :)

btw i had to pip3 the branch to install it (in case anyone else runs into python version issues): pip3 install git+https://github.com/antiboredom/videogrep@multisearch

antiboredom commented 2 years ago

Great - glad to hear! I'll probably release it in the next few days.