Vim-Snippets and Kodi

I was playing around with Kodi and had to add some nfo files in order to add some episodes to the kodi library that are not available in any scraper source.

Writing nfo files for kodi is a tedious task: A lot of XML structure, repeating itself over and over again.

Putting this into vim-snippets seems to be a logical process in order to make this easier to deal with.Vim-Snippets makes it in general easy to work with files and automatically replace and expand shortcuts depending on the code you’re working on.

NFO files are not that type of file that is defined by a certain syntax as it appears, so there are no snippets for nfo files in the vim-snippets repository. I had to add it myself.

First I added the syntax definition for nfo files to .vimrc:

au BufNewFile,BufRead *.nfo set filetype=nfo
au BufNewFile,BufRead tvshow.nfo set filetype=kodi_nfo

This will enable some snippets only for the tvshow files for kodi, others for all nfo files. According to the kodi documentation they must be called tvshow.nfo, so this will limit the snippet to one specific filename. The filetype kodi_nfo will make sure that there are only snippets in there used for kodi, not other nfo files.

Other snippets which must be available for all nfo files, since the files need to be named as the episode file.

The I placed the snippet code into ~/.vim/bundle/vim-snippets/snippets/kodi_nfo.snippets:

# Snippets for Kodi-NFO Files
#

snippet tvshow-full
     <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
     <tvshow>
       <title>${1}</title>
       <showtitle>${2}</showtitle>
       <rating>${3}</rating>
       <votes>${4}</votes>
       <epbookmark>${5:0.000000}</epbookmark>
       <year>${6:0}</year>
       <top250>${7:0}</top250>
       <season>${8:-1}</season>
       <episodes>${9:0}</episodes>
       <uniqueid>${10}</uniqueid>
       <displayseason>${11:-1}</displayseason>
       <displayepisode>${12:-1}</displayepisode>
       <outline>${13}</outline>
       <plot>${14:Best TV Show ever!}</plot>
       <tagline>${15}</tagline>
       <runtime>${16:0}</runtime>
       <mpaa>${17}</mpaa>
       <playcount>${18:0}</playcount>
       <lastplayed>${19}</lastplayed>
       <episodeguide>
         <url cache="${20:73255.xml}">${21:http://www.thetvdb.com/api/1D62F2F90030C444/series/73255/all/en.zip}</url>
       </episodeguide>
       <id>${22:73255}</id>
       <genre>${23:Drama}</genre>
       <set>${24}</set>
       <premiered>${25:yyyy-mm-dd}</premiered>
       <status>${26}</status>
       <code>${27}</code>
       <aired>${28:yyyy-mm-dd}</aired>
       <studio>${29:Studio or Production Channel}</studio>
       <trailer>${30}</trailer>
       <actor>
         <name>${31:Hugh Laurie}</name>
         <role>${32:Dr. Gregory House}</role>
         <thumb>${33:http://thetvdb.com/banners/actors/23842.jpg}</thumb>
       </actor>
       <resume>
         <position>${34:0.000000}</position>
         <total>${35:0.000000}</total>
       </resume>
       <dateadded>${36:yyyy-mm-dd hh:mm:ss}</dateadded>
     </tvshow>
snippet tvshow
     <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
     <tvshow>
       <title>${1:Titel}</title>
       <showtitle>${2:Showtitel}</showtitle>
       <thumb>${3:Thumb url}</thumb>
       <year>${4:year}</year>
       <season>${5:number of seasons}</season>
       <episode>${6:number of episodes}</episode>
       <displayseason>-1</displayseason>
       <displayepisode>-1</displayepisode>
       <plot>${7:Plot}</plot>
       <genre>${8:Genre}</genre>
     </tvshow>
snippet title
     <title>${1}</title>
snippet showtitle
     <showtitle>${1}</showtitle>
snippet rating
     <rating>${1}</rating>
snippet votes>
     <votes>${1}</votes>
snippet epbookmark
     <epbookmark>${1}</epbookmark>
snippet year
     <year>${1}</year>
snippet top250
     <top250>${1}</top250>
snippet season
     <season>${1}</season>
snippet episodes
     <episodes>${1}</episodes>
snippet uniqueid
     <uniqueid>${1}</uniqueid>
snippet displayseason
     <displayseason>${1}</displayseason>
snippet displayepisode
     <displayepisode>${1}</displayepisode>
snippet outline
     <outline>${1}</outline>
snippet plot
     <plot>${1}</plot>
snippet tagline
     <tagline>${1}</tagline>
snippet runtime
     <runtime>${1}</runtime>
snippet mpaa
     <mpaa>${1}</mpaa>
snippet playcount
     <playcount>${1}</playcount>
snippet lastplayed
     <lastplayed>${1}</lastplayed>
snippet episodeguide
     <episodeguide>
         <url cache="${1:73255.xml}">${2:http://www.thetvdb.com/api/1D62F2F90030C444/series/73255/all/en.zip}</url>
     </episodeguide>
snippet id
     <id>${1}</id>
snippet genre
     <genre>${1}</genre>
snippet set
     <snippet >${1}</snippet >
snippet premiered
     <premiered>${1}</premiered>
snippet status
     <status>${1}</status>
snippet code
     <code>${1}</code>
snippet aired
     <aired>${1}</aired>
snippet studio
     <studio>${1}</studio>
snippet trailer
     <trailer>${1}</trailer>
snippet actor
     <actor>
       <name>${1:Hugh Laurie}</name>
       <role>${2:Dr. Gregory House}</role>
       <thumb>${3:http://thetvdb.com/banners/actors/23842.jpg}</thumb>
     </actor>
snippet resume
     <resume>
       <position>${1:0.000000}</position>
       <total>${2:0.000000}</total>
     </resume>
snippet dateadded
     <dateadded>${1}</dateadded>

The snippet for all nfo files looks like this:

# Snippets for NFO Files
#
snippet episodedetails
     <episodedetails>
         <title>${1:Title}</title>
         <season>${2:season}</season>
         <episode>${3:episode}</episode>
         <playcount>0</playcount>
         <lastplayed></lastplayed>
     </episodedetails>
snippet episodedetails-full
     <episodedetails>
       <title>${1:Title}</title>
       <rating>${2:10.00}</rating>
       <season>${3:season}</season>
       <episode>${4:episode}</episode>
       <plot>${5:The best episode in the world}</plot>
       <thumb>${6:https://thetvdb.com/banners/episodes/164981/2528821.jpg}</thumb>
       <playcount>0</playcount>
       <lastplayed></lastplayed>
       <credits>${7:Writer}</credits>
       <director>${8:Mr. Vision}</director>
       <aired>${9:yyyy-mm-dd}</aired>
       <premiered>$9</premiered>
       <studio>${10:Production studio or channel}</studio>
       <mpaa>${11:MPAA certification}</mpaa>
       <epbookmark>${12:200}</epbookmark> <!-- For media Files containing multiple episodes, where value it the time where the next episode begins in seconds. -->
       <displayseason>${13:3}</displayseason> <!-- For TV show specials, determines how the episode is sorted in the series. -->
       <actor>
         <name>${14:Little Suzie}</name>
         <role>${15:Pole Jumper/Dancer</role>
       </actor>
     </episodedetails>
snippet credits
     <credits>${1:Writer}</credits>
snippet director
     <director>${1:Mr. Vision}</director>
snippet aired
     <aired>${1:yyyy-mm-dd}</aired>
snippet premiered
     <premiered>${1:yyyy-mm-dd}</premiered>
snippet studio
     <studio>${1:Production studio or channel}</studio>
snippet mpaa
     <mpaa>${1:MPAA certification}</mpaa>
snippet rating
     <rating>${1:5.0}</rating>
snippet plot
     <plot>${1:Some plot information}</plot>
snippet actor
     <actor>
       <name>${1:actor name}</name>
       <role>${2:Pole Jumper/Dancer}</role>
     </actor>

Now editing something like tvshow.nfo for kodi by just typing tvshow or episodedetails adds the necessary xml code and makes it easy to fill out. For some stuff it might be usefull to have some more tags available, so there is a second version with the extension -full. Also single tags are added in case they are needed.


  • Update: 2016-01-03: Some errors I make in the files and file structure got cleared and added more snippets.