Skip to content

Commit

Permalink
Add WebGrab+Plus
Browse files Browse the repository at this point in the history
Remove support of armhf and i386 architecture as dotnet8 is not available
there which is required for WG++
  • Loading branch information
dfigus committed Nov 11, 2024
1 parent a9942f7 commit 76f95d6
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 4 deletions.
14 changes: 14 additions & 0 deletions tvheadend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ RUN \
libxslt=1.1.39-r1 \
nginx=1.26.2-r0 \
linux-firmware-other=20240811-r0 \
dotnet8-runtime=8.0.10-r0 \
xmlstarlet=1.6.1-r2 \
&& pip3 install \
--no-cache-dir \
--prefer-binary \
Expand Down Expand Up @@ -237,6 +239,18 @@ RUN \
&& tar xfJ /picons/tmp/srp.tar.xz -C /picons/srp --strip-components=1 \
&& rm -rf /picons/tmp

# install WebGrab+
RUN \
mkdir -p /wg/tmp \
&& curl -o /wg/tmp/wg.tar.gz http://www.webgrabplus.com/sites/default/files/download/SW/V5.3.0/WebGrabPlus_V5.3_install.tar.gz \
&& tar -zxvf /wg/tmp/wg.tar.gz -C /wg \
&& /wg/.wg++/install.sh \
&& sed -i "s|<filename>guide.xml</filename>|<filename>/config/tvheadend/wg++/guide.xml</filename>|g" /wg/.wg++/WebGrab++.config.xml \
&& rm -rf /wg/tmp \
&& curl -o /usr/bin/tv_grab_wg++ http://www.webgrabplus.com/sites/default/files/tv_grab_wg.txt \
&& sed -i 's|~/.wg++/guide.xml|/config/tvheadend/wg++/guide.xml|g' /usr/bin/tv_grab_wg++ \
&& chmod +x /usr/bin/tv_grab_wg++

# Copy root filesystem
COPY rootfs /

Expand Down
2 changes: 0 additions & 2 deletions tvheadend/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
build_from:
aarch64: ghcr.io/hassio-addons/base/aarch64:16.3.4
amd64: ghcr.io/hassio-addons/base/amd64:16.3.4
armhf: ghcr.io/hassio-addons/base/armhf:16.3.4
armv7: ghcr.io/hassio-addons/base/armv7:16.3.4
i386: ghcr.io/hassio-addons/base/i386:16.3.4
7 changes: 5 additions & 2 deletions tvheadend/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ panel_icon: mdi:television
arch:
- aarch64
- amd64
- armhf
- armv7
- i386
host_network: true
video: true
usb: true
Expand Down Expand Up @@ -72,10 +70,15 @@ options:
init_commands: []
args: ""
comskip_ini: ""
wg_channels: []
schema:
system_packages:
- str?
init_commands:
- str?
args: str?
comskip_ini: str?
wg_channels:
- country: str?
site: str?
channel: str?
1 change: 1 addition & 0 deletions tvheadend/rootfs/etc/crontabs/root
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0 * * * /wg/.wg++/run.net.sh
Empty file.
10 changes: 10 additions & 0 deletions tvheadend/rootfs/etc/s6-overlay/s6-rc.d/cron/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: TVHeadend
# Start cron
# ==============================================================================

bashio::log.info "Starting cron..."

exec crond -f -l 2
1 change: 1 addition & 0 deletions tvheadend/rootfs/etc/s6-overlay/s6-rc.d/cron/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
1 change: 1 addition & 0 deletions tvheadend/rootfs/etc/s6-overlay/s6-rc.d/cron/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/cron/run
Empty file.
69 changes: 69 additions & 0 deletions tvheadend/rootfs/etc/s6-overlay/s6-rc.d/init-wg++/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: TVHeadend
# Updates WG++ channels in WG++ ini
# ==============================================================================
declare wg_channel
declare country
declare site
declare channel
declare filename

bashio::log.info "Init WG++..."
# create WG++ guide folder in addon config folder
if ! bashio::fs.directory_exists "/config/tvheadend/wg++"; then
bashio::log.info "Creating WG++ folder in config folder..."
mkdir -p /config/tvheadend/wg++
fi

expectedParentDir="/wg/.wg++/siteini.pack"

function verifySiteFile() {
local fullpath

fullpath="$expectedParentDir"/"$1"/"$2".channels.xml
if ! bashio::fs.file_exists "$fullpath"; then
bashio::log.fatal
bashio::log.fatal "WG Channel Configuration is incorrect for country $1 site $2"
bashio::log.fatal "File $1/$2.channels.xml does not exist. Only use contries and sites"
bashio::log.fatal "(case-sensitive) from the WG++ siteini.pack folder"
bashio::exit.nok
fi

rpath=$(realpath "$fullpath")
if [[ $rpath != ${expectedParentDir}* ]]; then
bashio::log.fatal
bashio::log.fatal "WG Channel Configuration is incorrect for country $1 site $2"
bashio::log.fatal "File $1/$2.channels.xml is traversing paths. Only use contries and sites"
bashio::log.fatal "(case-sensitive) from the WG++ siteini.pack folder"
bashio::exit.nok
bashio::exit.nok
fi
echo "$fullpath"
}

# remove dummy channel from initial config xml
xmlstarlet ed -L -d "/settings/channel" /wg/.wg++/WebGrab++.config.xml

# Add Channels into WG++ ini
if bashio::config.has_value 'wg_channels'; then
bashio::log.info "Updating WG++ Channels..."
for wg_channel in $(bashio::config 'wg_channels'); do
country=$(bashio::jq "$wg_channel" '.country')
site=$(bashio::jq "$wg_channel" '.site')
channel=$(bashio::jq "$wg_channel" '.channel')
bashio::log.info "Adding channel country: ${country} site: ${site} channel: ${channel} to wg++ config"

filename=$(verifySiteFile "$country" "$site")
if [[ ! $(xmlstarlet sel -t -v "//channel[@site_id='$channel']" "$filename") ]]; then
bashio::log.fatal "Channel $channel does not exist in channel file of $site"
bashio::exit.nok
fi

# run XSLT to copy over channel
xmlstarlet tr /wg/tr.xsl -s filename="$filename" -s channel="$channel" /wg/.wg++/WebGrab++.config.xml | xmlstarlet fo >/wg/.wg++/tmp.xml &&
mv /wg/.wg++/tmp.xml /wg/.wg++/WebGrab++.config.xml

done
fi
1 change: 1 addition & 0 deletions tvheadend/rootfs/etc/s6-overlay/s6-rc.d/init-wg++/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions tvheadend/rootfs/etc/s6-overlay/s6-rc.d/init-wg++/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-wg++/run
Empty file.
Empty file.
22 changes: 22 additions & 0 deletions tvheadend/rootfs/wg/tr.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="filename"/>
<xsl:param name="channel"/>
<!-- Identity template to copy everything by default -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<!-- Template to match the section where items will be added -->
<xsl:template match="/settings">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<!-- Add items from the source XML here -->
<xsl:for-each select="document($filename)//channel[@site_id=$channel]">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 76f95d6

Please sign in to comment.