Jump to content

Tool to Map XMLTV's ChannelId to emby's ChannelTunerNum


HumanPanda

Recommended Posts

HumanPanda

Hi Guys,
 
I don't know how many of you guys use XMLTV data that does not automatically map to a specific channel in your emby's TV Guide. However, I did have this issue and would have had to map 700+ channels. I was looking for a solution to automatically map them for me but, none existed. I dug around emby's developer guides and found out that it accepted REST Calls and it was possible to map channels through it. So I have made this tool which I have attached here and thought I would share it with you guys.
 
Now this tool is pretty crudely cobbled together and it has its kinks and issues but, it does work. I have tested this with data from zap2xml which was scraped from tvguide.com and it took anywhere between 20mins and 60mins for 700ish channels. Luckily it looks like you only have to do this once if you never switch your guide source so the ChannelId never changes.
 

Usage:

 

Download and unzip EmbyChannelMapper-v0.1-Release.zip and run:
 
I do recommend that you restart Emby first as there are issues as I will explain later.

EmbyChannelMapper -f <xmltv file> -s <servername> -u <username> -p <password>

 
Alternatively if you would like to pass the api_key/Authentication Token you can run it with:

EmbyChannelMapper -f <xmltv file> -s <servername> -a <api_key>

 
I have tested this on Windows Mono but, not yet on Linux. There is a bug with Windows Mono on Mono's side that makes it error out. This is resolved by adding
<dllmap dll="MonoPosixHelper" target="libMonoPosixHelper.dll" os="windows" />
to Mono\etc\config before </configuration>
 
but, why are you using Mono on Windows anyway?
 
I am sure there is a better way to do what I wanted to do and it is probably not through REST but, this is what I can come up with quickly. Now if anyone can improve on it, you can find it on github here: https://github.com/phiyuku/EmbyChannelMapper

and I have uploaded the master here as well. (Pretty sure you can tell but, if you can't, this is my first time delving into C#)
 
Now, how does it work?
 
It first starts by parsing the xmltv file you specify and from there determines what the Channel Number is and what the ChannelId is. Here is an example excerpt from a guide data:
 

    <channel id="I5.353.tvguide.com">
        <display-name>5 WNYW</display-name>
        <display-name>5</display-name>
        <display-name>WNYW</display-name>
    </channel>

 
So from here it parses out the channel id which would be "I5.353.tvguide.com" and then associates it with "5" because that is the only display name that is a full integer. What this means is that in order for this program to work your guide data must have a display-name which is the actual channel number itself. After it maps everything out, it begins to make REST calls to the emby server you specified using either the ApiKey or Username,Password you specified.
 
Issues:
Now the reason why I asked you to restart is for some reason or another Emby stops responding to REST Calls even if they show up in the log. I don't know why but, this is further confirmed by manually running the call through PostMan. The application currently seems like it is frozen because it is designed to keep trying if a call fails. The only way I have been able to resolve this is to end the program and restart Emby.
 
The main issue is, as I believe the reason the above is happening, is that mapping a channel through REST or even through the WebUI automatically kicks off the Refresh Guide Scheduled Task. This task then blocks future REST calls to map channels for some reason. In the WebUI you can continue updating mappings with no issue but, if using REST it freezes and no response is given. I have verified this is the Issue by manually calling the Cancel Task through PostMan or through the WebUI and the calls go through again. The way I resolved this is through a Timer that fires off every second a REST call to cancel the Refresh Guide task. In return this turns something that should be done in the same amount of REST calls to a whole bunch. If the program was to run for 30 minutes that would have been 1800 additional calls just in trying to cancel a task. I have looked as much as I can and have not found a way to disable that task from automatically firing. Because of all these additional REST calls, I believe it is causing the issue above.

EmbyChannelMapper-v0.1-Release.zip

EmbyChannelMapper-v0.1-master.zip

Edited by phiyuku
  • Like 2
Link to comment
Share on other sites

  • 5 months later...

Funny you Menton it. I moved Emby to a different server last night, restored from backup, and now the channels don't map. I'm using data from zap2xml which worked fine before using this tool .

 

After restoring from a different backup, the guide data is now coming in. Now I just need a script to pull in channel icons :) 
 

Edited by bigd271
Link to comment
Share on other sites

  • 2 weeks later...
HumanPanda

@@Luke I just tried by reimporting xmltv data and it doesn't seem like it works. Though to be fair it doesn't seem like my tool works either as it returns that the channel number does not exist on Emby's side. I will check in on that some time this weekend. Not sure how many people actually use this but, currently I have nothing mapped after removing the xmltv file so I would need to update it just for myself anyway =(

 

Actually I just noticed my xmltv data is outdated.

Edited by phiyuku
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...