my-private-iptv-m3u/.forgejo/workflows/generate-m3u.yml

157 lines
4.9 KiB
YAML
Raw Normal View History

name: Enhanced IPTV Playlist with Discovery
on:
push:
branches:
- main
workflow_dispatch:
jobs:
enhance-and-discover:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Discovery Dependencies
run: |
echo "Installing discovery dependencies..."
pip install requests
echo "Dependencies installed"
- name: Configure Git
run: |
git config --local user.email "actions@forgejo.plainrock127.xyz"
git config --local user.name "IPTV Discovery Bot"
- name: Setup Directories
run: |
echo "Setting up directory structure..."
mkdir -p reports/daily config
echo "Setup completed"
- name: Run Channel Discovery
run: |
echo "Running automated channel discovery..."
if [ -f scripts/source_scraper.py ]; then
python3 scripts/source_scraper.py
echo "Channel discovery completed"
else
echo "Discovery script not found, skipping discovery"
fi
- name: Check Import File
run: |
echo "Checking import file..."
if [ -f bulk_import.m3u ]; then
LINES=$(wc -l < bulk_import.m3u)
echo "Found bulk_import.m3u with $LINES lines"
if [ "$LINES" -gt 2 ]; then
echo "Contains channels to process"
fi
else
echo "Creating empty bulk_import.m3u"
echo '#EXTM3U' > bulk_import.m3u
fi
- name: Run Enhanced Playlist Generation
run: |
echo "Running enhanced playlist generation..."
if [ -f scripts/generate_playlist.py ]; then
python3 scripts/generate_playlist.py
echo "Playlist generation completed"
else
echo "Error: generate_playlist.py not found"
exit 1
fi
- name: Create Simple Report
run: |
echo "Creating report..."
if [ -f playlist.m3u ]; then
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
echo "Found $CHANNELS channels in playlist"
DATE=$(date +%Y%m%d_%H%M%S)
REPORT="reports/daily/report_$DATE.md"
echo "# Enhanced IPTV Report" > "$REPORT"
echo "Generated: $(date)" >> "$REPORT"
echo "Channels: $CHANNELS" >> "$REPORT"
# Check if discovery ran
if ls reports/daily/discovery_report_*.md 1> /dev/null 2>&1; then
LATEST_DISCOVERY=$(ls -t reports/daily/discovery_report_*.md | head -1)
DISCOVERED_COUNT=$(grep "Total Channels Discovered:" "$LATEST_DISCOVERY" | grep -o '[0-9]*' || echo "0")
echo "Discovered this session: $DISCOVERED_COUNT" >> "$REPORT"
fi
echo "Report created: $REPORT"
else
echo "No playlist found"
fi
- name: Clean Old Reports
run: |
echo "Cleaning old reports..."
cd reports/daily
if ls *.md >/dev/null 2>&1; then
COUNT=$(ls *.md | wc -l)
echo "Found $COUNT reports"
if [ "$COUNT" -gt 3 ]; then
echo "Removing excess reports..."
ls -t *.md | tail -n +4 | xargs rm -f
echo "Cleanup done"
fi
else
echo "No reports to clean"
fi
cd ../..
- name: Reset Import File
run: |
echo "Resetting import file..."
echo '#EXTM3U' > bulk_import.m3u
echo "Import file reset"
- name: Commit Changes
run: |
echo "Committing changes..."
git add .
if git diff --staged --quiet; then
echo "No changes to commit"
else
CHANNELS="0"
if [ -f playlist.m3u ]; then
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
fi
# Check for discovery
DISCOVERY_NOTE=""
if ls reports/daily/discovery_report_*.md 1> /dev/null 2>&1; then
LATEST_DISCOVERY=$(ls -t reports/daily/discovery_report_*.md | head -1)
DISCOVERED_COUNT=$(grep "Total Channels Discovered:" "$LATEST_DISCOVERY" | grep -o '[0-9]*' || echo "0")
if [ "$DISCOVERED_COUNT" -gt "0" ]; then
DISCOVERY_NOTE=" +$DISCOVERED_COUNT discovered"
fi
fi
git commit -m "🚀 Enhanced IPTV with $CHANNELS channels$DISCOVERY_NOTE - $(date '+%Y-%m-%d %H:%M')"
git push
echo "Changes committed"
fi
- name: Summary
run: |
echo "=== ENHANCED WORKFLOW COMPLETE ==="
if [ -f playlist.m3u ]; then
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
echo "✅ Playlist has $CHANNELS channels"
fi
echo "✅ Discovery system ready"
echo "✅ Enhanced reporting active"