davidde / mpv-autosub

Fully automatic subtitle downloading for the MPV media player
https://mpv.io/
MIT License
295 stars 42 forks source link

Square brackets in file name #3

Closed eqagunn closed 5 years ago

eqagunn commented 5 years ago

If square brackets are present in the filename, subtitles won't get downloaded. Example using subliminal in terminal:

matz@neon:~/Desktop$ subliminal download -l en "Game.of.Thrones.S08E03.720p.WEB.x265-MiNX[eztv].mkv" 1 video collected / 0 video ignored / 0 error Downloaded 0 subtitle

You could replace all occurrences of square brackets in filename string with dashes, and then send it to subliminal:

matz@neon:~/Desktop$ subliminal download -l en "Game.of.Thrones.S08E03.720p.WEB.x265-MiNX-eztv-.mkv" Collecting videos [####################################] 100%
1 video collected / 0 video ignored / 0 error Downloading subtitles [####################################] 100%
Downloaded 1 subtitle

davidde commented 5 years ago

I'm sorry, but I can't reproduce your issue. I have downloaded the same Game of Thrones file, and the subtitle download works flawlessly on my Debian Linux system.

What OS are you on? I have not yet tested this script on anything other than Linux, so maybe it is time to do so ...

eqagunn commented 5 years ago

Hi David.

I was no longer getting the same pattern when I tried to reproduce. I got the completely opposite results. Now it downloaded if square brackets were present, and it didn't if they weren't. Which made no sense so I went to make some deeper testing.

What I was able to realize is the following... When using subliminal in terminal, if the file name given matches the file that actually exists in the working directory, subliminal will look into its title metadata, and if it exists it will look for subtitles based on title name instead of the file name.

The reason I got the opposite results is that I had that file renamed in the meantime. And the reason it wouldn't download the subtitles if the filename was matched with an actual file is because the title of the file was "[removed]".

If I were to copy the filename to another file which doesn't have title metadata set it would downloaded subtitles regardless whether square brackets were present or not.

Or so I thought...

As I was about to submit this reply, I went to test this with another file that had title metadata set to "[removed]" and to my surprise, subtitles were downloaded without a problem.

Which makes my previous observations untrue.

The only conclusion I had is that it had to do something with that specific file I initially encountered problems with. So I ended up pulling it through mkvtoolnix multiplexer without changing any of the values, and the new output didn't have any before-mentioned problems, as expected.

I believe we weren't testing on the same file as mine seems to be a re-encode by torrentgalaxy. Their watermark is present from 2nd to 7th second of the video. If you would like to to test it yourself, you can get it from torrentz2.eu by searching for "[removed]". At the moment, it's the third result from the list. Torrent size is 415 MB. md5sum returns 5499d03c0c96b04ff4861904da8ee81c.

Kind regards and thanks for the script.

davidde commented 5 years ago

Ok, no worries, thanks for the elaborate clarification!

If I understand correctly, there are no further problems, so I'll close this issue.

davidde commented 5 years ago

I ended up testing this file anyway out of curiosity, and it appears the problem stems from the fact it has embedded subtitles that are inactivated by default. Subliminal still detects their presence, and aborts downloading subtitles because they are already present.

Updated the script with a fix and --debug mode, so it should work on the original file now.

eqagunn commented 4 years ago

Nicely done! This greatly increases the effectiveness of the script.

What do you think on using utils.subprocess() like vayan did in order to make the script work out-of-the-box, instead of requiring user to write down his subliminal path?

Another way could be using subliminal = (io.popen('which subliminal'):read("*a")):sub(1, -2) though popen() is system dependent and is not available on all platforms.

davidde commented 4 years ago

Actually, I do use utils.subprocess(), but this has nothing to do with making the subliminal path work without being specified.

Note that vayan's script will only work when you launch mpv from the terminal, since he hardcodes subliminal as executable. The terminal will be able to resolve this to the correct executable, but mpv's subprocess() will not. This means the script will fail when mpv is opened by doubleclicking a movie.

I don't think having to enter the subliminal path once on installation is all that bad. Plus, as you correctly indicate, it would be difficult to automate path retrieval in a cross-platform way. Besides popen() being system dependent, Windows for example does not have the which command, which complicates matters even more.

Thank you for the feedback!

John-Gee commented 3 years ago

Actually I'm finding, in part, the same issue:

subliminal --debug download -l en "1917 (2019) [BLURAY-1080P].mkv"

errors

but

subliminal --debug download -l en "1917 (2019) [BLURAY-1080P.mkv"

or

subliminal --debug download -l en "1917 (2019) [BLURAY-1080P[.mkv"

work just fine, not sure why the closing bracket matters.

a simple addition allows the script to works:

a[#a + 1] = filename:gsub(']', '')

but then we also need a rename on the way out and it works fine!