This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
FROM node:18-alpine
|
||||||
|
|
||||||
|
# Install required packages
|
||||||
|
RUN apk add --no-cache git curl unzip coreutils
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Download and extract the EPG repository
|
||||||
|
RUN curl -L https://github.com/iptv-org/epg/archive/refs/tags/2023.12.1.zip -o epg.zip && \
|
||||||
|
unzip epg.zip && \
|
||||||
|
mv epg-2023.12.1/* ./ && \
|
||||||
|
rm -rf epg.zip epg-2023.12.1 && \
|
||||||
|
npm install && \
|
||||||
|
npm install pm2 serve -g
|
||||||
|
|
||||||
|
# Copy entrypoint script
|
||||||
|
COPY entrypoint.sh /app/entrypoint.sh
|
||||||
|
RUN chmod +x /app/entrypoint.sh
|
||||||
|
|
||||||
|
# Expose port for serving the guide
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Set environment variables with defaults
|
||||||
|
ENV CRON_SCHEDULE="0 0,12 * * *" \
|
||||||
|
SITES="" \
|
||||||
|
MAX_CONNECTIONS=1 \
|
||||||
|
DAYS="" \
|
||||||
|
TIMEOUT=0 \
|
||||||
|
DELAY=0 \
|
||||||
|
LANG="" \
|
||||||
|
GZIP="false"
|
||||||
|
|
||||||
|
# Set entrypoint
|
||||||
|
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||||
@@ -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
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
2023.12.1
|
||||||
Reference in New Issue
Block a user