Giter VIP home page Giter VIP logo

mpv-autosub's Introduction

  • Cross-platform: Windows, Mac and Linux
  • Multi-language support
  • Subtitle provider login support
  • No hotkeys required: opening a video will automatically trigger subtitles to download
    (Only when the right subtitles are not yet present)

Dependencies

This Lua script uses the Python program subliminal to download subtitles. Make sure you have both installed:  

pip install subliminal

Setup

  1. Copy autosub.lua into:

    OS Path
    Windows [Drive]:\Users\[User]\AppData\Roaming\mpv\scripts\
    Mac/Linux ~/.config/mpv/scripts/
    mkdir ~/.config/mpv/scripts
    cat > ~/.config/mpv/scripts/autosub.lua
    [Paste script contents and CTRL+D]
  2. Specify the correct subliminal location for your system:

    • To determine the correct path, use:

      OS App Command
      Windows Command Prompt where subliminal
      Mac/Linux Terminal which subliminal
    • Copy this path to the subliminal variable at the start of the script:

      local subliminal = '/path/to/your/subliminal'

      On Windows, the backslashes in the path need to be escaped, e.g.:
      C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\Scripts\\subliminal.exe

Customization

  • Optionally change the subtitle languages / ISO codes. Be sure to put your preferred language at the top of the list.
    If necessary, you can manually trigger downloading your first choice language by pressing b,
    or your second choice language by pressing n.
  • Optionally specify the login credentials for your preferred subtitle provider(s), if you have one.
  • If you do not care for the automatic downloading functionality, and only wish to use the hotkeys,
    simply change the auto bool to false.
  • For added convenience, you can specify the locations to exclude from auto-downloading subtitles, or alternatively,
    the only locations that should auto-download subtitles.

This script is under the MIT License, so you are free to modify and adapt this script to your needs:
check out the MPV Lua API for more information.

If you find yourself unable to find the correct subtitles for some niche movies/series, you might be interested in the submod command line tool I've written to manually correct subtitle timing.

Credits

Inspired by selsta's and fullmetalsheep's autosub scripts.

mpv-autosub's People

Contributors

allanlaal avatar cloud11665 avatar davidde avatar fn-ix avatar gdmka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpv-autosub's Issues

Help with Installation

Hi,

I followed the instructions but the subtitles didnt load and when I clicked on 'b', it says no English Subtitles. I'm not sure if there was any mistake while installing both subliminal and autosub. Please help.

Additionally, there is not subliminal.exe as provided in the instructions. The only path I discovered is the one below which I have replaced in the autosub.lua;

'C:\\Users\\_user_\\venv\\Lib\\site-packages\\subliminal'

Issue with Ubuntu 21.10

This is the debug output of mpv, seems like there is a sort of error when the lua script trying to generate the command for subliminal...

 (+) Video --vid=1 (*) (h264 1920x1080 23.976fps)
 (+) Audio --aid=1 --alang=eng (*) (eac3 6ch 48000Hz)
     Subs  --sid=1 --slang=eng (subrip)
     Subs  --sid=2 --slang=eng 'SDH' (subrip)
File tags:
 Title: Chucky - S01E07 - Twice the Grieving Double the Loss
[autosub] Reactivate external subtitle files: 
Track list:
 (+) Video --vid=1 (*) (h264 1920x1080 23.976fps)
 (+) Audio --aid=1 --alang=eng (*) (eac3 6ch 48000Hz)
     Subs  --sid=1 --slang=eng (subrip)
     Subs  --sid=2 --slang=eng 'SDH' (subrip)
