Update .forgejo/workflows/generate-m3u.yml

This commit is contained in:
stoney420 2025-06-29 05:17:57 +02:00
parent 517493c17c
commit 0d80e31505

View file

@ -6,6 +6,19 @@ on:
- main - main
workflow_dispatch: workflow_dispatch:
jobs:
build-and-organize:
runs-on: ubuntu-22.04name: Generate M3U Playlist with Auto-Organization
on:
push:
branches:
- main
workflow_dispatch:
schedule:
# Run daily at 2 AM UTC to refresh playlist
- cron: '0 2 * * *'
jobs: jobs:
build-and-organize: build-and-organize:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
@ -23,6 +36,143 @@ jobs:
git config --local user.email "actions@forgejo.plainrock127.xyz" git config --local user.email "actions@forgejo.plainrock127.xyz"
git config --local user.name "IPTV Playlist Bot" git config --local user.name "IPTV Playlist Bot"
- name: Create Required Directories
run: |
echo "🏗️ Setting up directory structure..."
mkdir -p reports/daily
mkdir -p reports/archive
mkdir -p backups
mkdir -p logs
echo "✅ Directory structure created"
- name: Install Python Dependencies
run: |
echo "📦 Installing Python dependencies..."
python3 -m pip install --upgrade pip
python3 -m pip install requests aiohttp asyncio beautifulsoup4
echo "✅ Dependencies installed"
- name: Verify 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"
# Show first few lines for debugging
echo "📄 First 10 lines of import file:"
head -10 bulk_import.m3u
else
echo "⚠️ No bulk_import.m3u found, creating empty file"
echo '#EXTM3U' > bulk_import.m3u
echo '# Add your M3U content here' >> bulk_import.m3u
fi
- name: Run Playlist Generation
run: |
echo "🚀 Starting playlist generation..."
cd scripts
# Make the script executable
chmod +x generate_playlist.py
# Run the main script with enhanced logging
python3 generate_playlist.py 2>&1 | tee ../logs/generation.log
if [ $? -eq 0 ]; then
echo "✅ Playlist generation completed successfully"
else
echo "❌ Playlist generation failed"
echo "📋 Last 20 lines of log:"
tail -20 ../logs/generation.log
exit 1
fi
- name: Validate Generated Files
run: |
echo "🔍 Validating generated files..."
# Check if playlist was generated
if [ -f playlist.m3u ]; then
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
echo "✅ Generated playlist.m3u with $CHANNELS channels"
# Show playlist statistics
GROUPS=$(grep -o 'group-title="[^"]*"' playlist.m3u | sort -u | wc -l || echo "0")
echo "📊 Organized into $GROUPS groups"
else
echo "⚠️ No playlist.m3u generated"
fi
# Check channels.txt
if [ -f channels.txt ]; then
CHANNEL_BLOCKS=$(grep -c "^Stream name =" channels.txt || echo "0")
echo "✅ channels.txt contains $CHANNEL_BLOCKS channel records"
else
echo "⚠️ No channels.txt found"
fi
- name: Generate Comprehensive Report
run: |
echo "📊 Creating comprehensive report..."
DATE=$(date +%Y%m%d_%H%M%S)
REPORT="reports/daily/report_$DATE.md"
echo "# 📺 IPTV Playlist Generation Report" > "$REPORT"
echo "**Generated:** $(date)" >> "$REPORT"
echo "" >> "$REPORT"
# Playlist statistics
if [ -f playlist.m3u ]; then
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
GROUPS=$(grep -o 'group-title="[^"]*"' playlist.m3u | sort -u | wc -l || echo "0")
echo "## 📊 Statistics" >> "$REPORT"
echo "- **Total Channels:** $CHANNELS" >> "$REPORT"
echo "- **Country Groups:** $GROUPS" >> "$REPORT"
echo "" >> "$REPORT"
# List top 10 groups
echo "## 🌍 Top Channel Groups" >> "$REPORT"
grep -o 'group-title="[^"]*"' playlist.m3u | sed 's/group-title="//;s/"//' | sort | uniq -c | sort -nr | head -10 | while read count group; do
echo "- **$group:** $count channels" >> "$REPORT"
done
else
echo "## ⚠️ No playlist generated" >> "$REPORT"
fi
echo "" >> "$REPORT"
echo "---" >> "$REPORT"
echo "*Report generated automatically by Forgejo Actions*" >> "$REPORT"
echo "✅ Report created: $REPORT"
- name: Health Check (Optional)
continue-on-error: true
run: |
echo "🏥 Running health check on sample channels..."
if [ -f playlist.m3u ]; then
# Test first 5 channels only to avoid long execution times
echo "Testing first 5 channels for connectivity..."
head -20 playlist.m3u | grep -E "^(#EXTINF|http)" | head -10
fi
- name: Cleanup and Archive
run:
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Configure Git
run: |
git config --local user.email "actions@forgejo.plainrock127.xyz"
git config --local user.name "IPTV Playlist Bot"
- name: Create Required Directories - name: Create Required Directories
run: | run: |
echo "🏗️ Setting up directories..." echo "🏗️ Setting up directories..."