Locast interface (appliance)

Added by G Kazaroth 3 months ago

TVHeadend-Locast version 0.7.3-RC2
Working on getting a service that will take the Locast server stream, clean it and feed it into TVHeadend and other DVRs (Also tested on Emby and should work on Plex). It works on the subscription and free versions. Also it runs on Linux and Windows as a service. Windows has a installer. Once installed, setup is easy with TVHeadend.
1) Setup the automatic IPTV network

Make sure to set the number of tuners to 1. Locast does not like the speed of channel changes during initial scanning. Doing a force scan will create the mux and service values.
2) Next you can setup the grabber. I use a URL grabber which is an extremely small file

Have the grabber run and populate the EPG data into the EPG Grabber Channels tab.
3) In the Channel view, select Map all channels.

This will tie the services, EPG and channels together, automatically. After this, re-grab the EPG data. This will populate the EPG tab with shows. I also updated the Number column with the channel number, but is not required.
4) Display the TVGUIDE. This appliance has special features which maps the tvheadend genre, giving colors on tvguides. It also has enhanced guide descriptions and optional additional channel notations if you use many streams. Below is the Kodi tvguide using the pvr.hts plugin.

Replies (16)

RE: Locast interface (free version) - Added by G Kazaroth 3 months ago

Here is a video test file that has the ad followed by the actual stream. When I play on VLC, it works. When I stream it into TVHeadend, it stops after the ad plays.

RE: Locast interface (free version) - Added by G Kazaroth 3 months ago

Getting closer to the solution. My current solution is to use ffprobe to get the pts values for the packets in the current stream. If it detect a bad set of pts values, then those packets are dropped until good pts values occur. That along with using ffmpeg option -copyts seems to get rid of all the bad pts packets. More testing, but it is looking much better.

RE: Locast interface (free version) - Added by G Kazaroth 3 months ago

After testing for 4-5 hours, it seems to now work by removing the bad packets. My plan is to create a new app for TVHeadend associated with Locast. Based on tvheadend naming format for apps, my plan is to use "tvheadend-locast". Unless I hear otherwise, I will place the development in my github area. The software is based on locast2plex, so as that app is updated, those changes will be incorporated simply into the tvheadend one.

RE: Locast interface (free version) - Added by ace golfer 3 months ago

This is a great project. Curious, what's the file size of 1 hour recording?

RE: Locast interface (free version) - Added by G Kazaroth 3 months ago

