Jump to content

Translate TVHeadend Tags to Emby Tags


Go to solution Solved by Q-Droid,

Recommended Posts

Theradioguy
Posted

Hello,

I have a large number of channels in TVHeaded, each categorized by one or more tags.  I am wondering if there is a way to translate the TVHeadend tags to Emby tags, so that I don't need to duplicate all the work I have done on the TVHeadend side.

For context, I am using the Emby tags to gate access to channels for some users of my Emby server.

Posted
On 12/22/2023 at 6:59 PM, Theradioguy said:

Hello,

I have a large number of channels in TVHeaded, each categorized by one or more tags.  I am wondering if there is a way to translate the TVHeadend tags to Emby tags, so that I don't need to duplicate all the work I have done on the TVHeadend side.

For context, I am using the Emby tags to gate access to channels for some users of my Emby server.

Emby should see the tags you created in tvheadend and pass em through on the emby side, in the past it had done this for me. Unless you edited your m3u file after you used it as http://192.168.1.1:9981/playlist/channels ?

Theradioguy
Posted

Thanks for the reply, I don't see any tags in the Emby side, however, I'm not using the m3u8 method of importing channels, I'm using the TVHeadend plugin.  

Is using the m3u option the better way of adding channels into Emby?  Does it still transfer guide data from TVheadend?

  • Solution
Posted

I don't know what the plugin can do with tags. I only used the plugin once and found it to be so limited that I immediately switched to m3u.

You can create a separate m3u tuner in Emby for each tag (group) you have in TVH. Or for any channel grouping you might have. You can also use the API to pull the xmltv guide data from TVH for the corresponding tags and associate them with the matching tuners.

 

 

 

Theradioguy
Posted
6 hours ago, Q-Droid said:

I don't know what the plugin can do with tags. I only used the plugin once and found it to be so limited that I immediately switched to m3u.

You can create a separate m3u tuner in Emby for each tag (group) you have in TVH. Or for any channel grouping you might have. You can also use the API to pull the xmltv guide data from TVH for the corresponding tags and associate them with the matching tuners.

 

 

 

Thanks for the suggestion!  I'll look into pulling the EPG data out of TVHeadend and into emby, have a bit of experience working with APIs, so if it's exposed then I don't think it will be too difficult. 

Theradioguy
Posted (edited)

Just as an update, using the m3u output along with xmltv worked great.  used the following URL to add the TVHeadend channels via m3u:
http://x.x.x.x:9981/playlist/channels?profile=pass

And then I added an XMLTV source and also pointed it to the TVHeadend server:
http://x.x.x.x:9981/xmltv/channels

The channels automatically mapped to the guide data without needing to do anything else.

 

I am still having an issue with tags, in the Emby GUI none of the channels have tags associated with them.  When I look at the m3u from TVH in a text editor, I also don't see any tags, is there possibly a different URL I should be using?

Edited by Theradioguy
Theradioguy
Posted

Update, looks like it may not be supported by TVHeadend at this time: https://tvheadend.org/issues/4459 - unfortunate, I'll see if I can write some middlewear to ad the tags manually before Emby sees the m3u 

  • Thanks 1
Posted
21 minutes ago, Theradioguy said:

Just as an update, using the m3u output along with xmltv worked great.  used the following URL to add the TVHeadend channels via m3u:
http://x.x.x.x:9981/playlist/channels?profile=pass

And then I added an XMLTV source and also pointed it to the TVHeadend server:
http://x.x.x.x:9981/xmltv/channels

The channels automatically mapped to the guide data without needing to do anything else.

 

I am still having an issue with tags, in the Emby GUI none of the channels have tags associated with them.  When I look at the m3u from TVH in a text editor, I also don't see any tags, is there possibly a different URL I should be using?

Maybe the tvh url needs a query string param to include the tags in the m3u? Just an idea.

Theradioguy
Posted

writing a php application to grab the m3u from TVH, parse it, add the tags and then spit it back out seems to have done the trick.  Tags are now added to Emby.  Guessing if TVH ever adds support for the group-title attribute it will work nativly.

Thanks for all the support guys.

  • Thanks 1
  • 4 weeks later...
CharlieMurphy
Posted
On 1/3/2024 at 12:37 AM, Theradioguy said:

writing a php application to grab the m3u from TVH, parse it, add the tags and then spit it back out seems to have done the trick.  Tags are now added to Emby.  Guessing if TVH ever adds support for the group-title attribute it will work nativly.

Thanks for all the support guys.

Would you mind sharing this?

 

On 1/2/2024 at 11:18 PM, Luke said:

Maybe the tvh url needs a query string param to include the tags in the m3u? Just an idea.

There doesn't seem to be an option in TVHeadend to include the tags in m3u. Kodi gets the tags with HTSP though, so the TVHeadend plugin would be able to handle this if the code were there. I found this feature addition giving the option to sort the tags manually: https://tvheadend.org/issues/2560

I would totally do the work on the TVHeadend plugin for Emby but the code is Greek to me. 😞

  • Thanks 1
Theradioguy
Posted
3 hours ago, CharlieMurphy said:

Would you mind sharing this?

 

There doesn't seem to be an option in TVHeadend to include the tags in m3u. Kodi gets the tags with HTSP though, so the TVHeadend plugin would be able to handle this if the code were there. I found this feature addition giving the option to sort the tags manually: https://tvheadend.org/issues/2560

I would totally do the work on the TVHeadend plugin for Emby but the code is Greek to me. 😞

Sure, the code below is what I am using.  I'm just running it on an apache webserver with mod-php.  Note that this works specifically for my use case, has limited error checking and is not 'production ready' in any way.

<?php

//get channels by tag
$tags=file_get_contents("https://127.0.0.1:9981/playlist/tags?profile=pass");
$lines = explode("\n", $tags);
$ouputM3u="";

foreach ($lines as $line) {
    // Check if it's a channel line (starts with '#EXTINF')
    if (strpos($line, '#EXTINF') === 0) {
        $name = str_replace(',','',substr($line, strpos($line, ',') ));
    }
    else
    {
        if(strlen($line)>1) {
            $channelTag=file_get_contents($line);
        }
        $channelTags=explode("\n",$channelTag);

        foreach ($channelTags as $channel) {
            // Check if it's a channel line (starts with '#EXTINF')
            if (strpos($channel, '#EXTINF') === 0) {
                $currTags = substr($channel, 0, strpos($channel, ',') + 1);
                $channelInfo = substr($channel, strpos($channel, ',') + 1);

                // Add the group-title tag before the channel name
                $channel = str_replace(',','',$currTags) . ' group-title="'.$name.'",' . $channelInfo;
            }
            $outputM3u .= trim(str_replace("#EXTM3U","",$channel)). "\n";
        }  
    }
}
$outputM3u = preg_replace('/^[ \t]*[\r\n]+/m', '', $outputM3u);
echo "#EXTM3U\n".$outputM3u;

 

  • Thanks 2

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...