[autosub] Subtitle track 1 :
[autosub] { 
[autosub]   "selected": false 
[autosub]   "albumart": false 
[autosub]   "default": false 
[autosub]   "id": 1 
[autosub]   "src-id": 3 
[autosub]   "forced": false 
[autosub]   "type": "sub" 
[autosub]   "hearing-impaired": false 
[autosub]   "codec": "subrip" 
[autosub]   "ff-index": 2 
[autosub]   "external": false 
[autosub]   "visual-impaired": false 
[autosub]   "dependent": false 
[autosub]   "lang": "eng" 
[autosub] }
[autosub]  
[autosub] Subtitle track 2 :
[autosub] { 
[autosub]   "selected": false 
[autosub]   "albumart": false 
[autosub]   "default": false 
[autosub]   "id": 2 
[autosub]   "src-id": 4 
[autosub]   "forced": false 
[autosub]   "codec": "subrip" 
[autosub]   "type": "sub" 
[autosub]   "hearing-impaired": false 
[autosub]   "ff-index": 3 
[autosub]   "title": "SDH" 
[autosub]   "external": false 
[autosub]   "visual-impaired": false 
[autosub]   "dependent": false 
[autosub]   "lang": "eng" 
[autosub] }
[autosub]  
[autosub] No Italian subtitles were detected
[autosub] => Proceeding to download: 
[autosub] Searching Italian subtitles ... 
AO: [pulse] 48000Hz 5.1(side) 6ch float
VO: [gpu] 1920x1080 yuv420p
AV: 00:00:00 / 00:41:05 (0%) A-V:  0.004
[autosub] Usage: subliminal [OPTIONS] COMMAND [ARGS]...
[autosub] Try 'subliminal --help' for help.
[autosub] 
[autosub] Error: No such option: -e
AV: 00:00:01 / 00:41:05 (0%) A-V:  0.002
[autosub] No Italian subtitles found
[autosub]  
[autosub] No subtitles were found 
AV: 00:00:02 / 00:41:05 (0%) A-V:  0.000

Exiting... (Quit)

[autosub] Usage: subliminal [OPTIONS] COMMAND [ARGS]...
[autosub] Try 'subliminal --help' for help.
[autosub]
[autosub] Error: No such option: -e

Dealing with streams

In reference to #8 (comment), for http streams (e. g. from webtorrent-cli), subliminal’s output directory should be a directory on the user’s filesystem. Maybe the script should default to an actual path (like .config/mpv/autosubs) instead of the variable directory and pass it on to the mpv option sub-file-paths.

Autosub fails to find subtitles when playing videos from URL in MPV, but succeeds when playing downloaded files

Most of the time, when I use services like Seedr to paste a video URL and play it in MPV, the autosub script doesn't find subtitles. However, if I download the same video file to my disk and play it, autosub is able to find subtitles.

To illustrate, let's take the example of playing a movie from YouTube by pasting its URL (e.g., https://www.youtube.com/watch?v=DOZQ_9Ga-bE) in MPV. When I do this, autosub fails to find subtitles. However, if I download the video with the same title and play it using MPV, autosub successfully finds subtitles. This is just an example.

image

The issue seems to be that autosub relies on finding a location on disk to save the subtitles. If it can't locate this location, it reports "no subtitles." (I really don't know the real reason btw, just a guess)

I'm wondering if there's a way to incorporate subtitles directly, similar to the code snippet below, when playing a streamed video (URL) in MPV without being have to save subtitles to disk and instead paste it from URL like below.

function suPaste ()
	local clipboard = get_clipboard()
	mp.commandv("sub_add", clipboard)
	mp.osd_message('Pasted subtitle!')
end

No subtitles were found

It worked on file named "Interstellar.2014.720p.BluRay.x264.YIFY.mkv" but failed on most of the files.
For example "Game.of.Thrones.S01E01.720p.BluRay.450MB.ShAaNiG.com" didn't worked, tried changing to "Game of Thrones S01E01" and "Game of Thrones S1E1". Added opensubtitles and addic7ed credentials still not working.

Alternative Subtitle

Hi, when it downloads wrong subtitle or unsynchronized subtitle, pressing "b" again to download alternative subtitle (of the same language) would be great, if you consider.

can't find the downloaded subtitles

im new to github so i wasn't sure if i should ask this here, as i said in the title, i don't know where the subtitles are located, i thoguht they would be in the same directory where the video file is but it isn't

can't override subtitle track with local mpv.conf