For a 720 @30FPS (which seem to be what locast down-verts to on the major channels I get 610MB per hour. From the antenna, the same channel with 1080 @30 is 4.53GB. This was the same show recording on both channels at one time through tvheadend. I have mine running as a service for about 2 weeks and has had no issues, so far.

I have a baseline set of code completed and to some degree tested. It is at
I run this in Linux. You need a config.ini file at the top folder. Mine looks like

plex_accessible_ip = 192.168.1.<###>
locast_username = <username>
locast_password = <password>
uuid = noxnkxyu
bytes_per_read = 256000
epg_update_days = 7
free_refresh_rate = 1827
servicename_suffix = L

To run, download zip from github, unzip and from the top folder run the command

To test, run the URL from a browser
http://&lt;IP ADDRESS>:6077/lineup.json
This should give you a list of locast local channels.
Run the URL
http://&lt;IP ADDRESS>:6077/channels.m3u
which you can use to import into TVHeadend and automatically populate the muxes and services.
http://&lt;IP ADDRESS>:6077/xmltv.xml
produces the xmltv.xml file that TVHeadend needs for the EPG
I am running both the antenna and locast through the tvheadend with two different xmltv.xml files. One from locast and one from zap2it. It is all working fine. Only issue that seems to appear is when locast skips 6 seconds of video, tvheadend does not like it. I may have to use a filler video for that, but have not had time.

I am working on a number of projects which are higher priority right now, but plan to get back in a couple of weeks.

RE: Locast interface (free version) - Added by Chris Hubbard 3 months ago

I am curious, if I am a "paid" subscriber for the locast system, will your version choke when it does not see the ads, or will it "just work" when someone has donated to locast?

I am using the unmodified locast2plex, and have hacked it into my MythTV system. However I think if I am going to attempt to future-proof things this will likely be the route I head (using the tvheadend software).

RE: Locast interface (free version) - Added by G Kazaroth 3 months ago

The app is based on locast2plex. It should work with paid subscriptions since the paid tag is obtained from locast directly and then if statements are made to support the paid versus free interface. TVHeadend requires different information than what plex needs, so changes to the ffmpeg call and updates to the tv guide are needed. I have not implemented the tv guide updates, but I am aware of the changes. The project is setup to overlay the locast2plex updates easily with minimum impacts to the tvheadend source. The cool part of the product is that you can start up the service manually and then point a VLC client at it and it will play the channel using the URLs instead of using TVHeadend.

All files except those in the tvheadend-locast/lib/tvheadend/ are from locast2plex.

RE: Locast interface (free version) - Added by G Kazaroth 2 months ago

tvheadend-locast is now fully working on Linux (Ubuntu) and Windows OS. It can either play through tvheadend or play directly from a player like VLC. I have not created any installers. Just unpack and run the command "python3" after updating/creating the config.ini file. Still working on documentation and installers, but very happy with the results so far.

RE: Locast interface (free version) - Added by G Kazaroth 2 months ago

Added Windows installer for tvheadend-locast
After installing, browse to the URL
This will download a m3u file. If you have VLC installed, it should auto-populate with the channels.
I would be interested in how it went.
Next step is to create a Debian/Ubuntu installer.

RE: Locast interface (free version) - Added by Tony Wagner about 2 months ago

Thanks for sharing, I just got this working on my Raspberry Pi. Two things of note:

1. Be sure to copy the tvheadend-specific config_example.ini file to the root directory as config.ini, then edit it with your IP and account information:

cp lib/tvheadend/config_example.ini config.ini

2. After that, the program would start for me but quickly broke with this error:

Traceback (most recent call last):
File "", line 11, in <module>
File "/home/piuser/locast/lib/tvheadend/", line 130, in main
epg2xml.generate_epg_file(config, location_info.location)
File "/home/piuser/locast/lib/tvheadend/", line 122, in generate_epg_file
channel_number = str(dma_channels[sid]['channel'])
KeyError: '1595365120185'

Somehow the program was looking for an id (1595365120185) that didn't exist in my dma_channels list. I got around this by editing lib/tvheadend/ and adding a quick check if the channel exists at line 122, as follows:

sid = str(channel_item['id'])
channel = dma_channels.get(sid)
if not channel:
channel_number = str(dma_channels[sid]['channel'])

RE: Locast interface (free version) - Added by G Kazaroth about 2 months ago

First, thank you for running the test; it is very much appreciated. The windows installer (and the debian installer I am working on), will do the config.ini copy for you. As for the IP address, I changed the code so you can use "" for the IP address. Standard socket libraries will open a port against all IP addresses on your box using that IP. (It takes can of people looking for an IP and works with WiFi and electrical connections together.) All the installer does to the config.ini is set the user/password; the rest of the config_example.ini file in lib/tvheadend/ should be fine for starters.

As for the issue you found. I believe I understand. The Kodi version shows that the Locast EPG can have more channels than those listed in the station list. I believe a filter is needed like you mentioned to filter out any channel IDs that are not in the station list. The interesting part is that the other channels are, many times, duplicates running at a different resolution. Like NBC is at 720p, but the other EPG channel for NBC runs at 1080. For now, I am ignoring these other channels. If you want to check the lists, here is how. In the .\cache\*epg\ folder there are json files with dates. Throw one of these files into your favorite browser and it should organize the epg data. You can then see how many channels it is reporting and the SIDs. Then there is the .\cache\stations\*station.json which has the list of official SIDs and channels.

Oh, your Raspberry Pi. I am not an expert on Raspberry Pis... What OS is it running? I am assuming a Debian version. Is this correct?
Thank you again.

RE: Locast interface (free version) - Added by G Kazaroth about 2 months ago

Fix implemented and released as 0.7.2.

RE: Locast interface (free version) - Added by Tony Wagner about 2 months ago

Thanks! I just updated and the EPG error is now gone. And yes, my Pi is running Raspbian, based on Debian.

One more issue: if I leave the IP address set to, the stream URLs in channels.m3u and lineup.json all point to no matter what computer makes the request. Not a problem for TVHeadend on the same machine, but those stream URLs obviously won't play on other computers on the network unless I change the IP.

Can channels.m3u and lineup.json just return relative stream URLs? Or if they have to be absolute, they could get the IP/domain specified in the request, as use that to build the stream URLs.

RE: Locast interface (free version) - Added by G Kazaroth about 2 months ago

I also noticed it that seemed to get the localhost address instead of the network IP. It is suppose to be caused by the /etc/hosts file setup with the primary hostname. I have researched and made changes to the code to pull the network IP. The channels.m3u must have absolute URLs, sorry. I have been testing most of the day on both unix and windows and it looks like it is fixed.

The latest is RC2.

RE: Locast interface (appliance) - Added by G Kazaroth 24 days ago

Released 0.7.3-RC2

RE: Locast interface (appliance) - Added by Alistair Ruckus 16 days ago

this works perfectly. i'm a paid subscriber of locast and was looking for something exactly like this to get locast into tvh.

thank you for your hard work!