Giter VIP home page Giter VIP logo

kodi-nfo-generator's Introduction

kodi-nfo-generator

The kodi-nfo-generator is a simple Python-based command-line tool that allows you to generate .nfo files for movies/TV shows that Kodi can use for its library.

This tool is aimed at people that manually curate their movie databases, in order to avoid using scrapers that may pull in the wrong information (or none at all). All the user has to do is place an ID file alongside their movie files, the default is *.imdb, containing the unique IMDB movie ID (or full IMDB movie URL). The tool will then scour the movie directories for these files and pull in the information and create the .nfo files in the same location.

It is also possible to pull in information about episodes of a TV series (--episodes). Though this is slow due to a lot more API calls. In this case, .nfo files for TV episodes are being generated. The video files need to have the pattern S01E01 in the file name to be recognized by kodi (and the generator). The episodes can either be in the same directory of the .nfo file of the series or in sub-directories.

Kodi integration

See the following repository for integrating this tool with Kodi:

https://github.com/fracpete/kodi-nfo-generator-addon

Installation

You can install the tool with pip as follows:

pip install kodi-nfo-generator

Tools

kodi-nfo-gen

The kodi-nfo-gen tool can be used for pulling in the information from the web using the IDs stored in the ID files.

The following parameters can be supplied to the tool:

usage: kodi-nfo-gen [-h] --dir DIR [--type {imdb}] [--recursive]
                    [--pattern GLOB] [--delay SECONDS]
                    [--preferred_language LANG]
                    [--fanart {none,download,download-missing,use-existing}]
                    [--fanart_file FILE] [--episodes]
                    [--episode_pattern [EPISODE_PATTERN [EPISODE_PATTERN ...]]]
                    [--season_group SEASON_GROUP]
                    [--episode_group EPISODE_GROUP] [--multi_episodes]
                    [--dry_run] [--overwrite] [--verbose] [--debug]
                    [--interactive] [--user-agent USER_AGENT]

Generates Kodi .nfo files with information retrieved from IMDB using local
files containing the unique IMDB movie ID.

