iptv-epg v1
Build and Push Docker Images / build-and-push (push) Successful in 1m54s

This commit is contained in:
2025-04-18 22:39:32 +02:00
parent dd82f28bdc
commit 763f519bd6
3 changed files with 133 additions and 0 deletions
+97
View File
@@ -0,0 +1,97 @@
#!/bin/sh
set -e
# Function to grab EPG data for a site
grab_epg() {
site=$1
echo "Grabbing EPG data for site: $site"
# Build command with optional parameters
cmd="npm run grab -- --site=$site --output=${site}.xml --maxConnections=${MAX_CONNECTIONS}"
# Add optional parameters if they are set
if [ -n "$DAYS" ]; then
cmd="$cmd --days=${DAYS}"
fi
if [ -n "$TIMEOUT" ]; then
cmd="$cmd --timeout=${TIMEOUT}"
fi
if [ -n "$DELAY" ]; then
cmd="$cmd --delay=${DELAY}"
fi
if [ -n "$LANG" ]; then
cmd="$cmd --lang=${LANG}"
fi
if [ "$GZIP" = "true" ]; then
cmd="$cmd --gzip"
fi
# Execute the command
eval $cmd
}
# Function to grab EPG data for all sites
grab_all_sites() {
# Split the SITES environment variable by comma - POSIX sh compatible
echo "$SITES" | tr ',' '\n' >/tmp/sites.txt
# Process each site
while read site; do
grab_epg "$site"
done </tmp/sites.txt
# Clean up
rm /tmp/sites.txt
}
# Initial grab
if [ -n "$SITES" ]; then
grab_all_sites
fi
# Set up cron job using PM2
if [ -n "$CRON_SCHEDULE" ] && [ -n "$SITES" ]; then
echo "Setting up cron job with schedule: $CRON_SCHEDULE"
# Create a script to grab all sites
cat >/app/grab-sites.js <<EOL
#!/usr/bin/env node
const { execSync } = require('child_process');
const sites = process.env.SITES.split(',');
sites.forEach(site => {
try {
console.log(\`Grabbing EPG data for site: \${site}\`);
let cmd = \`npm run grab -- --site=\${site} --output=\${site}.xml --maxConnections=\${process.env.MAX_CONNECTIONS || 1}\`;
// Add optional parameters
if (process.env.DAYS) cmd += \` --days=\${process.env.DAYS}\`;
if (process.env.TIMEOUT) cmd += \` --timeout=\${process.env.TIMEOUT}\`;
if (process.env.DELAY) cmd += \` --delay=\${process.env.DELAY}\`;
if (process.env.LANG) cmd += \` --lang=\${process.env.LANG}\`;
if (process.env.GZIP === 'true') cmd += \` --gzip\`;
execSync(cmd, { stdio: 'inherit' });
} catch (error) {
console.error(\`Error grabbing EPG data for site: \${site}\`, error);
}
});
EOL
chmod +x /app/grab-sites.js
# Start the cron job
pm2 start --name epg-grabber /app/grab-sites.js --no-autorestart --cron-restart="$CRON_SCHEDULE"
fi
# Start the server to serve the guide files
cd /app
echo "Starting server on port 3000"
npx serve -p 3000
# Keep the container running
tail -f /dev/null