I sometimes use a directory-local mpv.conf (use-filedir-conf) to force a subtitle track, in this case the local mpv.conf contains sid=2. Without mpv-autosub it works but when the plugin is loaded the default (or the first?) track is always selected.

Is it possible to have the plugin respect the configuration?

mpv log
[autosub] Reactivate external subtitle files:
Track list:
 (+) Video --vid=1 (*) (hevc 1920x1080 23.976fps)
     Video --vid=2 [P] 'cover.jpg' (mjpeg)
     Audio --aid=1 --alang=eng (*) 'Stereo - ENG (AAC)' (aac 2ch 48000Hz)
 (+) Audio --aid=2 --alang=jpn 'Stereo - JPN (AAC)' (aac 2ch 48000Hz)
     Subs  --sid=1 --slang=eng (*) 'Signs - ENG (ASS)' (ass)
 (+) Subs  --sid=2 --slang=eng 'Dialog - ENG (ASS)' (ass)
[autosub] No German subtitles were detected
[autosub] => Proceeding to download:
[autosub] Searching German subtitles ...
AO: [pulse] 48000Hz stereo 2ch float
VO: [gpu] 1920x1080 yuv420p10
[autosub] No German subtitles found
[autosub]
Track switched:
 (+) Video --vid=1 (*) (hevc 1920x1080 23.976fps)
     Video --vid=2 [P] 'cover.jpg' (mjpeg)
     Audio --aid=1 --alang=eng (*) 'Stereo - ENG (AAC)' (aac 2ch 48000Hz)
 (+) Audio --aid=2 --alang=jpn 'Stereo - JPN (AAC)' (aac 2ch 48000Hz)
 (+) Subs  --sid=1 --slang=eng (*) 'Signs - ENG (ASS)' (ass)
     Subs  --sid=2 --slang=eng 'Dialog - ENG (ASS)' (ass)
[autosub] Enabled English embedded subtitles!
[autosub] => NOT downloading new subtitles

[question] multiple languages + opensubtitles user pass argument?

Hi,

I'm not at all good at scripting/programming ;) maybe i'm missing something, but how can I use multiple languages in your script? I would like to have polish and english and script would download either or both. Then I would like to have it imported both or one.

Also, how to modify command line argument for subliminal to include --opensubtitles USER PASS ?

Thanks and sorry for n00bish questions....

not work at all

tried to do all the steps but not got to work
i replaced the location the subliminal after knowning where it was by cmd "where subliminal"
local subliminal = '/home/david/.local/bin/subliminal' >>> local subliminal = 'C:\Python34\Scripts\subliminal.exe'
then saved tried the scrtipt but it even says no key binding for "b" or"n"
soo what do i do
note thet other scrtipts works fine

Wrong subtitles downloaded

Hey,

At the beginning I wanted to say thank you for this incredible plugin <3

I am using this for a while and I see some problem, sometimes and I don't really know what is condition plugin just download wrong subtitles. So before I had english and polsih subtitles, but I didn't like it much so I commented polish one:

local languages = {
--          If subtitles are found for the first language,
--          other languages will NOT be downloaded,
--          so put your preferred language first:
            { 'English', 'en', 'eng' },
--          { 'Dutch', 'nl', 'dut' },
--          { 'Spanish', 'es', 'spa' },
--          { 'French', 'fr', 'fre' },
--          { 'German', 'de', 'ger' },
--          { 'Italian', 'it', 'ita' },
--          { 'Portuguese', 'pt', 'por' },
--          { 'Polish', 'pl', 'pol' },
--          { 'Russian', 'ru', 'rus' },
--          { 'Chinese', 'zh', 'chi' },
--          { 'Arabic', 'ar', 'ara' },
}

But it still for some movies to download polish ones, which is strange, it not listed on the opensubtitles. Because I put in config my credentials when I log in I can see my last downloaded subs and it never is listed, so idk where those wrong subs are but definitely not from opensubtitles because on that page I can find the English version ..

--

now I found a file where subs are downloaded with wrong way
so after a while, it downloads and calls it English one, also file name is ...en.srt (but this is actually the same I guess)
I simply change debug = true and open mpv by terminal, here is output: https://termbin.com/8cuv

