Tvheadend Library integration script
#1
I created a post processing script to automatically integrate my tvheadend recordings into the XBMC Library and thought it would be useful to others. It can be found at: http://jesshaas.com/software/xbmc/tvheadend_post.sh

It uses xmltv data from schedules direct(other sources may require tweaks) to rename recordings to include the original airdate in the filename. This allows xbmc to properly scrape them using thetvdb. If it can't find the original airdate or the show is in a list of shows not scrapeable by thetvdb(sports, news, etc...) then an nfo file is created so that it can still be imported into the library. If not an xml file is created containing all the data for later use(just rename to .nfo if xbmc isn't scraping something)

I don't really have the time to package it up any better or walk through every setup step at the moment but wanted to get it up here so others don't have to reinvent the wheel. Feel free to improve it or come up with a setup guide if you can.

The script requires schedule direct data downloaded before the recording started in /tmp/schedules_direct-past.xml
I recommend setting up a cron job to download and rotate files atleast once a day.
In order to setup a log file do the following(as root):
# touch /var/log/tvheadend_post.log
# chown tvheadend.video /var/log/tvheadend_post.log

put the script in /usr/local/bin and within tvheadened set it as a post processing script like so:
/usr/local/bin/tvheadend_post.sh "%f" "%b" "%c" "%t" "%d"

You can also edit the list of shows to create nfo files for within the script.

Hope this is helpful to someone. I find it so much better than the live tv recordings interface and it allows my downloaded shows and dvr shows to integrate seamlessly.

~Jess
Reply
#2
I just fixed a few bugs and added some more error handling. I also moved the schedules direct data to ~/.xmltv so that it would survive a reboot. New version is in the same spot:
http://jesshaas.com/software/xbmc/tvheadend_post.sh
Also here is the script I use to fetch and rotate schedules direct data:
http://jesshaas.com/software/xbmc/schedu...-rotate.sh

One thing I forgot to mention before is that timeoffset must be properly set for your timezone in ~/.xmltv/tv_grab_na_dd.conf or some shows will not be found. Unfortunately it needs to be updated after daylight savings, etc...

Looks like a number of people have downloaded my script. Is anyone finding it useful?

~Jess
Reply
#3
Love it!
Just started looking at a way to do this myself.

A lot of my EPG is coming OTA though, so I've still got a bit of work to do, but I'll have a good look into this approach first.
Reply
#4
Lightbulb 
Update: I wrote up the HOWTO referenced below:
http://forum.kodi.tv/showthread.php?tid=282720

This thread is two years old at this point but I wanted to chime in and talk about my experience now. The situation has definitely improved from both the tvheadend side and from the Kodi side to the point where if you set things up correctly with "good" guide listings, tvheadend can accomodate most of what you need to get the TVDB scraping to work. I didn't need any external renaming scripts or tv scraping beyond what you need to set up to get guide listing working in tvheadend. It's pretty badass at this point.

I will probably post a new thread/HOWTO to get it rolling, and link to it from here. It's obviously a summary/collation of other peoples' hard work and just a formula for success.

The general steps are (biased towards a US-based setup, but it will work for other regions as well):

1) install the latest version of tvheadend - there are plenty of easy ways to do this via ubuntu, even using Xenial/16.04 if you just add the right repos.

2) configure tvheadend up through the channel mapping step - in a new post I will be much more specific, but configure tuners, network, services, and channels (map services to channels).

3) the "fun" part is configuring the EPG and recording profiles part.
a) EPG: After mapping your services to channels, you need to set up XMLTV-based grabbers. There are good tutorials for this which I will link to. Basically you install tv_grab_file and restart tvheadend service. I will explain this in more detail in another post. For the US, Zap2it is an excellent provider because it contains season AND episode info in the extended listings. THIS IS THE KEY! DO NOT use mc2xml, use zap2xml and grab the Zap2It listings. MAKE SURE you use the extended guide listing options of -D and -I, especially -I (that's a capital "eye"). It will make your initial zap2xml run very long but it's worth it because you need to get the extended descriptions, episode titles, and the TVDB season and episode numbers, which are part of Zap2It's service now! I have not paid for or tried Schedules Direct and cannot say whether or not those listings contain the season and episode info. For other regions, mc2xml may be the right way to go. Now, once you have zap2it running and pulling into your xmltv file, point tv_grab_file at it by editing tv_grab_file and choosing the path to your XMLTV file produced by zap2xml. Then go into tvheadend, configure EPG/internal grabbers, disable ALL external or over-the-air grabbers, and choose tv_grab_file as your internal grabber. If everything is set up correctly, it will run, and you will now have XMLTV EPG sources. Once this is done (it's fast), then go into the EPG setup for your channels and choose XMLTV: <correct name or number of channel> for each channel you want guide listings for in the EPG source column. (If anyone knows of a quicker way to do this other than manually for each channel, I'm listening! Big Grin ). SAVE before paging to the next page. Get everything lined up, then wait for the EPG to populate.
b) Recording profiles: Go into tvheadend's config and choose Recording. On the right side make sure your default recording profile has the following:
  • A recording system path that points to a location you will set up as a source in Kodi - this is important so you can automate everything later.
  • Check the "include episode in filename" option - this is not the episode name, it's the season and episode NUMBERS, which is the #1 key
  • Make subdirectories per title (don't choose the other two)
  • To be on the safe side, in case you record something that does not have episode numbers, also choose the two options for date and time. I also select Put Episode In Filename Before Date And Time. Time is helpful if your recording gets interrupted so you can resume and not overwrite the older file for that same episode/recording.
Save everything! Your recordings will now have the episode AND season info in the filename, which is exactly what the TVDB scraper in Kodi loves.

4) The Kodi part is easy. In Kodi, add a new source which corresponds to the same recording path location that you are asking tvheadend to record to. It can be an internal or external drive on the same machine if you are running Kodi and tvheadend together, or it can be an NFS or SMB (network) share if tvheadend is on a separate machine. I'll add more info about this particular part in the more detailed version of this post; the permissions have to be right in the directory/recording path, so tvheadend can write recordings to the directory, and so Kodi can read the files from it into its library. Set the source type to TV Shows when setting up your video source. Kodi will now scan the folder and if there are any recordings in there, it will create TV Show metadata for them. Now, install the Library Watchdog add-on.

5) Voila. Every time a new recording is placed in the recordings folder, it will be scanned in and the proper show will now show up in your TV library. This works even during the beginning of a recording, so you can start to watch even before the recording is complete. This also works for instant recordings, one-off recordings, timer-based recordings, recordings you schedule directly in tvheadend, and files you may move into this folder on your own (downloaded, etc.). If you have multiple files for the same show (you stopped and restarted recording) this works if you are putting the timestamp in the filename - you will get two instances of the episode showing up so you can watch both parts, etc.
Reply
#5
Can anyone confirm whether this is still working, please?

Further to my post here:

https://forum.kodi.tv/showthread.php?tid=339439

This script might be exactly what I am after.
Reply

Logout Mark Read Team Forum Stats Members Help
Tvheadend Library integration script0