optional arguments:
  -h, --help            show this help message and exit
  --dir DIR             the directory to traverse (default: None)
  --type {imdb}         what type of ID the movie ID files represent, ie the
                        website they are from (default: imdb)
  --recursive           whether to traverse the directory recursively
                        (default: False)
  --pattern GLOB        the pattern for the files that contain the movie IDs
                        (default: *.imdb)
  --delay SECONDS       the delay in seconds between web queries (to avoid
                        blacklisting) (default: 1)
  --preferred_language LANG
                        the preferred language for the titles (ISO 639-1, see
                        https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
                        (default: en)
  --fanart {none,download,download-missing,use-existing}
                        how to deal with fan-art (default: none)
  --fanart_file FILE    when downloading or using existing fanart, use this
                        filename (default: folder.jpg)
  --episodes            whether to generate .nfo files for episodes as well
                        (default: False)
  --episode_pattern [EPISODE_PATTERN [EPISODE_PATTERN ...]]
                        the shell pattern(s) to use for locating episode files
                        (default: *S??E??*.*)
  --season_group SEASON_GROUP
                        the regular expression to extract the season (first
                        group) (default: .*S([0-9]?[0-9])E.*)
  --episode_group EPISODE_GROUP
                        the regular expression to extract the episode (first
                        group) (default: .*E([0-9]?[0-9]).*)
  --multi_episodes      whether to store the episodes info in a single file
                        (default: False)
  --dry_run             whether to perform a 'dry-run', ie only outputting the
                        .nfo content to stdout but not saving it to files
                        (default: False)
  --overwrite           whether to overwrite existing .nfo files, ie
                        recreating them with freshly retrieved data (default:
                        False)
  --verbose             whether to output logging information (default: False)
  --debug               whether to output debugging information (default:
                        False)
  --interactive         for enabling interactive mode (default: False)
  --user-agent USER_AGENT, --ua USER_AGENT
                        User agent for HTTP requests (default: Mozilla)

kodi-nfo-guess

The kodi-nfo-guess tool can be used for generating, e.g., the .imdb meta-files used by kodi-nfo-gen. It looks for directories that are missing the meta-files, then uses the particular movie database to look up titles that may match the directory name and the user then gets prompted to select the appropriate title. If there is a successful hit, the meta-file gets written.

The following parameters can be supplied to the tool:

usage: kodi-nfo-guess [-h] --dir DIR [--type {imdb}] [--recursive]
                      [--pattern GLOB] [--delay SECONDS]
                      [--preferred_language LANG] [--dry_run] [--overwrite]
                      [--verbose] [--debug] [--user-agent USER_AGENT]

Generates output files for the kodi-nfo-gen tool.

optional arguments:
  -h, --help            show this help message and exit
  --dir DIR             the directory to traverse (default: None)
  --type {imdb}         what type of ID the movie ID files represent, ie the
                        website they are from (default: imdb)
  --recursive           whether to traverse the directory recursively
                        (default: False)
  --pattern GLOB        the pattern for the files that contain the movie IDs
                        (default: *.imdb)
  --delay SECONDS       the delay in seconds between web queries (to avoid
                        blacklisting) (default: 1)
  --preferred_language LANG
                        the preferred language for the titles (ISO 639-1, see
                        https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
                        (default: en)
  --dry_run             whether to perform a 'dry-run', ie only outputting the
                        .nfo content to stdout but not saving it to files
                        (default: False)
  --overwrite           whether to overwrite existing .nfo files, ie
                        recreating them with freshly retrieved data (default:
                        False)
  --verbose             whether to output logging information (default: False)
  --debug               whether to output debugging information (default:
                        False)
  --user-agent USER_AGENT, --ua USER_AGENT
                        User agent for HTTP requests (default: Mozilla)

kodi-nfo-rename

Simple renaming tool, e.g., to be used for renaming episodes of TV shows to a format that kodi recognizes.

The following parameters can be supplied to the tool:

usage: kodi-nfo-rename [-h] --dir DIR --find REGEXP --replace PATTERN
                       [--recursive] [--dry_run] [--verbose] [--debug]

Simple renaming tool using regular expressions.

optional arguments:
  -h, --help         show this help message and exit
  --dir DIR          the directory to traverse (default: None)
  --find REGEXP      the regular expression that files must match in order to
                     be renamed (excluding path; must specify groups to
                     identify season, episode and extension) (default:
                     ([0-9]?[0-9])x([0-9][0-9]).(.*))
  --replace PATTERN  the pattern for assembling the new file name (default:
                     S\1E\2.\3)
  --recursive        whether to traverse the directory recursively (default:
                     False)
  --dry_run          whether to perform a 'dry-run', ie only outputting the
                     .nfo content to stdout but not saving it to files
                     (default: False)
  --verbose          whether to output logging information (default: False)
  --debug            whether to output debugging information (default: False)

kodi-nfo-export

Using the kodi-nfo-export tool, you can export your ID files in a CSV file, associating them with the directory that they were located in. The tool also looks for .nfo files, in case you already have meta-data stored for your movies.

The following parameters can be supplied to the tool:

usage: kodi-nfo-export [-h] --dir DIR [--recursive] [--type {imdb}]
                       [--pattern GLOB] --output CSV [--verbose] [--debug]
                       [--interactive]

Exports Kodi ID/.nfo files to CSV, associating directories with IDs.

optional arguments:
  -h, --help      show this help message and exit
  --dir DIR       the directory to traverse (default: None)
  --recursive     whether to traverse the directory recursively (default:
                  False)
  --type {imdb}   what type of ID the movie ID files represent, ie the website
                  they are from (default: imdb)
  --pattern GLOB  the pattern for the files that contain the movie IDs
                  (default: *.imdb)
  --output CSV    the CSV output file to store the collected information in
                  (default: None)
  --verbose       whether to output logging information (default: False)
  --debug         whether to output debugging information (default: False)
  --interactive   for enabling interactive mode (default: False)

kodi-nfo-import

With the kodi-nfo-import tool, you can import IDs from a CSV file and create ID files in your movie directory structure.

The following parameters can be supplied to the tool:

usage: kodi-nfo-import [-h] --input CSV --dir DIR [--type {imdb}] --col_id COL
                       --col_dir COL [--col_file COL] [--dry_run]
                       [--overwrite] [--verbose] [--debug] [--interactive]

Imports IDs from CSV, storing ID files in the associated directories.

optional arguments:
  -h, --help      show this help message and exit
  --input CSV     the CSV output file to store the collected information in
                  (default: None)
  --dir DIR       the top-level directory of the movies if relative
                  directories are used in the CSV file (default: None)
  --type {imdb}   what type of ID to create, ie what website the IDs are from
                  (default: imdb)
  --col_id COL    the column that contains the ID (name or 1-based index)
                  (default: None)
  --col_dir COL   the column that contains the directory (name or 1-based
                  index) (default: None)
  --col_file COL  the column that contains the file name (name or 1-based
                  index) (default: None)
  --dry_run       whether to perform a 'dry-run', ie only outputting the ID
                  file content to stdout but not saving them to files
                  (default: False)
  --overwrite     whether to overwrite any existing ID files or leave them be
                  (default: False)
  --verbose       whether to output logging information (default: False)
  --debug         whether to output debugging information (default: False)
  --interactive   for enabling interactive mode (default: False)

Examples

For the following examples, we assume your movies are structured like this:

./mymovies
|
+- Metropolis
|  |
|  +- Metropolis.mp4
|  |
|  +- Metropolis.imdb   # content: tt0017136
|
+- Spies
|  |
|  +- Spies.mkv
|  |
|  +- Spies.imdb   # content: https://www.imdb.com/title/tt0019415/?ref_=nm_knf_i2
|
+- movies
   |
   +- Nosferatu.mp4
   |
   +- Nosferatu.imdb   # content: tt0013442
   |
   +- Sunrise.mp4
   |
   +- Sunrise.imdb   # content: tt0018455

kodi-nfo-gen

And for each movie an .imdb file with either the unique IMDB ID or the full IMDB URL is present.

Then you can the tool for generating the .nfo files like this:

kodi-nfo-gen \
  --dir ./mymovies \
  --recursive \
  --verbose

If you also want to download fan art (e.g., as folder.jpg), then you can use the following command-line:

kodi-nfo-gen \
  --dir ./mymovies \
  --recursive \
  --fanart download \
  --verbose

kodi-nfo-export

The following command-line exports all the movies from the ./mymovies directory as a CSV file ./list.csv:

kodi-nfo-export \
  --dir ./mymovies \
  --output ./list.csv \
  --recursive \
  --verbose

kodi-nfo-import

Assuming this CSV file (./list.csv) containing movie IDs and their associated directories (and optional file name):

ID,File,Dir
tt0017136,,Metropolis
https://www.imdb.com/title/tt0019415/?ref_=nm_knf_i2,,Spies
tt0013442,Nosferatu,Movies
tt0018455,Sunrise,Movies

Then the following command-line imports the IMDB IDs from the CSV file using ./mymovies as top-level directory for relative paths in the CSV file:

kodi-nfo-import \
  --input ./list.csv \
  --dir ./mymovies \
  --type imdb \
  --col_id 1 \
  --col_file 2 \
  --col_dir 3 \
  --verbose

Note: If a file name should not be present in the CSV, the import will then look for files in that directory (.nfo, .mp4, .mkv, .avi). If it cannot find such a file, it will use the base name of the directory (Spies and Metropolis in the above example directory structure).

kodi-nfo-generator's People

Contributors

fracpete avatar ggalan87 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

kodi-nfo-generator's Issues

feature request: option for generate a single multi-episode.nfo file instead of an nfo per episode

Hi, i think it would be a good option to have the possibility to create a single nfo file for a series rather than one nfo file per episode.

Kodi had an option for this, it just bundle all the single nfo files inside a single file with the name mutli-episode.nfo

Its no big deal to create this file from the single episode files

➤ echo "<?xml version="1.0" ?>" > multi-episode.nfo 
➤ for i in $(ls *S??E??*.nfo); do cat $i | tac | head -n -1 | tac >> multi-episode.nfo ; done
➤ rm *S??E??*.nfo

The only 'tricky' part is maybe to match the wildcards (*SE.nfo) under certain circumstances.

But i think it would be nice to had an option which just create this kind of file instead of a nfo for every single episode.
Anyway big thanks for your project it has already saved me a lot of work.

Problem generate nfo for episodes

Hi, i try to generate a nfo file for episodes, but it does not work, tested with python3.8 and 3.11 - same problem.

➤ kodi-nfo-gen --dir ~/spinningDisk1/Wer\ nicht\ fragt,\ stirbt\ dumm!\ \(2015\)/ --episodes --verbose --debug --overwrite                                                                                                      20:14:56
DEBUG:kodi.generator:Namespace(dir='/home/karloff/spinningDisk1/Wer nicht fragt, stirbt dumm! (2015)/', type='imdb', recursive=False, pattern='*.imdb', delay=1, language='en', fanart='none', fanart_file='folder.jpg', episodes=True, episode_pattern='*S??E??*.*', season_group='.*S([0-9]?[0-9])E.*', episode_group='.*E([0-9]?[0-9]).*', dry_run=False, overwrite=True, verbose=True, debug=True, interactive=False, user_agent='Mozilla')
INFO:kodi.generator:# dirs: 1
INFO:kodi.generator:Current dir: /home/karloff/spinningDisk1/Wer nicht fragt, stirbt dumm! (2015)/
INFO:kodi.generator:ID file: /home/karloff/spinningDisk1/Wer nicht fragt, stirbt dumm! (2015)/Wer nicht fragt, stirbt dumm!.imdb
INFO:kodi.generator:ID: tt5338680
INFO:kodi.imdb:IMDB URL: https://www.imdb.com/title/tt5338680/
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.imdb.com:443
DEBUG:urllib3.connectionpool:https://www.imdb.com:443 "GET /title/tt5338680/ HTTP/1.1" 200 None
DEBUG:kodi.imdb:{'@context': 'https://schema.org', '@type': 'TVSeries', 'url': 'https://www.imdb.com/title/tt5338680/', 'name': 'Tu mourras moins bête', 'image': 'https://m.media-amazon.com/images/M/MV5BNzZlNTQ2ODgtYzQ1YS00MzNiLWIxNDEtNTI2ODA0MTU2MWU2XkEyXkFqcGdeQXVyMjU1ODAyMDM@._V1_.jpg', 'description': 'A mustached female professor answers scientific questions in a comedic way, for multiple customers.', 'aggregateRating': {'@type': 'AggregateRating', 'ratingCount': 48, 'bestRating': 10, 'worstRating': 1, 'ratingValue': 7.9}, 'genre': ['Animation', 'Short', 'Comedy'], 'datePublished': '2015-08-23', 'keywords': 'question,scientific explanation,question and answer,scientist,science', 'actor': [{'@type': 'Person', 'url': 'https://www.imdb.com/name/nm0603586/', 'name': 'François Morel'}, {'@type': 'Person', 'url': 'https://www.imdb.com/name/nm1767399/', 'name': 'Jérôme Pauwels'}, {'@type': 'Person', 'url': 'https://www.imdb.com/name/nm0287131/', 'name': 'Nathalie Fort'}], 'creator': [{'@type': 'Organization', 'url': 'https://www.imdb.com/company/co0044919/'}, {'@type': 'Organization', 'url': 'https://www.imdb.com/company/co0028384/'}, {'@type': 'Organization', 'url': 'https://www.imdb.com/company/co0014456/'}]}
INFO:kodi.imdb:Has episode data
INFO:kodi.imdb:Default episodes URL: https://www.imdb.com/title/tt5338680/episodes/
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.imdb.com:443
DEBUG:urllib3.connectionpool:https://www.imdb.com:443 "GET /title/tt5338680/episodes/ HTTP/1.1" 200 None
INFO:kodi.imdb:Season using buttons
INFO:kodi.imdb:Available seasons:
INFO:kodi.imdb:Located seasons: 1, 2, 3
INFO:kodi.imdb:Season 1 URL: https://www.imdb.com/title/tt5338680/episodes/?season=1
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.imdb.com:443
DEBUG:urllib3.connectionpool:https://www.imdb.com:443 "GET /title/tt5338680/episodes/?season=1 HTTP/1.1" 200 None
INFO:kodi.imdb:extract_episodes: episode-item-wrapper based
INFO:kodi.generator:Traceback (most recent call last):
  File "/home/karloff/pip/kodi-nfo-gen/lib/python3.11/site-packages/kodi/generator.py", line 98, in generate
    file_generated = generate_imdb(id, language=language, fanart=fanart, fanart_file=fanart_file,
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/karloff/pip/kodi-nfo-gen/lib/python3.11/site-packages/kodi/imdb.py", line 211, in generate_imdb
    episodes_data = extract_episodes(soup_ep, season)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/karloff/pip/kodi-nfo-gen/lib/python3.11/site-packages/kodi/imdb_series.py", line 236, in extract_episodes
    s = rating_tag["aria-label"]
        ~~~~~~~~~~^^^^^^^^^^^^^^
  File "/home/karloff/pip/kodi-nfo-gen/lib/python3.11/site-packages/bs4/element.py", line 1573, in __getitem__
    return self.attrs[key]
           ~~~~~~~~~~^^^^^
KeyError: 'aria-label'

my files order in following schema

➤ ls -1 ~/spinningDisk1/Wer\ nicht\ fragt,\ stirbt\ dumm!\ \(2015\)/                                                                                                                                         20:22:21
'S01E01 - Wer_nicht_fragt,_stirbt_dumm!_-_Angst_vorm_Fliegen.mp4'
'S01E02 - Wer_nicht_fragt,_stirbt_dumm!_-_Liebling,_ich_will_die_Kinder_schrumpfen!.mp4'
'S01E03 - Wer_nicht_fragt,_stirbt_dumm!_-_Wann_kommt_das_Laserschwert?.mp4'
'S01E04 - Wer_nicht_fragt,_stirbt_dumm!_-_Der_Sprung_von_der_Golden_Gate_Bridge.mp4'
'S01E05 - Wer_nicht_fragt,_stirbt_dumm!_-_Immunologie.mp4'
'S01E06 - Wer_nicht_fragt,_stirbt_dumm!_-_Im_Schlaf_Spinnen_verschlucken.mp4'
'S01E07 - Wer_nicht_fragt,_stirbt_dumm!_-_Kopfverpflanzungen.mp4'
'S01E08 - Wer_nicht_fragt,_stirbt_dumm!_-_Einführung_in_die_Hobbitologie.mp4'
'S01E09 - Wer_nicht_fragt,_stirbt_dumm!_-_Meine_Freundin_liebt_ein_Pony.mp4'
'S01E10 - Wer_nicht_fragt,_stirbt_dumm!_-_Higgs-Boson?_Wassolldassein?.mp4'
'S01E11 - Wer_nicht_fragt,_stirbt_dumm!_-_Wann_kommt_die_Kryonik?.mp4'
'S01E12 - Wer_nicht_fragt,_stirbt_dumm!_-_Wie_Tiere_die_Welt_sehen.mp4'
[...]
'S03E27 - Wer_nicht_fragt,_stirbt_dumm!_-_Atomversuch_mit_Ziege.mp4'
'S03E28 - Wer_nicht_fragt,_stirbt_dumm!_-_Was_sind_Pseudowissenschaften?.mp4'
'S03E29 - Wer_nicht_fragt,_stirbt_dumm!_-_Wie_verläuft_ein_wissenschaftlicher_Kongress?.mp4'
'S03E30 - Wer_nicht_fragt,_stirbt_dumm!_-_Was_ist_eigentlich_ein_Blob?.mp4'
'Wer nicht fragt, stirbt dumm!.imdb'
``

Add support for TV Shows

I would love if there was support added for television shows. Airdate and DVD order choices. Thanks for a great tool

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.