Any tip is welcome!

Error error

Hello! :)

I get a "Subtitles ready!" message even when no subtitles where downloaded. Not a big deal, but it would be nice if it was fixed.

Thank you for the script!

disabling my subtitle

without this script mpv loads subtitles and everything is ok when i add this to script folder i can download new subs but previous subs cant get detected nor added

Peerflix

Referencing: noctuid/mpv-peerflix-hook#3

  • peerflix does not display the file title properly (usually http://localhost:8888 or magnet link in mpv-peerflix-hook's case), thus making it impossible for autosub to download subs for said file.
  • --force-media-title can be used to mitigate this, but autosub does not seem to use this forced media title. which outside of this use case, can be very helpful with other files and their subs.
  • peerflix/mpv-peerflix-hook store the file in /tmp/torrent-stream, but mpv uses http://localhost:NNNN to stream the file, how can one include these in local includes array to automatically get subs?

Needs function to download alternate subs if first file is no good

Sometimes this script will download subs that are bad, for instance I have this movie, white snake, and the downloaded sub for it is
White.Snake.2019.1080p.BluRay.x264.AAC5.1-[YTS.LT].en.srt

It's (entire) content:

`1
00:00:30,000 --> 00:00:36,000
Provided by YTS.LT

2
00:00:36,500 --> 00:00:42,000
Find the official YIFY movies site at
https://YTS.LT

3
00:30:30,000 --> 00:30:36,000
Downloaded from YTS.LT

4
01:00:30,000 --> 01:00:36,000
Download more movies for free
from YTS.LT
`

Nevermind being a mistimed subtitle file, it's just not a real subtitle at all.

I'd like to have the ability to press a key that makes it look for an alternative subtitle file instead of the one it first downloaded.

Additionally or perhaps alternatively(?) an automated feature that checks if the filesize of the subtitle file is at least over 1kb and rejects the file if it isn't to prevent this specific scenario might be nice.

Name Collision

Instead of overwriting files, append .num to the file name. Ex:
naked.lunch.1991.en.srt => naked.lunch.1991.en.1.srt & naked.lunch.1991.en.2.srt. (also, check if there are already numbered subs.)
This works with mpv and vlc with srt files. I have not tested other formats and video players.

Also, could you, please, add the repo link to the description of the script and some sort of versioning (in the README as well)? the script name is widely used.

Is there a way to make the script's output less verbose in the terminal? (not shut it entirely.)

Keybindings don't work

In "manual" mode keybindings don't work because directory and filename variables in download_subs are undefined.

I suppose this part of control_downloads should be done for manual invocations too:

    -- Make MPV accept external subtitle files with language specifier:
    mp.set_property('sub-auto', 'fuzzy')
    -- Set subtitle language preference:
    mp.set_property('slang', languages[1][2])
    mp.msg.warn('Reactivate external subtitle files:')
    mp.commandv('rescan_external_files')
    directory, filename = utils.split_path(mp.get_property('path'))

Also, changing bindings to use control_downloads is not a good option as if you trigger it manually, you most likely want to download subtitles regardless of video length, name, etc.

Portuguese Brazil subtitles

hi! thanks for the script! I just can't figure it out how to configure for pt-br subs. pt is working for portuguese (portugal), but I tried pt-br, ptbr, pob, pb, pbr, br... nothing works to find portuguese brazil subtitles... :( thanks

Unable to download brazilian portuguese subtitles.

i couldn't manage to download subtitles for brazilian portuguese since it doens't has a code specified by ISO 639-1, i tried tinkering with the language part but i didn't get anything to work, is there a fix to this?

Square brackets in file name

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

change directory

Hi, I am looking for a way to change the directory of downloaded file after pressing downloading key...I do not want it to be near to file. just for more organization.

flatpak installation notes

Hi, I've included subliminal in mpv flatpak, please add instructions for flatpak mpv. flathub/io.mpv.Mpv#66

Kindly include this in your Readme.md for io.mpv.Mpv flatpak support

cd /tmp
git clone https://github.com/davidde/mpv-autosub.git
cd mpv-autosub/
sed "s/local subliminal = .*$/local subliminal = '\/app\/bin\/subliminal/g" -i autosub.lua 
mkdir -p ~/.var/app/io.mpv.Mpv/config/mpv/scripts/
cp autosub.lua ~/.var/app/io.mpv.Mpv/config/mpv/scripts/
flatpak --user override --filesystem=host io.mpv.Mpv ; # to download subtitles in the same directory containing video

No longer seems to work

[autosub] No English subtitles were detected
[autosub] => Proceeding to download:
[autosub] Searching English subtitles ...
[autosub] Traceback (most recent call last):
[autosub]   File "/usr/bin/subliminal", line 33, in <module>
[autosub]     sys.exit(load_entry_point('subliminal==2.1.0', 'console_scripts', 'subliminal')())
[autosub]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[autosub]   File "/usr/bin/subliminal", line 25, in importlib_load_entry_point
[autosub]     return next(matches).load()
[autosub]            ^^^^^^^^^^^^^^^^^^^^
[autosub]   File "/usr/lib/python3.12/importlib/metadata/__init__.py", line 205, in load
[autosub]     module = import_module(match.group('module'))
[autosub]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[autosub]   File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
[autosub]     return _bootstrap._gcd_import(name[level:], package, level)
[autosub]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[autosub]   File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
[autosub]   File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
[autosub]   File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
[autosub]   File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
[autosub]   File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
[autosub]   File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
[autosub]   File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
[autosub]   File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
[autosub]   File "<frozen importlib._bootstrap_external>", line 995, in exec_module
[autosub]   File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
[autosub]   File "/usr/lib/python3.12/site-packages/subliminal/__init__.py", line 11, in <module>
[autosub]     from .core import (AsyncProviderPool, ProviderPool, check_video, download_best_subtitles, download_subtitles,
[autosub]   File "/usr/lib/python3.12/site-packages/subliminal/core.py", line 11, in <module>
[autosub]     from babelfish import Language, LanguageReverseError
[autosub]   File "/usr/lib/python3.12/site-packages/babelfish/__init__.py", line 14, in <module>
[autosub]     from .converters import (LanguageConverter, LanguageReverseConverter, LanguageEquivalenceConverter, CountryConverter,
[autosub]   File "/usr/lib/python3.12/site-packages/babelfish/converters/__init__.py", line 5, in <module>
[autosub]     from pkg_resources import iter_entry_points, EntryPoint
[autosub]   File "/usr/lib/python3.12/site-packages/pkg_resources/__init__.py", line 3324, in <module>
[autosub]     @_call_aside
[autosub]      ^^^^^^^^^^^
[autosub]   File "/usr/lib/python3.12/site-packages/pkg_resources/__init__.py", line 3299, in _call_aside
[autosub]     f(*args, **kwargs)
[autosub]   File "/usr/lib/python3.12/site-packages/pkg_resources/__init__.py", line 3337, in _initialize_master_working_set
[autosub]     working_set = WorkingSet._build_master()
[autosub]                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
[autosub]   File "/usr/lib/python3.12/site-packages/pkg_resources/__init__.py", line 631, in _build_master
[autosub]     ws.require(__requires__)
[autosub]   File "/usr/lib/python3.12/site-packages/pkg_resources/__init__.py", line 968, in require
[autosub]     needed = self.resolve(parse_requirements(requirements))
[autosub]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[autosub]   File "/usr/lib/python3.12/site-packages/pkg_resources/__init__.py", line 829, in resolve
[autosub]     dist = self._resolve_dist(
[autosub]            ^^^^^^^^^^^^^^^^^^^
[autosub]   File "/usr/lib/python3.12/site-packages/pkg_resources/__init__.py", line 870, in _resolve_dist
[autosub]     raise DistributionNotFound(req, requirers)
[autosub] pkg_resources.DistributionNotFound: The 'rarfile>=2.7' distribution was not found and is required by subliminal
[autosub] No English subtitles found
[autosub]
[autosub] No subtitles were found

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.