emericg / OpenSubtitlesDownload

Automatically find and download the right subtitles for your favorite videos!
https://emeric.io/OpenSubtitlesDownload
GNU General Public License v3.0
579 stars 63 forks source link

Searching by filename breaks when there's a number in the title #84

Closed Huntracony closed 6 months ago

Huntracony commented 2 years ago

When the filename includes the episode's title and that includes a number, it never seems to find any subtitles. Examples: The Americans S03E13 March 8, 1983.mkv The Americans S05E05 Lotus 1-2-3.mkv

(Guess what series I've been watching recently.) The search works fine when you remove the episode titles form the filenames. I also tested a random episode of Babylon 5 to see if numbers in the series name would break it too, but that seemed to work fine.

In case it matters, I'm using Windows CLI. And thanks for the tool! It's been very useful.

Morikko commented 1 year ago

True i confirm this but the problem is on opensubtitles.org.

Example:

I added this custom change as a workaround:

    # ==== Get file hash, size and name
    videoTitle = ''
    videoHash = hashFile(currentVideoPath)
    videoSize = os.path.getsize(currentVideoPath)
    videoFileName = os.path.basename(currentVideoPath)

    # Custom Change: Remove the episode number at the beginning
    # `opensubtitles.org` would not find any result with it.
    # https://github.com/emericg/OpenSubtitlesDownload/issues/84
    # Expectation: The character "-" split the episode number from the title
    if "-" in videoFileName[:5]:
        episode_number , videoFileName = videoFileName.split("-", maxsplit=1)

    # ==== Search for available subtitles

So 01 - My Title would be searched as My Title. The episode number has to be at the beginning and separated by a - in the first 5 characters. Of course, you can adapt the rules to match your naming preference.

emericg commented 6 months ago

This doesn't happen anymore with the "new" provider opensubtitles.com