├── LICENSE ├── open-imdb-page.py ├── README.md └── main.lua /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 ctlaltdefeat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /open-imdb-page.py: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/env python 3 | """ 4 | This script takes a media filename of a movie or TV episode as parameter 5 | and opens the corresponding IMDb page with the webbrowser. 6 | 7 | Requires the following pip packages: 8 | guessit 9 | cinemagoer 10 | 11 | This file is part of the mpv-open-imdb-page mpv script: 12 | https://github.com/ctlaltdefeat/mpv-open-imdb-page 13 | """ 14 | 15 | import sys 16 | import webbrowser 17 | 18 | from guessit import guessit 19 | from imdb import Cinemagoer 20 | 21 | 22 | def get_imdb_url(filename): 23 | result = None 24 | ia = Cinemagoer() 25 | g = guessit(filename) 26 | title = g["title"] 27 | if "year" in g: 28 | title = "{} {}".format(title, g["year"]) 29 | results = ia.search_movie(title) 30 | if g["type"] == "episode": 31 | it = iter(res for res in results if res["kind"] == "tv series") 32 | while not result: 33 | series = next(it) 34 | season = g["season"] 35 | try: 36 | ia.update_series_seasons(series, [season]) 37 | result = series["episodes"][season][g["episode"]] 38 | except Exception: 39 | pass 40 | else: 41 | result = next( 42 | iter( 43 | res 44 | for res in results 45 | if res["kind"] not in ["tv series", "episode"] 46 | ) 47 | ) 48 | return ia.get_imdbURL(result) 49 | 50 | 51 | if __name__ == "__main__": 52 | try: 53 | url = get_imdb_url(sys.argv[1]) 54 | webbrowser.open_new_tab(url) 55 | except Exception as e: 56 | print("ERROR: {}".format(e)) 57 | sys.exit(1) 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | This script opens the IMDb page that corresponds to the currently playing media file, whether a film or a specific TV episode. 4 | 5 | It does this by extracting/guessing the relevant metadata from the file name (using [guessit](https://github.com/guessit-io/guessit)), finding it on IMDb, and then opening the page in a new tab on your default browser. 6 | 7 | Scene/release-type file names are supported. 8 | 9 | # Requirements 10 | 11 | The script is tested on Windows and Linux, and should work on any platform with the dependencies correctly installed. 12 | 13 | ## Python and Packages 14 | 15 | You need Python 3 installed and in path, as well as the modules ```guessit``` and ```cinemagoer```. The latest git version of ```cinemagoer``` should be used: 16 | 17 | ```sh 18 | pip install guessit 19 | pip install git+https://github.com/cinemagoer/cinemagoer 20 | ``` 21 | 22 | ## mpv 23 | 24 | The script won't load for any mpv build below v0.33.1 (Apr 05, 2021). Since that release includes security fixes, you should upgrade to the [newest version](https://mpv.io/installation/) anyways. Note that the default repos of Debian/Ubuntu are often outdated. 25 | 26 | # Install 27 | 28 | Copy the contents of this repo into a folder inside the ```scripts``` folder of your mpv configuration directory (See [mpv's manual](https://mpv.io/manual/master/#files)). 29 | 30 | For example, installing can be done like this: 31 | ```sh 32 | # Linux: 33 | git clone --depth=1 https://github.com/ctlaltdefeat/mpv-open-imdb-page ~/.config/mpv/scripts/mpv-open-imdb-page 34 | 35 | # Windows: 36 | git clone --depth=1 https://github.com/ctlaltdefeat/mpv-open-imdb-page %APPDATA%/mpv/scripts/mpv-open-imdb-page 37 | 38 | # To update (in Linux, Win is analogous): 39 | git -C ~/.config/mpv/scripts/mpv-open-imdb-page pull 40 | 41 | # To update dependencies: 42 | pip install --upgrade guessit git+https://github.com/cinemagoer/cinemagoer 43 | ``` 44 | 45 | # Usage 46 | 47 | By default, the script binds itself to ```Ctrl+i```. 48 | You can change the binding by editing the last line in the ```main.lua``` script file or in mpv's ```input.conf``` like this: 49 | ``` 50 | Ctrl+i script-binding open-imdb-page 51 | ``` 52 | -------------------------------------------------------------------------------- /main.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | mpv-open-imdb-page | https://github.com/ctlaltdefeat/mpv-open-imdb-page 4 | 5 | This mpv script opens the IMDb page that corresponds to the currently playing media file, 6 | whether a film or a specific TV episode. 7 | 8 | This script requires open-imdb-page.py to be in the same directory. 9 | The directory should be placed inside the script folder of mpv's configuration. 10 | 11 | Requires Python 3 and the following pip packages: 12 | guessit 13 | cinemagoer 14 | 15 | Assigns the script-binding launch-imdb as Ctrl+i 16 | 17 | ]] 18 | 19 | function get_python_binary() 20 | local msg = "" 21 | 22 | -- try: python 23 | local python_version = mp.command_native({ 24 | name = "subprocess", 25 | args = { "python", "--version"}, 26 | capture_stdout = true 27 | }) 28 | if python_version.error_string ~= "" then 29 | msg = msg.."'python' not found; " 30 | else 31 | if python_version.stdout:find("3%.") ~= nil then 32 | msg = msg.."'python' with version 3 found!" 33 | return "python", msg 34 | else 35 | msg = msg.."'python' is not version 3; " 36 | end 37 | end 38 | 39 | -- try: python3 40 | python_version = mp.command_native({ 41 | name = "subprocess", 42 | args = { "python3", "--version" }, 43 | capture_stdout = true 44 | }) 45 | if python_version.error_string ~= "" then 46 | msg = msg.."'python3' not found; " 47 | else 48 | msg = msg.."'python3' found!" 49 | return "python3", msg 50 | end 51 | 52 | --no python 3 found 53 | msg = msg.."no Python 3 binary found!" 54 | return nil, msg 55 | end 56 | 57 | function callback(success, result, error) 58 | if result.status == 0 then 59 | mp.osd_message("Launched browser", 1) 60 | else 61 | mp.osd_message("Unable to find IMDb URL", 3) 62 | end 63 | end 64 | 65 | function launch_imdb() 66 | local python_binary, python_msg = get_python_binary() 67 | if python_binary ~= nil then 68 | mp.msg.info(python_msg) 69 | mp.msg.info("Calling open-imdb-page.py") 70 | mp.osd_message("Searching IMDb...", 30) 71 | local cmd = mp.command_native_async({ 72 | name = "subprocess", 73 | args = { 74 | python_binary, 75 | mp.get_script_directory().."/open-imdb-page.py", 76 | mp.get_property("filename") 77 | } 78 | }, 79 | callback 80 | ) 81 | else 82 | mp.msg.error(python_msg) 83 | mp.osd_message("ERROR: "..python_msg, 10) 84 | return 85 | end 86 | end 87 | 88 | -- change key binding as desired 89 | mp.add_key_binding('ctrl+i', 'open-imdb-page', launch_imdb) 90 | --------------------------------------------------------------------------------